Skip to content

Commit

Permalink
Update test scripts to credentials from json config file
Browse files Browse the repository at this point in the history
  • Loading branch information
shapovalovts committed Aug 11, 2024
1 parent 6636bdf commit d33d1c2
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 30 deletions.
8 changes: 4 additions & 4 deletions scripts/azure/api/create-partition.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

source ~/.swm/azure.env
source $(dirname "$0")/helpers.sh

CREDS=$(read_credentials azure)
CERT=~/.swm/cert.pem
KEY=~/.swm/key.pem
CA=/opt/swm/spool/secure/cluster/ca-chain-cert.pem
Expand All @@ -13,9 +13,9 @@ HOST=$(hostname -s)

REQUEST=POST
HEADER1="Accept: application/json"
HEADER2="subscriptionid: ${SUBSCRIPTION_ID}"
HEADER3="tenantid: ${TENANT_ID}"
HEADER4="appid: ${APP_ID}"
HEADER2="subscriptionid: $(echo $CREDS | jq -r '.subscription_id')"
HEADER3="tenantid: $(echo $CREDS | jq -r '.tenant_id')"
HEADER4="appid: $(echo $CREDS | jq -r '.app_id')"
HEADER5="osversion: ubuntu-22.04"
HEADER6="containerimage: swmregistry.azurecr.io/jupyter/datascience-notebook:hub-3.1.1"
HEADER7="containerregistryuser: $ACR_TOKEN_NAME"
Expand Down
8 changes: 4 additions & 4 deletions scripts/azure/api/delete-partition.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
PARTIOTION_ID=$1
#PARTITION_ID=/subscriptions/3f2fc2c5-8446-4cd5-af2f-a6af7f85ea75/resourceGroups/swm-02ccc5c0-resource-group

source ~/.swm/azure.env
source $(dirname "$0")/helpers.sh

CREDS=$(read_credentials azure)
CERT=~/.swm/cert.pem
KEY=~/.swm/key.pem
CA=/opt/swm/spool/secure/cluster/ca-chain-cert.pem
Expand All @@ -16,9 +16,9 @@ HOST=$(hostname -s)

REQUEST=DELETE
HEADER1="Accept: application/json"
HEADER2="subscriptionid: ${SUBSCRIPTION_ID}"
HEADER3="tenantid: ${TENANT_ID}"
HEADER4="appid: ${APP_ID}"
HEADER2="subscriptionid: $(echo $CREDS | jq -r '.subscription_id')"
HEADER3="tenantid: $(echo $CREDS | jq -r '.tenant_id')"
HEADER4="appid: $(echo $CREDS | jq -r '.app_id')"
URL="https://${HOST}:${PORT}/azure/partitions/$PARTIOTION_ID"
BODY='{"pem_data": '${PEM_DATA}'}'

Expand Down
12 changes: 8 additions & 4 deletions scripts/azure/api/get-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
IMAGE_ID=$1
#IMAGE_ID=/Subscriptions/3f2fc2c5-8446-4cd5-af2f-a6af7f85ea75/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/0001-com-ubuntu-server-jammy/Skus/22_04-lts/Versions/22.04.202407010

source ~/.swm/azure.env
source $(dirname "$0")/helpers.sh

CREDS=$(read_credentials azure)
CERT=~/.swm/cert.pem
KEY=~/.swm/key.pem
CA=/opt/swm/spool/secure/cluster/ca-chain-cert.pem
Expand All @@ -16,15 +16,19 @@ HOST=$(hostname -s)

REQUEST=GET
HEADER1="Accept: application/json"
HEADER2="subscriptionid: ${SUBSCRIPTION_ID}"
HEADER3="tenantid: ${TENANT_ID}"
HEADER4="appid: ${APP_ID}"
HEADER2="subscriptionid: $(echo $CREDS | jq -r '.subscription_id')"
HEADER3="tenantid: $(echo $CREDS | jq -r '.tenant_id')"
HEADER4="appid: $(echo $CREDS | jq -r '.app_id')"
URL="https://${HOST}:${PORT}/azure/images/${IMAGE_ID}"
BODY='{"pem_data": '${PEM_DATA}'}'

echo $URL
echo

echo $HEADER2
echo $HEADER3
echo $HEADER4

