From cc02fdc90828fc91f7c3e1cce468fca8d2edd48f Mon Sep 17 00:00:00 2001 From: raymond zhang Date: Wed, 29 Mar 2023 11:31:51 -0700 Subject: [PATCH] added an environment variable for testing --- tkg/test/ui/data/aws/aws-test-1-output-config.yaml | 2 +- tkg/web/server/handlers/export.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tkg/test/ui/data/aws/aws-test-1-output-config.yaml b/tkg/test/ui/data/aws/aws-test-1-output-config.yaml index f51aa658c2..a16d9d240f 100644 --- a/tkg/test/ui/data/aws/aws-test-1-output-config.yaml +++ b/tkg/test/ui/data/aws/aws-test-1-output-config.yaml @@ -1 +1 @@ -"AWS_AMI_ID: ami-012886bac01b37bae\nAWS_NODE_AZ: us-west-a\nAWS_NODE_AZ_1: \"\"\nAWS_NODE_AZ_2: \"\"\nAWS_PRIVATE_NODE_CIDR: \"\"\nAWS_PRIVATE_NODE_CIDR_1: \"\"\nAWS_PRIVATE_NODE_CIDR_2: \"\"\nAWS_PRIVATE_SUBNET_ID: sn4\nAWS_PRIVATE_SUBNET_ID_1: \"\"\nAWS_PRIVATE_SUBNET_ID_2: \"\"\nAWS_PROFILE: profile1\nAWS_PUBLIC_NODE_CIDR: \"\"\nAWS_PUBLIC_NODE_CIDR_1: \"\"\nAWS_PUBLIC_NODE_CIDR_2: \"\"\nAWS_PUBLIC_SUBNET_ID: sn1\nAWS_PUBLIC_SUBNET_ID_1: \"\"\nAWS_PUBLIC_SUBNET_ID_2: \"\"\nAWS_REGION: us-west-2\nAWS_SSH_KEY_NAME: myKeyPair\nAWS_VPC_CIDR: \"\"\nAWS_VPC_ID: vpc-1\nBASTION_HOST_ENABLED: \"true\"\nCLUSTER_ANNOTATIONS: 'description:,location:'\nCLUSTER_CIDR: 100.96.0.0/11\nCLUSTER_NAME: my-aws-name\nCLUSTER_PLAN: dev\nCONTROL_PLANE_MACHINE_TYPE: c6gn.medium\nENABLE_AUDIT_LOGGING: \"\"\nENABLE_CEIP_PARTICIPATION: \"true\"\nENABLE_MHC: \"false\"\nIDENTITY_MANAGEMENT_TYPE: none\nINFRASTRUCTURE_PROVIDER: aws\nLDAP_BIND_DN: \"\"\nLDAP_BIND_PASSWORD: \"\"\nLDAP_GROUP_SEARCH_BASE_DN: \"\"\nLDAP_GROUP_SEARCH_FILTER: \"\"\nLDAP_GROUP_SEARCH_GROUP_ATTRIBUTE: \"\"\nLDAP_GROUP_SEARCH_NAME_ATTRIBUTE: cn\nLDAP_GROUP_SEARCH_USER_ATTRIBUTE: DN\nLDAP_HOST: \"\"\nLDAP_ROOT_CA_DATA_B64: \"\"\nLDAP_USER_SEARCH_BASE_DN: \"\"\nLDAP_USER_SEARCH_FILTER: \"\"\nLDAP_USER_SEARCH_NAME_ATTRIBUTE: \"\"\nLDAP_USER_SEARCH_USERNAME: userPrincipalName\nNODE_MACHINE_TYPE: c6gn.medium\nOIDC_IDENTITY_PROVIDER_CLIENT_ID: \"\"\nOIDC_IDENTITY_PROVIDER_CLIENT_SECRET: \"\"\nOIDC_IDENTITY_PROVIDER_GROUPS_CLAIM: \"\"\nOIDC_IDENTITY_PROVIDER_ISSUER_URL: \"\"\nOIDC_IDENTITY_PROVIDER_NAME: \"\"\nOIDC_IDENTITY_PROVIDER_SCOPES: \"\"\nOIDC_IDENTITY_PROVIDER_USERNAME_CLAIM: \"\"\nOS_ARCH: amd64\nOS_NAME: amazon\nOS_VERSION: \"2\"\nSERVICE_CIDR: 100.64.0.0/13\nTKG_HTTP_PROXY_ENABLED: \"false\"\n" +"AWS_AMI_ID: ami-09a464de0bba738ff\nAWS_B64ENCODED_CREDENTIALS: foobar\nAWS_NODE_AZ: us-west-a\nAWS_NODE_AZ_1: \"\"\nAWS_NODE_AZ_2: \"\"\nAWS_PRIVATE_NODE_CIDR: \"\"\nAWS_PRIVATE_NODE_CIDR_1: \"\"\nAWS_PRIVATE_NODE_CIDR_2: \"\"\nAWS_PRIVATE_SUBNET_ID: sn4\nAWS_PRIVATE_SUBNET_ID_1: \"\"\nAWS_PRIVATE_SUBNET_ID_2: \"\"\nAWS_PROFILE: profile1\nAWS_PUBLIC_NODE_CIDR: \"\"\nAWS_PUBLIC_NODE_CIDR_1: \"\"\nAWS_PUBLIC_NODE_CIDR_2: \"\"\nAWS_PUBLIC_SUBNET_ID: sn1\nAWS_PUBLIC_SUBNET_ID_1: \"\"\nAWS_PUBLIC_SUBNET_ID_2: \"\"\nAWS_REGION: us-west-2\nAWS_SSH_KEY_NAME: myKeyPair\nAWS_VPC_CIDR: \"\"\nAWS_VPC_ID: vpc-1\nBASTION_HOST_ENABLED: \"true\"\nCLUSTER_ANNOTATIONS: 'description:,location:'\nCLUSTER_CIDR: 100.96.0.0/11\nCLUSTER_NAME: my-aws-name\nCLUSTER_PLAN: dev\nCONTROL_PLANE_MACHINE_TYPE: c6gn.medium\nENABLE_AUDIT_LOGGING: \"\"\nENABLE_CEIP_PARTICIPATION: \"true\"\nENABLE_MHC: \"false\"\nIDENTITY_MANAGEMENT_TYPE: none\nINFRASTRUCTURE_PROVIDER: aws\nLDAP_BIND_DN: \"\"\nLDAP_BIND_PASSWORD: \"\"\nLDAP_GROUP_SEARCH_BASE_DN: \"\"\nLDAP_GROUP_SEARCH_FILTER: \"\"\nLDAP_GROUP_SEARCH_GROUP_ATTRIBUTE: \"\"\nLDAP_GROUP_SEARCH_NAME_ATTRIBUTE: cn\nLDAP_GROUP_SEARCH_USER_ATTRIBUTE: DN\nLDAP_HOST: \"\"\nLDAP_ROOT_CA_DATA_B64: \"\"\nLDAP_USER_SEARCH_BASE_DN: \"\"\nLDAP_USER_SEARCH_FILTER: \"\"\nLDAP_USER_SEARCH_NAME_ATTRIBUTE: \"\"\nLDAP_USER_SEARCH_USERNAME: userPrincipalName\nNODE_MACHINE_TYPE: c6gn.medium\nOIDC_IDENTITY_PROVIDER_CLIENT_ID: \"\"\nOIDC_IDENTITY_PROVIDER_CLIENT_SECRET: \"\"\nOIDC_IDENTITY_PROVIDER_GROUPS_CLAIM: \"\"\nOIDC_IDENTITY_PROVIDER_ISSUER_URL: \"\"\nOIDC_IDENTITY_PROVIDER_NAME: \"\"\nOIDC_IDENTITY_PROVIDER_SCOPES: \"\"\nOIDC_IDENTITY_PROVIDER_USERNAME_CLAIM: \"\"\nOS_ARCH: amd64\nOS_NAME: amazon\nOS_VERSION: \"2\"\nSERVICE_CIDR: 100.64.0.0/13\nTKG_HTTP_PROXY_ENABLED: \"false\"\n" diff --git a/tkg/web/server/handlers/export.go b/tkg/web/server/handlers/export.go index a7a4edefb0..ab9d9f418b 100644 --- a/tkg/web/server/handlers/export.go +++ b/tkg/web/server/handlers/export.go @@ -4,6 +4,8 @@ package handlers import ( + "os" + "github.com/go-openapi/runtime/middleware" yaml "gopkg.in/yaml.v3" @@ -61,8 +63,14 @@ func (app *App) ExportAzureConfig(params azure.ExportTKGConfigForAzureParams) mi func (app *App) ExportAWSConfig(params aws.ExportTKGConfigForAWSParams) middleware.Responder { var config *tkgconfigproviders.AWSConfig var configString string + var err error + var encodedCreds string - encodedCreds, err := app.awsClient.EncodeCredentials() + if os.Getenv("CLI_TEST_RUN") == "true" { + encodedCreds = "foobar" + } else { + encodedCreds, err = app.awsClient.EncodeCredentials() + } if err == nil { // create the provider object with the configuration data config, err = tkgconfigproviders.New(app.AppConfig.TKGConfigDir, app.TKGConfigReaderWriter).NewAWSConfig(params.Params, encodedCreds)