-
Notifications
You must be signed in to change notification settings - Fork 12
/
config.go
112 lines (98 loc) · 3.88 KB
/
config.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 providerConfigs
import (
"fmt"
"os"
"github.com/rs/zerolog/log"
)
type ProviderConfig struct {
CivoToken string
DigitaloceanToken string
GCPAuth string
GCPProject string
VultrToken string
CloudflareApiToken string
GithubToken string
GitlabToken string
ArgoWorkflowsDir string
DestinationGitopsRepoHttpsURL string
DestinationGitopsRepoGitURL string
DestinationGitopsRepoURL string
DestinationMetaphorRepoHttpsURL string
DestinationMetaphorRepoGitURL string
DestinationMetaphorRepoURL string
GitopsDir string
GitProvider string
GitProtocol string
K1Dir string
Kubeconfig string
KubectlClient string
KubefirstBotSSHPrivateKey string
KubefirstConfig string
LogsDir string
MetaphorDir string
RegistryAppName string
RegistryYaml string
SSLBackupDir string
TerraformClient string
ToolsDir string
GitopsDirectoryValues *GitopsDirectoryValues
MetaphorDirectoryValues *MetaphorTokenValues
}
// GetConfig - load default values from kubefirst installer
func GetConfig(
clusterName string,
domainName string,
gitProvider string,
gitOwner string,
gitProtocol string,
cloudflareAPIToken string,
) *ProviderConfig {
config := ProviderConfig{}
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal().Msgf("something went wrong getting home path: %s", err)
}
// cGitHost describes which git host to use depending on gitProvider
var cGitHost string
switch gitProvider {
case "github":
cGitHost = GithubHost
case "gitlab":
cGitHost = GitlabHost
}
config.DestinationGitopsRepoHttpsURL = fmt.Sprintf("https://%s/%s/gitops.git", cGitHost, gitOwner)
config.DestinationGitopsRepoGitURL = fmt.Sprintf("git@%s:%s/gitops.git", cGitHost, gitOwner)
config.DestinationMetaphorRepoHttpsURL = fmt.Sprintf("https://%s/%s/metaphor.git", cGitHost, gitOwner)
config.DestinationMetaphorRepoGitURL = fmt.Sprintf("git@%s:%s/metaphor.git", cGitHost, gitOwner)
// Define constant url based on flag input, only expecting 2 protocols
switch gitProtocol {
case "https":
config.DestinationGitopsRepoURL = config.DestinationGitopsRepoHttpsURL
config.DestinationMetaphorRepoURL = config.DestinationMetaphorRepoHttpsURL
default: //"ssh"
config.DestinationGitopsRepoURL = config.DestinationGitopsRepoGitURL
config.DestinationMetaphorRepoURL = config.DestinationMetaphorRepoGitURL
}
config.ArgoWorkflowsDir = fmt.Sprintf("%s/.k1/%s/argo-workflows", homeDir, clusterName)
config.GitopsDir = fmt.Sprintf("%s/.k1/%s/gitops", homeDir, clusterName)
config.GitProvider = gitProvider
config.GitProtocol = gitProtocol
config.CloudflareApiToken = cloudflareAPIToken
config.Kubeconfig = fmt.Sprintf("%s/.k1/%s/kubeconfig", homeDir, clusterName)
config.K1Dir = fmt.Sprintf("%s/.k1/%s", homeDir, clusterName)
config.KubectlClient = fmt.Sprintf("%s/.k1/%s/tools/kubectl", homeDir, clusterName)
config.KubefirstConfig = fmt.Sprintf("%s/.k1/%s/%s", homeDir, clusterName, ".kubefirst")
config.LogsDir = fmt.Sprintf("%s/.k1/%s/logs", homeDir, clusterName)
config.MetaphorDir = fmt.Sprintf("%s/.k1/%s/metaphor", homeDir, clusterName)
config.RegistryAppName = "registry"
config.RegistryYaml = fmt.Sprintf("%s/.k1/%s/gitops/registry/%s/registry.yaml", homeDir, clusterName, clusterName)
config.SSLBackupDir = fmt.Sprintf("%s/.k1/%s/ssl/%s", homeDir, clusterName, domainName)
config.TerraformClient = fmt.Sprintf("%s/.k1/%s/tools/terraform", homeDir, clusterName)
config.ToolsDir = fmt.Sprintf("%s/.k1/%s/tools", homeDir, clusterName)
return &config
}