json=$(curl --request ${REQUEST}\
--cacert ${CA}\
--cert ${CERT}\
Expand Down
6 changes: 3 additions & 3 deletions scripts/azure/api/get-partition.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
PARTITION_ID=$1
#PARTITION_ID=/subscriptions/3f2fc2c5-8446-4cd5-af2f-a6af7f85ea75/resourceGroups/swm-02ccc5c0-resource-group

source ~/.swm/azure.env
source $(dirname "$0")/helpers.sh

CREDS=$(read_credentials azure)
CERT=~/.swm/cert.pem
KEY=~/.swm/key.pem
CA=/opt/swm/spool/secure/cluster/ca-chain-cert.pem
Expand All @@ -16,8 +16,8 @@ HOST=$(hostname -s)

REQUEST=GET
HEADER1="Accept: application/json"
HEADER2="tenantid: ${TENANT_ID}"
HEADER3="appid: ${APP_ID}"
HEADER2="tenantid: $(echo $CREDS | jq -r '.tenant_id')"
HEADER3="appid: $(echo $CREDS | jq -r '.app_id')"
URL="https://${HOST}:${PORT}/azure/partitions/${PARTITION_ID}"
BODY='{"pem_data": '${PEM_DATA}'}'

Expand Down
20 changes: 19 additions & 1 deletion scripts/azure/api/helpers.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function make_pem_data() {
make_pem_data() {
local cert=$1
local key=$2
local joined_content
Expand All @@ -11,3 +11,21 @@ function make_pem_data() {

printf "%s" "$joined_content"
}

read_credentials() {
local provider="$1"
local credentials_file="$HOME/.swm/credentials.json"

if [[ ! -f "$credentials_file" ]]; then
echo "Credentials file not found: $credentials_file" >&2
return 1
fi

local credentials=$(jq -r ".$provider" "$credentials_file")
if [[ -z "$credentials" ]]; then
echo "Provider '$provider' not found in credentials file" >&2
return 1
fi

echo "$credentials"
}
8 changes: 4 additions & 4 deletions scripts/azure/api/list-flavors.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

source ~/.swm/azure.env
source $(dirname "$0")/helpers.sh

CREDS=$(read_credentials azure)
CERT=~/.swm/cert.pem
KEY=~/.swm/key.pem
CA=/opt/swm/spool/secure/cluster/ca-chain-cert.pem
Expand All @@ -13,9 +13,9 @@ HOST=$(hostname -s)

REQUEST=GET
HEADER1="Accept: application/json"
HEADER2="subscriptionid: ${SUBSCRIPTION_ID}"
HEADER3="tenantid: ${TENANT_ID}"
HEADER4="appid: ${APP_ID}"
HEADER2="subscriptionid: $(echo $CREDS | jq -r '.subscription_id')"
HEADER3="tenantid: $(echo $CREDS | jq -r '.tenant_id')"
HEADER4="appid: $(echo $CREDS | jq -r '.app_id')"
HEADER5="location: eastus"
URL="https://${HOST}:${PORT}/azure/flavors"
BODY='{"pem_data": '${PEM_DATA}'}'
Expand Down
11 changes: 5 additions & 6 deletions scripts/azure/api/list-images.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash

source ~/.swm/azure.env
source $(dirname "$0")/helpers.sh

CREDS=$(read_credentials azure)
CERT=~/.swm/cert.pem
KEY=~/.swm/key.pem
CA=/opt/swm/spool/secure/cluster/ca-chain-cert.pem
PEM_DATA=$(make_pem_data $CERT $KEY)

LOCATION=eastus
PUBLISHER=Canonical
OFFER=0001-com-ubuntu-server-jammy
#SKUS=22_04-lts
Expand All @@ -18,10 +17,10 @@ HOST=$(hostname -s)

REQUEST=GET
HEADER1="Accept: application/json"
HEADER2="subscriptionid: ${SUBSCRIPTION_ID}"
HEADER3="tenantid: ${TENANT_ID}"
HEADER4="appid: ${APP_ID}"
HEADER5="location: ${LOCATION}"
HEADER2="subscriptionid: $(echo $CREDS | jq -r '.subscription_id')"
HEADER3="tenantid: $(echo $CREDS | jq -r '.tenant_id')"
HEADER4="appid: $(echo $CREDS | jq -r '.app_id')"
HEADER5="location: $(echo $CREDS | jq -r '.location')"
HEADER6="publisher: ${PUBLISHER}"
HEADER7="offer: ${OFFER}"
HEADER8="skus: ${SKUS}"
Expand Down
8 changes: 4 additions & 4 deletions scripts/azure/api/list-partitions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
PARTIOTION_ID=$1
#PARTITION_ID=/subscriptions/3f2fc2c5-8446-4cd5-af2f-a6af7f85ea75/resourceGroups/swm-02ccc5c0-resource-group

source ~/.swm/azure.env
source $(dirname "$0")/helpers.sh

CREDS=$(read_credentials azure)
CERT=~/.swm/cert.pem
KEY=~/.swm/key.pem
CA=/opt/swm/spool/secure/cluster/ca-chain-cert.pem
Expand All @@ -16,9 +16,9 @@ HOST=$(hostname -s)

REQUEST=GET
HEADER1="Accept: application/json"
HEADER2="subscriptionid: ${SUBSCRIPTION_ID}"
HEADER3="tenantid: ${TENANT_ID}"
HEADER4="appid: ${APP_ID}"
HEADER2="subscriptionid: $(echo $CREDS | jq -r '.subscription_id')"
HEADER3="tenantid: $(echo $CREDS | jq -r '.tenant_id')"
HEADER4="appid: $(echo $CREDS | jq -r '.app_id')"
URL="https://${HOST}:${PORT}/azure/partitions"
BODY='{"pem_data": '${PEM_DATA}'}'

Expand Down

0 comments on commit d33d1c2

Please sign in to comment.