diff --git a/.github/workflows/command_10_tests.yml b/.github/workflows/command_10_tests.yml new file mode 100644 index 00000000..37ed97e9 --- /dev/null +++ b/.github/workflows/command_10_tests.yml @@ -0,0 +1,133 @@ +name: KFC 10.X.X Tests + +on: + push: + branches: + - "*" + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: Install dependencies + run: go mod download && go mod tidy + - name: Install Azure CLI + run: | + curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash + az --version + + + ### Store Type Tests + Test_StoreTypes_KFC_10_4_5: + runs-on: ubuntu-latest + needs: build + env: + SECRET_NAME: "command-config-1045-clean" + KEYFACTOR_HOSTNAME: "int1045-test-clean.kfdelivery.com" + KEYFACTOR_DOMAIN: "command" + KEYFACTOR_USERNAME: ${{ secrets.LAB_USERNAME }} + KEYFACTOR_PASSWORD: ${{ secrets.LAB_PASSWORD }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: | + unset KFUTIL_DEBUG + go test -v ./cmd -run "^Test_StoreTypes*" + Test_StoreTypes_KFC_10_2_1: + runs-on: ubuntu-latest + needs: build + env: + SECRET_NAME: "command-config-1021-clean" + KEYFACTOR_HOSTNAME: "int1021-test-clean.kfdelivery.com" + KEYFACTOR_DOMAIN: "command" + KEYFACTOR_USERNAME: ${{ secrets.LAB_USERNAME }} + KEYFACTOR_PASSWORD: ${{ secrets.LAB_PASSWORD }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: | + unset KFUTIL_DEBUG + go test -v ./cmd -run "^Test_StoreTypes*" + + ### Store Tests + Test_Stores_KFC_10_4_5: + runs-on: ubuntu-latest + needs: + - build + - Test_StoreTypes_KFC_10_4_5 + env: + SECRET_NAME: "command-config-1045" + KEYFACTOR_HOSTNAME: "integrations1045-lab.kfdelivery.com" + KEYFACTOR_DOMAIN: "command" + KEYFACTOR_USERNAME: ${{ secrets.LAB_USERNAME }} + KEYFACTOR_PASSWORD: ${{ secrets.LAB_PASSWORD }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: go test -v ./cmd -run "^Test_Stores_*" + Test_Stores_KFC_10_2_1: + runs-on: ubuntu-latest + needs: + - build + - Test_StoreTypes_KFC_10_2_1 + env: + SECRET_NAME: "command-config-1021" + KEYFACTOR_HOSTNAME: "integrations1021-lab.kfdelivery.com" + KEYFACTOR_DOMAIN: "command" + KEYFACTOR_USERNAME: ${{ secrets.LAB_USERNAME }} + KEYFACTOR_PASSWORD: ${{ secrets.LAB_PASSWORD }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: | + unset KFUTIL_DEBUG + go test -v ./cmd -run "^Test_Stores_*" + + ### PAM Tests + Test_PAM_KFC_10_4_5: + runs-on: ubuntu-latest + needs: + - build + - Test_StoreTypes_KFC_10_4_5 + env: + SECRET_NAME: "command-config-1045" + KEYFACTOR_HOSTNAME: "integrations1045-lab.kfdelivery.com" + KEYFACTOR_DOMAIN: "command" + KEYFACTOR_USERNAME: ${{ secrets.LAB_USERNAME }} + KEYFACTOR_PASSWORD: ${{ secrets.LAB_PASSWORD }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: | + unset KFUTIL_DEBUG + go test -v ./cmd -run "^Test_PAM*" + Test_PAM_KFC_10_2_1: + runs-on: ubuntu-latest + needs: + - build + - Test_StoreTypes_KFC_10_2_1 + env: + SECRET_NAME: "command-config-1021" + KEYFACTOR_HOSTNAME: "integrations1021-lab.kfdelivery.com" + KEYFACTOR_DOMAIN: "command" + KEYFACTOR_USERNAME: ${{ secrets.LAB_USERNAME }} + KEYFACTOR_PASSWORD: ${{ secrets.LAB_PASSWORD }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: | + unset KFUTIL_DEBUG + go test -v ./cmd -run "^Test_PAM*" \ No newline at end of file diff --git a/.github/workflows/command_11_tests.yml b/.github/workflows/command_11_tests.yml new file mode 100644 index 00000000..430abefc --- /dev/null +++ b/.github/workflows/command_11_tests.yml @@ -0,0 +1,82 @@ +name: KFC 11.X.X Tests + +on: + push: + branches: + - "*" + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: Install dependencies + run: go mod download && go mod tidy + - name: Install Azure CLI + run: | + curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash + az --version + + ### Store Type Tests + Test_StoreTypes_KFC_11_0_0: + runs-on: ubuntu-latest + needs: build + env: + SECRET_NAME: "command-config-1100-clean" + KEYFACTOR_HOSTNAME: "int11-test-clean.kfdelivery.com" + KEYFACTOR_DOMAIN: "command" + KEYFACTOR_USERNAME: ${{ secrets.LAB_USERNAME }} + KEYFACTOR_PASSWORD: ${{ secrets.LAB_PASSWORD }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: | + unset KFUTIL_DEBUG + go test -v ./cmd -run "^Test_StoreTypes*" + + ### Store Tests + Test_Stores_KFC_11_0_0: + runs-on: ubuntu-latest + needs: + - build + - Test_StoreTypes_KFC_11_0_0 + env: + SECRET_NAME: "command-config-1100" + KEYFACTOR_HOSTNAME: "integrations1100b3-lab.kfdelivery.com" + KEYFACTOR_DOMAIN: "command" + KEYFACTOR_USERNAME: ${{ secrets.LAB_USERNAME }} + KEYFACTOR_PASSWORD: ${{ secrets.LAB_PASSWORD }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: | + unset KFUTIL_DEBUG + go test -v ./cmd -run "^Test_Stores_*" + + ### PAM Tests + Test_PAM_KFC_11_0_0: + runs-on: ubuntu-latest + needs: + - build + - Test_StoreTypes_KFC_11_0_0 + env: + SECRET_NAME: "command-config-1100" + KEYFACTOR_HOSTNAME: "integrations1100b3-lab.kfdelivery.com" + KEYFACTOR_DOMAIN: "command" + KEYFACTOR_USERNAME: ${{ secrets.LAB_USERNAME }} + KEYFACTOR_PASSWORD: ${{ secrets.LAB_PASSWORD }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: | + unset KFUTIL_DEBUG + go test -v ./cmd -run "^Test_PAM*" \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 8109d1b9..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,197 +0,0 @@ -name: Go Test - -on: - push: - branches: - - "*" - workflow_dispatch: - -jobs: - build: - runs-on: self-hosted - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - - name: Install dependencies - run: go mod download && go mod tidy - - - name: Install Azure CLI - run: | - curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash - az --version - - # Store Type Tests - Test_Stores_KFC_11_0_0: - runs-on: self-hosted - needs: build - env: - SECRET_NAME: "command-config-1100" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: list dir - run: ls -la - - - name: Get secret from Azure Key Vault - run: | - . ./examples/auth/akv/akv_auth.sh - - - name: Run tests - run: go test -v ./cmd -run "^Test_Stores*" - - Test_StoreTypes_KFC_10_4_0: - runs-on: self-hosted - needs: build - env: - SECRET_NAME: "command-config-1040-clean" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: list dir - run: ls -la - - - name: Get secret from Azure Key Vault - run: | - . ./examples/auth/akv/akv_auth.sh - - - name: Run tests - run: go test -v ./cmd -run "^Test_StoreType*" - Test_StoreTypes_KFC_10_2_1: - runs-on: self-hosted - needs: build - env: - SECRET_NAME: "command-config-1021-clean" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: list dir - run: ls -la - - - name: Get secret from Azure Key Vault - run: | - . ./examples/auth/akv/akv_auth.sh - - - name: Run tests - run: go test -v ./cmd -run "^Test_StoreType*" - - # Store Tests - Test_StoreTypes_KFC_11_0_0: - runs-on: self-hosted - needs: build - env: - SECRET_NAME: "command-config-1100-clean" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: list dir - run: ls -la - - - name: Get secret from Azure Key Vault - run: | - . ./examples/auth/akv/akv_auth.sh - - - name: Run tests - run: go test -v ./cmd -run "^Test_StoreType*" - Test_Stores_KFC_10_4_0: - runs-on: self-hosted - needs: build - env: - SECRET_NAME: "command-config-1040" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: list dir - run: ls -la - - - name: Get secret from Azure Key Vault - run: | - . ./examples/auth/akv/akv_auth.sh - - - name: Run tests - run: go test -v ./cmd -run "^Test_Stores*" - Test_Stores_KFC_10_2_1: - runs-on: self-hosted - needs: build - env: - SECRET_NAME: "command-config-1021" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: list dir - run: ls -la - - - name: Get secret from Azure Key Vault - run: | - . ./examples/auth/akv/akv_auth.sh - - - name: Run tests - run: go test -v ./cmd -run "^Test_Stores*" - - # PAM Tests - Test_PAM_KFC_11_0_0: - runs-on: self-hosted - needs: build - env: - SECRET_NAME: "command-config-1100" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: list dir - run: ls -la - - - name: Get secret from Azure Key Vault - run: | - . ./examples/auth/akv/akv_auth.sh - - - name: Run tests - run: go test -v ./cmd -run "^Test_PAM*" - Test_PAM_KFC_10_4_0: - runs-on: self-hosted - needs: build - env: - SECRET_NAME: "command-config-1040" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: list dir - run: ls -la - - - name: Get secret from Azure Key Vault - run: | - . ./examples/auth/akv/akv_auth.sh - - - name: Run tests - run: go test -v ./cmd -run "^Test_PAM*" - Test_PAM_KFC_10_2_1: - runs-on: self-hosted - needs: build - env: - SECRET_NAME: "command-config-1021" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: list dir - run: ls -la - - - name: Get secret from Azure Key Vault - run: | - . ./examples/auth/akv/akv_auth.sh - - - name: Run tests - run: go test -v ./cmd -run "^Test_PAM*" \ No newline at end of file diff --git a/cmd/helpers.go b/cmd/helpers.go index 917e7923..a60e73d5 100644 --- a/cmd/helpers.go +++ b/cmd/helpers.go @@ -19,11 +19,11 @@ import ( "encoding/json" "errors" "fmt" + "github.com/google/uuid" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "io" - "math/rand" "net/http" "os" "path/filepath" @@ -201,13 +201,13 @@ func isExperimentalFeatureEnabled(expFlag bool, isExperimental bool) (bool, erro return envValue, nil } -func generateRandomNumberString(length int) string { - // Generate a random number string of the specified length - var numberString string - for i := 0; i < length; i++ { - numberString += fmt.Sprintf("%d", rand.Intn(10)) +func generateRandomUUID() string { + uuidObj, err := uuid.NewRandom() + if err != nil { + // Handle the error if UUID generation fails. + panic(err) } - return numberString + return uuidObj.String() } func loadJSONFile(filename string) (map[string]interface{}, error) { diff --git a/cmd/pam.go b/cmd/pam.go index 421c89b4..cd894670 100644 --- a/cmd/pam.go +++ b/cmd/pam.go @@ -81,7 +81,7 @@ var pamTypesListCmd = &cobra.Command{ log.Error().Err(mErr).Send() return mErr } - log.Info().Str("output", string(jsonString)). + log.Info(). Msg("successfully listed PAM provider types") outputResult(jsonString, outputFormat) return nil @@ -102,7 +102,7 @@ https://github.com/Keyfactor/hashicorp-vault-pam/blob/main/integration-manifest. // Specific flags pamConfigFile, _ := cmd.Flags().GetString("from-file") - providerName, _ := cmd.Flags().GetString("name") + pamProviderName, _ := cmd.Flags().GetString("name") repoName, _ := cmd.Flags().GetString("repo") branchName, _ := cmd.Flags().GetString("branch") @@ -114,7 +114,7 @@ https://github.com/Keyfactor/hashicorp-vault-pam/blob/main/integration-manifest. } // Log flags - log.Info().Str("name", providerName). + log.Info().Str("name", pamProviderName). Str("repo", repoName). Str("branch", branchName). Msg("create PAM Provider Type") @@ -140,11 +140,11 @@ https://github.com/Keyfactor/hashicorp-vault-pam/blob/main/integration-manifest. if repoName != "" { // get JSON config from integration-manifest on GitHub log.Debug(). - Str("providerName", providerName). + Str("pamProviderName", pamProviderName). Str("repoName", repoName). Str("branchName", branchName). Msg("call: GetTypeFromInternet()") - pamProviderType, err = GetTypeFromInternet(providerName, repoName, branchName, pamProviderType) + pamProviderType, err = GetTypeFromInternet(pamProviderName, repoName, branchName, pamProviderType) log.Debug().Msg("returned: GetTypeFromInternet()") if err != nil { log.Error().Err(err).Send() @@ -161,10 +161,13 @@ https://github.com/Keyfactor/hashicorp-vault-pam/blob/main/integration-manifest. } } - if providerName != "" { - pamProviderType.Name = providerName + if pamProviderName != "" { + pamProviderType.Name = pamProviderName } + log.Info().Str("pamProviderName", pamProviderType.Name). + Msg("creating PAM provider type") + log.Debug().Msg("call: PAMProviderCreatePamProviderType()") createdPamProviderType, httpResponse, rErr := sdkClient.PAMProviderApi.PAMProviderCreatePamProviderType(context.Background()). XKeyfactorRequestedWith(XKeyfactorRequestedWith).XKeyfactorApiVersion(XKeyfactorApiVersion). @@ -174,7 +177,7 @@ https://github.com/Keyfactor/hashicorp-vault-pam/blob/main/integration-manifest. log.Trace().Interface("httpResponse", httpResponse).Msg("PAMProviderCreatePamProviderType") if rErr != nil { log.Error().Err(rErr).Send() - return rErr + return returnHttpErr(httpResponse, rErr) } log.Debug().Msg("Converting PAM Provider Type response to JSON") diff --git a/cmd/pam_test.go b/cmd/pam_test.go index 330c4eba..c07a44c7 100644 --- a/cmd/pam_test.go +++ b/cmd/pam_test.go @@ -19,6 +19,8 @@ import ( "fmt" "github.com/stretchr/testify/assert" "os" + "path" + "path/filepath" "strconv" "strings" "testing" @@ -165,7 +167,8 @@ func Test_PAMGetCmd(t *testing.T) { func Test_PAMTypesCreateCmd(t *testing.T) { testCmd := RootCmd // test - randomName := "test-" + generateRandomNumberString(5) + randomName := generateRandomUUID() + t.Logf("randomName: %s", randomName) testCmd.SetArgs([]string{"pam", "types-create", "--repo", "hashicorp-vault-pam", "--name", randomName}) output := captureOutput(func() { err := testCmd.Execute() @@ -173,6 +176,7 @@ func Test_PAMTypesCreateCmd(t *testing.T) { }) var createResponse interface{} if err := json.Unmarshal([]byte(output), &createResponse); err != nil { + t.Log(output) t.Fatalf("Error unmarshalling JSON: %v", err) } assert.NotEmpty(t, createResponse.(map[string]interface{})["Id"]) @@ -183,9 +187,17 @@ func Test_PAMTypesCreateCmd(t *testing.T) { func Test_PAMCreateCmd(t *testing.T) { // test + + // get current working dir + cwd, _ := os.Getwd() + t.Logf("cwd: %s", cwd) + providerName := "Delinea-SecretServer-test" - inputFileName := "artifacts/pam/pam-create-template.json" - invalidInputFileName := "pam-create-invalid.json" + t.Logf("providerName: %s", providerName) + inputFileName := path.Join(filepath.Dir(cwd), "artifacts/pam/pam-create-template.json") + t.Logf("inputFileName: %s", inputFileName) + invalidInputFileName := path.Join(filepath.Dir(cwd), "artifacts/pam/pam-create-invalid.json") + t.Logf("invalidInputFileName: %s", invalidInputFileName) //cProviderTypeName := "Delinea-SecretServer" // read input file into a map[string]interface{} @@ -232,11 +244,17 @@ func Test_PAMCreateCmd(t *testing.T) { } func Test_PAMUpdateCmd(t *testing.T) { - //updatedName := "Delinea-SecretServer-test-updated" // test + // get current working dir + cwd, _ := os.Getwd() + t.Logf("cwd: %s", cwd) + providerName := "Delinea-SecretServer-test" - inputFileName := "artifacts/pam/pam-create-template.json" - //cProviderTypeName := "Delinea-SecretServer" + t.Logf("providerName: %s", providerName) + inputFileName := path.Join(filepath.Dir(cwd), "artifacts/pam/pam-create-template.json") + t.Logf("inputFileName: %s", inputFileName) + invalidInputFileName := path.Join(filepath.Dir(cwd), "artifacts/pam/pam-create-invalid.json") + t.Logf("invalidInputFileName: %s", invalidInputFileName) // read input file into a map[string]interface{} updatedFileName, fErr := testFormatPamCreateConfig(t, inputFileName, "", false) @@ -282,8 +300,17 @@ func Test_PAMUpdateCmd(t *testing.T) { func Test_PAMDeleteCmd(t *testing.T) { // test + // get current working dir + cwd, _ := os.Getwd() + t.Logf("cwd: %s", cwd) + providerName := "Delinea-SecretServer-test" - inputFileName := "artifacts/pam/pam-create-template.json" + t.Logf("providerName: %s", providerName) + inputFileName := path.Join(filepath.Dir(cwd), "artifacts/pam/pam-create-template.json") + t.Logf("inputFileName: %s", inputFileName) + invalidInputFileName := path.Join(filepath.Dir(cwd), "artifacts/pam/pam-create-invalid.json") + t.Logf("invalidInputFileName: %s", invalidInputFileName) + //cProviderTypeName := "Delinea-SecretServer" // read input file into a map[string]interface{} diff --git a/cmd/storeTypes.go b/cmd/storeTypes.go index 14d1827a..e0847207 100644 --- a/cmd/storeTypes.go +++ b/cmd/storeTypes.go @@ -47,6 +47,7 @@ var storesTypesListCmd = &cobra.Command{ if debugErr != nil { return debugErr } + informDebug(debugFlag) // Authenticate authConfig := createAuthConfigFromParams(kfcHostName, kfcUsername, kfcPassword, kfcDomain, kfcAPIPath) @@ -84,11 +85,11 @@ var storesTypeGetCmd = &cobra.Command{ // Debug + expEnabled checks isExperimental := false - informDebug(debugFlag) debugErr := warnExperimentalFeature(expEnabled, isExperimental) if debugErr != nil { return debugErr } + informDebug(debugFlag) // Authenticate authConfig := createAuthConfigFromParams(kfcHostName, kfcUsername, kfcPassword, kfcDomain, kfcAPIPath) @@ -411,12 +412,12 @@ var fetchStoreTypes = &cobra.Command{ gitRef, _ := cmd.Flags().GetString(FlagGitRef) // Debug + expEnabled checks - informDebug(debugFlag) isExperimental := false debugErr := warnExperimentalFeature(expEnabled, isExperimental) if debugErr != nil { return debugErr } + informDebug(debugFlag) if gitRef == "" { gitRef = "main" diff --git a/cmd/stores_test.go b/cmd/stores_test.go index cdd36421..b9500c88 100644 --- a/cmd/stores_test.go +++ b/cmd/stores_test.go @@ -24,7 +24,7 @@ import ( "testing" ) -func Test_StoresHelpCmd(t *testing.T) { +func Test_Stores_HelpCmd(t *testing.T) { // Test root help testCmd := RootCmd testCmd.SetArgs([]string{"stores", "--help"}) @@ -48,7 +48,7 @@ func Test_StoresHelpCmd(t *testing.T) { } } -func Test_StoresListCmd(t *testing.T) { +func Test_Stores_ListCmd(t *testing.T) { testCmd := RootCmd // test testCmd.SetArgs([]string{"stores", "list", "--exp"}) @@ -76,7 +76,7 @@ func Test_StoresListCmd(t *testing.T) { } } -func Test_StoresGetCmd(t *testing.T) { +func Test_Stores_GetCmd(t *testing.T) { testCmd := RootCmd // test testCmd.SetArgs([]string{"stores", "list", "--exp"}) @@ -124,19 +124,19 @@ func Test_StoresGetCmd(t *testing.T) { } } -func Test_StoresCreateCmd(t *testing.T) { +func Test_Stores_CreateCmd(t *testing.T) { // TODO: test create command } -func Test_StoresUpdateCmd(t *testing.T) { +func Test_Stores_UpdateCmd(t *testing.T) { // TODO: test update command } -func Test_StoresDeleteCmd(t *testing.T) { +func Test_Stores_DeleteCmd(t *testing.T) { // This is covered by import/export tests } -func Test_StoresImportCmd(t *testing.T) { +func Test_Stores_ImportCmd(t *testing.T) { // first export a store _, files := testExportStore(t, "k8ssecret") @@ -163,7 +163,7 @@ func Test_StoresImportCmd(t *testing.T) { // modify row row["Id"] = "" - row["StorePath"] = fmt.Sprintf("%s-test-%s", row["StorePath"], generateRandomNumberString(6)) + row["StorePath"] = fmt.Sprintf("%s-test-%s", row["StorePath"], generateRandomUUID()) row["Properties.ServerUsername"] = "kubeconfig" row["Properties.ServerPassword"] = "test" @@ -202,7 +202,7 @@ func Test_StoresImportCmd(t *testing.T) { } } -func Test_StoresExportCmd(t *testing.T) { +func Test_Stores_ExportCmd(t *testing.T) { // test _, files := testExportStore(t, "k8ssecret") @@ -225,7 +225,7 @@ func Test_StoresExportCmd(t *testing.T) { } } -func Test_StoresGenerateImportTemplateCmd(t *testing.T) { +func Test_Stores_GenerateImportTemplateCmd(t *testing.T) { testCmd := RootCmd // test testCmd.SetArgs([]string{"stores", "import", "generate-template", "--store-type-name", "k8ssecret", "--exp"}) diff --git a/examples/auth/akv/akv_auth.sh b/examples/auth/akv/akv_auth.sh index e481fe60..cd3aa69d 100644 --- a/examples/auth/akv/akv_auth.sh +++ b/examples/auth/akv/akv_auth.sh @@ -4,6 +4,8 @@ set -e -o pipefail # Define the default values using environment variables default_vault_name="${VAULT_NAME:-kfutil}" default_secret_name="${SECRET_NAME:-integration-labs}" +echo "Default vault name: $default_vault_name" +echo "Default secret name: $default_secret_name" export METADATA_URL="http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://vault.azure.net" @@ -11,6 +13,10 @@ export METADATA_URL="http://169.254.169.254/metadata/identity/oauth2/token?api-v read_keyvault_secret() { local vault_name="$1" local secret_name="$2" + + echo "Vault Name: $vault_name" + echo "Secret Name: $secret_name" + # Make a request to the metadata endpoint echo "Querying metadata endpoint for access token..." echo "Metadata URL: $METADATA_URL" @@ -36,7 +42,9 @@ read_keyvault_secret() { #echo "Secret Value: $secret_value" mkdir -p ~/.keyfactor - echo $secret_value | jq -r . > ~/.keyfactor/command_config.json + echo "${secret_value}" | jq -r . > "${secret_name}.json" + rm -f "${HOME}/.keyfactor/command_config.json" || true + echo "${secret_value}" | jq -r . > "${HOME}/.keyfactor/command_config.json" # echo $secret_value > .env }