-
Notifications
You must be signed in to change notification settings - Fork 14
/
env.go
112 lines (96 loc) · 4.71 KB
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
Copyright (C) 2021-2023, Kubefirst
This program is licensed under MIT.
See the LICENSE file for more details.
*/
package aws
import (
"fmt"
"strconv"
"strings"
"github.com/kubefirst/kubefirst-api/internal/k8s"
"github.com/kubefirst/kubefirst-api/internal/vault"
"github.com/kubefirst/kubefirst-api/pkg/providerConfigs"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
log "github.com/rs/zerolog/log"
"k8s.io/client-go/kubernetes"
)
func readVaultTokenFromSecret(clientset *kubernetes.Clientset) string {
existingKubernetesSecret, err := k8s.ReadSecretV2(clientset, vault.VaultNamespace, vault.VaultSecretName)
if err != nil || existingKubernetesSecret == nil {
log.Printf("Error reading existing Secret data: %s", err)
return ""
}
return existingKubernetesSecret["root-token"]
}
func GetAwsTerraformEnvs(envs map[string]string, cl *pkgtypes.Cluster) map[string]string {
// needed for s3 api connectivity to object storage
envs["AWS_ACCESS_KEY_ID"] = cl.StateStoreCredentials.AccessKeyID
envs["AWS_SECRET_ACCESS_KEY"] = cl.StateStoreCredentials.SecretAccessKey
envs["AWS_SESSION_TOKEN"] = cl.AWSAuth.SessionToken
envs["TF_VAR_aws_access_key_id"] = cl.StateStoreCredentials.AccessKeyID
envs["TF_VAR_aws_secret_access_key"] = cl.StateStoreCredentials.SecretAccessKey
envs["TF_VAR_aws_session_token"] = cl.AWSAuth.SessionToken
envs["TF_VAR_aws_region"] = cl.CloudRegion
envs["TF_VAR_hosted_zone_name"] = cl.DomainName
//envs["TF_LOG"] = "debug"
return envs
}
func GetGithubTerraformEnvs(envs map[string]string, cl *pkgtypes.Cluster) map[string]string {
envs["GITHUB_TOKEN"] = cl.GitAuth.Token
envs["GITHUB_OWNER"] = cl.GitAuth.Owner
envs["TF_VAR_atlantis_repo_webhook_secret"] = cl.AtlantisWebhookSecret
envs["TF_VAR_atlantis_repo_webhook_url"] = cl.AtlantisWebhookURL
envs["TF_VAR_kbot_ssh_public_key"] = cl.GitAuth.PublicKey
envs["AWS_ACCESS_KEY_ID"] = cl.StateStoreCredentials.AccessKeyID
envs["AWS_SECRET_ACCESS_KEY"] = cl.StateStoreCredentials.SecretAccessKey
envs["AWS_SESSION_TOKEN"] = cl.AWSAuth.SessionToken
envs["TF_VAR_aws_access_key_id"] = cl.StateStoreCredentials.AccessKeyID
envs["TF_VAR_aws_secret_access_key"] = cl.StateStoreCredentials.SecretAccessKey
envs["TF_VAR_aws_session_token"] = cl.AWSAuth.SessionToken
return envs
}
func GetGitlabTerraformEnvs(envs map[string]string, gid int, cl *pkgtypes.Cluster) map[string]string {
envs["GITLAB_TOKEN"] = cl.GitAuth.Token
envs["GITLAB_OWNER"] = cl.GitAuth.Owner
envs["TF_VAR_atlantis_repo_webhook_secret"] = cl.AtlantisWebhookSecret
envs["TF_VAR_atlantis_repo_webhook_url"] = cl.AtlantisWebhookURL
envs["TF_VAR_kbot_ssh_public_key"] = cl.GitAuth.PublicKey
envs["AWS_ACCESS_KEY_ID"] = cl.StateStoreCredentials.AccessKeyID
envs["AWS_SECRET_ACCESS_KEY"] = cl.StateStoreCredentials.SecretAccessKey
envs["AWS_SESSION_TOKEN"] = cl.AWSAuth.SessionToken
envs["TF_VAR_aws_access_key_id"] = cl.StateStoreCredentials.AccessKeyID
envs["TF_VAR_aws_secret_access_key"] = cl.StateStoreCredentials.SecretAccessKey
envs["TF_VAR_aws_session_token"] = cl.AWSAuth.SessionToken
envs["TF_VAR_owner_group_id"] = strconv.Itoa(gid)
envs["TF_VAR_gitlab_owner"] = cl.GitAuth.Owner
return envs
}
func GetUsersTerraformEnvs(clientset *kubernetes.Clientset, cl *pkgtypes.Cluster, envs map[string]string) map[string]string {
envs["VAULT_TOKEN"] = readVaultTokenFromSecret(clientset)
envs["VAULT_ADDR"] = providerConfigs.VaultPortForwardURL
envs[fmt.Sprintf("%s_TOKEN", strings.ToUpper(cl.GitProvider))] = cl.GitAuth.Token
envs[fmt.Sprintf("%s_OWNER", strings.ToUpper(cl.GitProvider))] = cl.GitAuth.Owner
return envs
}
func GetVaultTerraformEnvs(clientset *kubernetes.Clientset, cl *pkgtypes.Cluster, envs map[string]string) map[string]string {
envs[fmt.Sprintf("%s_TOKEN", strings.ToUpper(cl.GitProvider))] = cl.GitAuth.Token
envs[fmt.Sprintf("%s_OWNER", strings.ToUpper(cl.GitProvider))] = cl.GitAuth.Owner
envs["TF_VAR_email_address"] = cl.AlertsEmail
envs["TF_VAR_vault_addr"] = providerConfigs.VaultPortForwardURL
envs["TF_VAR_vault_token"] = readVaultTokenFromSecret(clientset)
envs[fmt.Sprintf("TF_VAR_%s_token", cl.GitProvider)] = cl.GitAuth.Token
envs["VAULT_ADDR"] = providerConfigs.VaultPortForwardURL
envs["VAULT_TOKEN"] = readVaultTokenFromSecret(clientset)
envs["TF_VAR_atlantis_repo_webhook_secret"] = cl.AtlantisWebhookSecret
envs["TF_VAR_atlantis_repo_webhook_url"] = cl.AtlantisWebhookURL
envs["TF_VAR_cloudflare_origin_ca_api_key"] = cl.CloudflareAuth.OriginCaIssuerKey
envs["TF_VAR_cloudflare_api_key"] = cl.CloudflareAuth.APIToken
envs["TF_VAR_kbot_ssh_private_key"] = cl.GitAuth.PrivateKey
envs["TF_VAR_kbot_ssh_public_key"] = cl.GitAuth.PublicKey
switch cl.GitProvider {
case "gitlab":
envs["TF_VAR_owner_group_id"] = fmt.Sprint(cl.GitlabOwnerGroupID)
}
return envs
}