Skip to content

Commit

Permalink
Merge pull request #31 from balena-io-examples/balena-sdk-19
Browse files Browse the repository at this point in the history
Balena sdk 19
  • Loading branch information
thgreasi authored Feb 22, 2024
2 parents 6e6bce8 + 3c9b400 commit 2cd6211
Show file tree
Hide file tree
Showing 11 changed files with 1,472 additions and 1,034 deletions.
2 changes: 2 additions & 0 deletions balena.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type: sw.application
version: '2.0.0'
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# see more about dockerfile templates here: http://docs.balena.io/deployment/docker-templates/
# and about balena base images here: http://docs.balena.io/reference/base-images/base-images/
# Note the node:slim image doesn't have node-gyp
FROM balenalib/%%BALENA_ARCH%%-node:12
FROM balenalib/%%BALENA_ARCH%%-debian-node:18-bookworm

# use apt-get if you need to install dependencies,
# for instance if you need ALSA sound utils, just uncomment the lines below.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
TAG_KEY=$1
BALENA_DEVICE_ID=$2
if ! [ "$BALENA_DEVICE_ID" ] ; then
BALENA_DEVICE_ID=$(curl -sSL "$BALENA_API_URL/v3/device?\$select=id,uuid&\$filter=uuid%20eq%20'$BALENA_DEVICE_UUID'" -H "Authorization: Bearer $BALENA_API_KEY" | jq '.d[0].id')
BALENA_DEVICE_ID=$(curl -sSL "$BALENA_API_URL/v6/device?\$select=id,uuid&\$filter=uuid%20eq%20'$BALENA_DEVICE_UUID'" -H "Authorization: Bearer $BALENA_API_KEY" | jq '.d[0].id')
fi

curl -sSL -X GET "$BALENA_API_URL/v3/device_tag?\$filter=((device%20eq%20$BALENA_DEVICE_ID)%20and%20(tag_key%20eq%20'$TAG_KEY'))" \
curl -sSL -X GET "$BALENA_API_URL/v6/device_tag?\$filter=((device%20eq%20$BALENA_DEVICE_ID)%20and%20(tag_key%20eq%20'$TAG_KEY'))" \
-H "Content-Type:application/json" \
-H "Authorization: Bearer $BALENA_API_KEY"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
curl -sSL -X GET "$BALENA_API_URL/v3/device_tag" \
curl -sSL -X GET "$BALENA_API_URL/v6/device_tag" \
-H "Content-Type:application/json" \
-H "Authorization: Bearer $BALENA_API_KEY"
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
TAG_KEY=$1
TAG_VALUE=$2

BALENA_DEVICE_ID=$(curl -sSL "$BALENA_API_URL/v3/device?\$select=id,uuid&\$filter=uuid%20eq%20'$BALENA_DEVICE_UUID'" -H "Authorization: Bearer $BALENA_API_KEY" | jq '.d[0].id')
BALENA_DEVICE_ID=$(curl -sSL "$BALENA_API_URL/v6/device?\$select=id,uuid&\$filter=uuid%20eq%20'$BALENA_DEVICE_UUID'" -H "Authorization: Bearer $BALENA_API_KEY" | jq '.d[0].id')

SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
cd $SCRIPTPATH
TAG_EXISTS=$(sh get-device-tag.sh "$TAG_KEY" "$BALENA_DEVICE_ID" | jq ".d[0] != null")

if [ "$TAG_EXISTS" = "false" ] ; then
curl -sSL -X POST "$BALENA_API_URL/v3/device_tag" \
curl -sSL -X POST "$BALENA_API_URL/v6/device_tag" \
-H "Authorization: Bearer $BALENA_API_KEY" \
-H "Content-Type: application/json" \
--data-binary '{"tag_key":"'$TAG_KEY'","device":'$BALENA_DEVICE_ID',"value":"'$TAG_VALUE'"}'
else
curl -sSL -X PATCH "$BALENA_API_URL/v3/device_tag?\$filter=tag_key%20eq%20'$TAG_KEY'" \
curl -sSL -X PATCH "$BALENA_API_URL/v6/device_tag?\$filter=tag_key%20eq%20'$TAG_KEY'" \
-H "Authorization: Bearer $BALENA_API_KEY" \
-H "Content-Type: application/json" \
--data-binary '{"tag_key":"'$TAG_KEY'", "device":'$BALENA_DEVICE_ID', "value":"'$TAG_VALUE'"}'
Expand Down
Loading

0 comments on commit 2cd6211

Please sign in to comment.