diff --git a/.github/workflows/command_10_tests.yml b/.github/workflows/command_10_tests.yml deleted file mode 100644 index 37ed97e9..00000000 --- a/.github/workflows/command_10_tests.yml +++ /dev/null @@ -1,133 +0,0 @@ -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 deleted file mode 100644 index 430abefc..00000000 --- a/.github/workflows/command_11_tests.yml +++ /dev/null @@ -1,82 +0,0 @@ -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 new file mode 100644 index 00000000..a05a14fe --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,384 @@ +name: go 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 + + # 10.x.x + kf_10_x_x: + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run tests + run: echo "Running tests for KF 10.x.x" + + ### Store Type Tests + Test_StoreTypes_KFC_10_4_5: + runs-on: ubuntu-latest + needs: + - build + - kf_10_x_x + 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 + - kf_10_x_x + 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*" + +# Test_StoreTypes_KFC_10_1_1: +# runs-on: ubuntu-latest +# needs: +# - build +# - kf_10_x_x +# env: +# SECRET_NAME: "command-config-1011-clean" +# KEYFACTOR_HOSTNAME: "int1011-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 + - kf_10_x_x + - 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 + - kf_10_x_x + - 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_*" + +# Test_Stores_KFC_10_1_1: +# runs-on: ubuntu-latest +# needs: +# - build +# - kf_10_x_x +# - Test_StoreTypes_KFC_10_1_1 +# env: +# SECRET_NAME: "command-config-1011" +# KEYFACTOR_HOSTNAME: "integrations1011-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 + - kf_10_x_x + - 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 + - kf_10_x_x + - 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*" +# Test_PAM_KFC_10_1_1: +# runs-on: ubuntu-latest +# needs: +# - build +# - kf_10_x_x +# - Test_StoreTypes_KFC_10_1_1 +# env: +# SECRET_NAME: "command-config-1011" +# KEYFACTOR_HOSTNAME: "integrations1011-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*" + + ### PAM Tests AKV Auth Provider + Test_AKV_PAM_KFC_10_4_5: + runs-on: self-hosted + needs: + - Test_PAM_KFC_10_4_5 + env: + SECRET_NAME: "command-config-1045-az" + 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: Get secret from Azure Key Vault + run: | + . ./examples/auth/akv/akv_auth.sh + cat $HOME/.keyfactor/command_config.json + - name: Install kfutil + run: | + make install + - name: Run tests + run: | + go test -v ./cmd -run "^Test_PAM*" + + Test_AKV_PAM_KFC_10_2_1: + runs-on: self-hosted + needs: + - Test_PAM_KFC_10_2_1 + env: + SECRET_NAME: "command-config-1021-az" + 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: Get secret from Azure Key Vault + run: | + . ./examples/auth/akv/akv_auth.sh + cat $HOME/.keyfactor/command_config.json + - name: Install kfutil + run: | + make install + - name: Run tests + run: | + go test -v ./cmd -run "^Test_PAM*" +# Test_AKV_PAM_KFC_10_1_1: +# runs-on: self-hosted +# needs: +# - kf_10_x_x +# - Test_PAM_KFC_10_1_1 +# env: +# SECRET_NAME: "command-config-1011-az" +# 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: Get secret from Azure Key Vault +# run: | +# . ./examples/auth/akv/akv_auth.sh +# cat $HOME/.keyfactor/command_config.json +# - name: Install kfutil +# run: | +# make install +# - name: Run tests +# run: | +# go test -v ./cmd -run "^Test_PAM*" +# # 11.x.x +# kf_11_x_x: +# runs-on: ubuntu-latest +# needs: +# - build +# steps: +# - name: Checkout code +# uses: actions/checkout@v4 +# - name: Run tests +# run: echo "Running tests for KF 11.x.x" +# ### Store Type Tests +# Test_StoreTypes_KFC_11_0_0: +# runs-on: ubuntu-latest +# needs: +# - build +# - kf_11_x_x +# 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 +# - kf_11_x_x +# - 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 +# - kf_11_x_x +# - 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*" +# ### PAM Tests AKV Auth Provider +# Test_AKV_PAM_KFC_11_0_0: +# runs-on: self-hosted +# needs: +# - build +# - kf_11_x_x +# - Test_StoreTypes_KFC_11_0_0 +# - Test_PAM_KFC_11_0_0 +# env: +# SECRET_NAME: "command-config-1100-az" +# steps: +# - name: Checkout code +# uses: actions/checkout@v4 +# +# - name: Get secret from Azure Key Vault +# run: | +# . ./examples/auth/akv/akv_auth.sh +# +# - name: Run tests +# run: | +# unset KFUTIL_DEBUG +# kfutil logout || true +# printenv | grep -i keyfactor +# go test -v ./cmd -run "^Test_PAM*" \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 19db4f6f..e075736d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # v1.2.0 ## Features -feat(auth): Added support for sourcing credentials from [Azure Key Vault using Azure ID](docs/auth_providers#azure-key-vault) +feat(auth): Added support for sourcing credentials from [Azure Key Vault using Azure ID](docs/auth_providers.md#azure-key-vault) feat(cli): Added enhanced logging when `KFUTIL_DEBUG` is set. feat(store-types): `store-types create` now supports the `--all` flag. feat(stores): `stores` sub CLI is now non-experimental. [See docs](docs/kfutil_stores.md) diff --git a/GNUmakefile b/GNUmakefile index 3846d3e0..8846389f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -40,13 +40,14 @@ release: GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386 GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64 -install: fmt setversion +install: fmt go build -o ${BINARY} rm -rf ${INSTALLDIR}/${BINARY} mkdir -p ${INSTALLDIR} chmod oug+x ${BINARY} cp ${BINARY} ${INSTALLDIR} - mv ${BINARY} /usr/local/bin/${BINARY} + mkdir -p ${HOME}/.local/bin || true + mv ${BINARY} ${HOME}/.local/bin/${BINARY} vendor: go mod vendor diff --git a/cmd/login.go b/cmd/login.go index 48cc1a54..ac3c316e 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -17,6 +17,7 @@ package cmd import ( "encoding/json" "fmt" + "github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor" "github.com/Keyfactor/keyfactor-go-client/v2/api" "github.com/google/go-cmp/cmp" "github.com/rs/zerolog/log" @@ -597,6 +598,100 @@ func authViaProvider() (*api.Client, error) { return nil, fmt.Errorf("unable to auth via provider, providerType is empty") } +func authViaProviderGenClient() (*keyfactor.APIClient, error) { + var commandConfig ConfigurationFile + if providerType != "" { + log.Info().Str("providerType", providerType).Msg("attempting to auth via auth provider") + var providerConfig AuthProvider + if providerProfile == "" { + log.Info().Str("providerProfile", providerProfile).Msg("auth provider profile not set, defaulting to 'default'") + providerProfile = "default" + } + + providerConfig = AuthProvider{ + Type: providerType, + Profile: providerProfile, + Parameters: nil, + } + + if configFile == "" { + homeDir, hdErr := os.UserHomeDir() + if hdErr != nil { + homeDir, hdErr = os.Getwd() + if hdErr != nil { + homeDir = "." // Default to current directory + } + } + configFile = path.Join(homeDir, ".keyfactor", DefaultConfigFileName) + } + + // Load config file + log.Debug().Str("configFile", configFile).Msg("configFile is set, loading config file") + log.Debug().Msg("calling loadConfigurationFile()") + configurationFile, cErr := loadConfigurationFile(configFile, true) + log.Debug().Msg("loadConfigurationFile() returned") + if cErr != nil { + log.Error().Err(cErr).Msg("unable to load provider config file") + return nil, cErr + } + // look for profile in config file + log.Debug().Str("profile", profile). + Str("providerProfile", providerProfile). + Msg("checking if providerProfile exists in config file") + + providerConfigEntry, providerProfileExists := configurationFile.Servers[providerProfile] + if !providerProfileExists { + log.Error().Str("providerProfile", providerProfile).Msg("providerProfile does not exist in config file") + return nil, fmt.Errorf("providerProfile '%s' does not exist in config file", providerProfile) + } + params := providerConfigEntry.AuthProvider.Parameters + if params == nil { + log.Error().Msg("providerProfile parameters are empty") + return nil, fmt.Errorf("providerProfile '%s' parameters are empty", providerProfile) + } + providerConfig.Parameters = params + + log.Debug().Str("providerConfig.Type", providerConfig.Type). + Msg("call: authViaProviderParams()") + pvConfig, pErr := authViaProviderParams(&providerConfig) + log.Debug().Msg("returned: authViaProviderParams()") + if pErr != nil { + log.Error().Err(pErr). + Str("providerConfig.Type", providerConfig.Type). + Str("providerConfig.Profile", providerConfig.Profile). + Msg("unable to auth via provider") + return nil, pErr + } + log.Trace().Interface("pvConfig", pvConfig).Send() + + commandConfig = pvConfig + sdkClientConfig := make(map[string]string) + sdkClientConfig["host"] = commandConfig.Servers[providerProfile].Hostname + sdkClientConfig["username"] = commandConfig.Servers[providerProfile].Username + sdkClientConfig["password"] = commandConfig.Servers[providerProfile].Password + sdkClientConfig["domain"] = commandConfig.Servers[providerProfile].Domain + sdkClientConfig["apiPath"] = commandConfig.Servers[providerProfile].APIPath + + log.Debug().Str("clientAuth.Username", sdkClientConfig["username"]). + Str("clientAuth.Password", hashSecretValue(sdkClientConfig["password"])). + Str("clientAuth.Domain", sdkClientConfig["domain"]). + Str("clientAuth.Hostname", sdkClientConfig["host"]). + Str("clientAuth.APIPath", sdkClientConfig["apiPath"]). + Msg("Client authentication params") + + log.Debug().Msg("call: api.NewKeyfactorClient()") + configuration := keyfactor.NewConfiguration(sdkClientConfig) + c := keyfactor.NewAPIClient(configuration) + log.Debug().Msg("complete: api.NewKeyfactorClient()") + log.Info().Msg("Keyfactor Command client created") + log.Debug().Str("flagAuthProvider", providerType). + Str("providerProfile", providerProfile). + Msg("returning from provider auth") + return c, nil + } + return nil, fmt.Errorf("unable to auth via provider, providerType is empty") +} + func authViaProviderParams(providerConfig *AuthProvider) (ConfigurationFile, error) { pt := providerConfig.Type diff --git a/cmd/root.go b/cmd/root.go index dce81d68..68b0ea52 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -200,6 +200,10 @@ func initClient(flagConfigFile string, flagProfile string, flagAuthProviderType func initGenClient(flagConfig string, flagProfile string, noPrompt bool, authConfig *api.AuthConfig, saveConfig bool) (*keyfactor.APIClient, error) { var commandConfig ConfigurationFile + if providerType != "" { + return authViaProviderGenClient() + } + commandConfig, _ = authEnvVars(flagConfig, "", saveConfig) if flagConfig != "" || !validConfigFileEntry(commandConfig, flagProfile) {