diff --git a/configs/config.go b/configs/config.go index 6f3182910..8d0f2e993 100644 --- a/configs/config.go +++ b/configs/config.go @@ -58,6 +58,23 @@ type Config struct { MetaphorTemplateURL string GitopsTemplateURL string + LocalArgoWorkflowsURL string + LocalVaultURL string + LocalArgoURL string + LocalAtlantisURL string + + LocalMetaphorDev string + LocalMetaphorGoDev string + LocalMetaphorFrontDev string + + LocalMetaphorStaging string + LocalMetaphorGoStaging string + LocalMetaphorFrontStaging string + + LocalMetaphorProd string + LocalMetaphorGoProd string + LocalMetaphorFrontProd string + GitHubPersonalAccessToken string `env:"GITHUB_AUTH_TOKEN"` } @@ -109,6 +126,24 @@ func ReadConfig() *Config { config.MetaphorTemplateURL = "https://github.com/kubefirst/metaphor-template.git" config.GitopsTemplateURL = "https://github.com/kubefirst/gitops-template-gh.git" + // Local Configs URL + config.LocalArgoWorkflowsURL = "http://localhost:2746" + config.LocalVaultURL = "http://localhost:8200" + config.LocalArgoURL = "http://localhost:8080" + config.LocalAtlantisURL = "http://localhost:4141" + + config.LocalMetaphorDev = "http://localhost:3000" + config.LocalMetaphorGoDev = "http://localhost:5000" + config.LocalMetaphorFrontDev = "http://localhost:4000" + + config.LocalMetaphorStaging = "http://localhost:3001" + config.LocalMetaphorGoStaging = "http://localhost:5001" + config.LocalMetaphorFrontStaging = "http://localhost:4001" + + config.LocalMetaphorProd = "http://localhost:3002" + config.LocalMetaphorGoProd = "http://localhost:5002" + config.LocalMetaphorFrontProd = "http://localhost:4002" + // If the AWS_SDK_LOAD_CONFIG environment variable is set to a truthy value the shared config file (~/.aws/config) // will also be loaded in addition to the shared credentials file (~/.aws/credentials). // AWS SDK client will take it in advance diff --git a/internal/api/api_default.go b/internal/api/api_default.go index dc29d204c..e69ba4f4e 100644 --- a/internal/api/api_default.go +++ b/internal/api/api_default.go @@ -11,6 +11,7 @@ package swagger import ( "encoding/json" + "fmt" "log" "net/http" @@ -44,6 +45,58 @@ func ConfigsGet(w http.ResponseWriter, r *http.Request) { Key: "HOSTED_ZONE_NAME", Value: viper.GetString("aws.hostedzonename"), }, + { + Key: "VAULT_URL", + Value: fmt.Sprintf("https://vault.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "ATLANTIS_URL", + Value: fmt.Sprintf("https://atlantis.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "ARGO_WORKFLOWS_URL", + Value: fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "ARGO_CD_URL", + Value: fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "METAPHOR_DEV", + Value: fmt.Sprintf("https://metaphor-development.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "METAPHOR_GO_DEV", + Value: fmt.Sprintf("https://metaphor-go-development.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "METAPHOR_FRONT_DEV", + Value: fmt.Sprintf("https://metaphor-frontend-development.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "METAPHOR_STAGING", + Value: fmt.Sprintf("https://metaphor-staging.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "METAPHOR_GO_STAGING", + Value: fmt.Sprintf("https://metaphor-go-staging.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "METAPHOR_FRONT_STAGING", + Value: fmt.Sprintf("https://metaphor-frontend-staging.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "METAPHOR_PROD", + Value: fmt.Sprintf("https://metaphor-production.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "METAPHOR_GO_PROD", + Value: fmt.Sprintf("https://metaphor-go-production.%s", viper.GetString("aws.hostedzonename")), + }, + { + Key: "METAPHOR_FRONT_PROD", + Value: fmt.Sprintf("https://metaphor-frontend-production.%s", viper.GetString("aws.hostedzonename")), + }, } jsonData, err := json.Marshal(configValues) diff --git a/pkg/helpers.go b/pkg/helpers.go index b4b4f839e..a05989210 100644 --- a/pkg/helpers.go +++ b/pkg/helpers.go @@ -115,7 +115,10 @@ func DetokenizeDirectory(path string, fi os.FileInfo, err error) error { gitlabConfigured := viper.GetBool("gitlab.keyuploaded") newContents := string(read) + config := configs.ReadConfig() + cloudK3d := "k3d" + cloud := viper.GetString("cloud") botPublicKey := viper.GetString("botpublickey") hostedZoneId := viper.GetString("aws.hostedzoneid") hostedZoneName := viper.GetString("aws.hostedzonename") @@ -228,6 +231,44 @@ func DetokenizeDirectory(path string, fi os.FileInfo, err error) error { newContents = strings.Replace(newContents, "", region, -1) newContents = strings.Replace(newContents, "", awsAccountId, -1) } + + if cloud == cloudK3d { + newContents = strings.Replace(newContents, "", cloud, -1) + newContents = strings.Replace(newContents, "", config.LocalArgoWorkflowsURL, -1) + newContents = strings.Replace(newContents, "", config.LocalVaultURL, -1) + newContents = strings.Replace(newContents, "", config.LocalArgoURL, -1) + newContents = strings.Replace(newContents, "", config.LocalAtlantisURL, -1) + + newContents = strings.Replace(newContents, "", config.LocalMetaphorDev, -1) + newContents = strings.Replace(newContents, "", config.LocalMetaphorGoDev, -1) + newContents = strings.Replace(newContents, "", config.LocalMetaphorFrontDev, -1) + + newContents = strings.Replace(newContents, "", config.LocalMetaphorStaging, -1) + newContents = strings.Replace(newContents, "", config.LocalMetaphorGoStaging, -1) + newContents = strings.Replace(newContents, "", config.LocalMetaphorFrontStaging, -1) + + newContents = strings.Replace(newContents, "", config.LocalMetaphorProd, -1) + newContents = strings.Replace(newContents, "", config.LocalMetaphorGoProd, -1) + newContents = strings.Replace(newContents, "", config.LocalMetaphorFrontProd, -1) + } else { + newContents = strings.Replace(newContents, "", cloud, -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://argo.%s", hostedZoneName), -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://vault.%s", hostedZoneName), -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://argocd.%s", hostedZoneName), -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://atlantis.%s", hostedZoneName), -1) + + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://metaphor-development.%s", hostedZoneName), -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://metaphor-go-development.%s", hostedZoneName), -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://metaphor-frontend-development.%s", hostedZoneName), -1) + + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://metaphor-staging.%s", hostedZoneName), -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://metaphor-go-staging.%s", hostedZoneName), -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://metaphor-frontend-staging.%s", hostedZoneName), -1) + + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://metaphor-production.%s", hostedZoneName), -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://metaphor-go-production.%s", hostedZoneName), -1) + newContents = strings.Replace(newContents, "", fmt.Sprintf("https://metaphor-frontend-production.%s", hostedZoneName), -1) + } if removeFile { err = os.Remove(path)