From 03394b7526f0dd60588ae54dde602f9a0548cb90 Mon Sep 17 00:00:00 2001 From: Bill Monkman Date: Wed, 3 Jun 2020 11:02:48 -0700 Subject: [PATCH 1/2] Reorganize config code by moving different config types into better-named packages --- cmd/apply.go | 4 +-- cmd/init.go | 6 ++-- internal/api/generate_api.go | 10 +++--- .../{ => globalconfig}/global_config.go | 8 ++--- .../{ => globalconfig}/global_config_test.go | 32 +++++++++---------- internal/config/init_test.go | 32 ------------------- .../{ => moduleconfig}/module_config.go | 2 +- internal/config/{ => projectconfig}/init.go | 8 ++--- internal/config/projectconfig/init_test.go | 32 +++++++++++++++++++ .../project_config.go} | 2 +- .../constants/constants.go | 2 +- internal/context/init.go | 20 ++++++------ internal/generate/generate_infrastructure.go | 8 ++--- internal/generate/generate_modules.go | 8 ++--- internal/module/module.go | 11 ++++--- pkg/credentials/credentials.go | 4 +-- tests/integration/ci/ci_test.go | 6 ++-- 17 files changed, 99 insertions(+), 96 deletions(-) rename internal/config/{ => globalconfig}/global_config.go (93%) rename internal/config/{ => globalconfig}/global_config_test.go (73%) delete mode 100644 internal/config/init_test.go rename internal/config/{ => moduleconfig}/module_config.go (97%) rename internal/config/{ => projectconfig}/init.go (78%) create mode 100644 internal/config/projectconfig/init_test.go rename internal/config/{context_config.go => projectconfig/project_config.go} (97%) rename configs/configs.go => internal/constants/constants.go (92%) diff --git a/cmd/apply.go b/cmd/apply.go index 75670b7bc..5fb71f221 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/commitdev/zero/configs" + "github.com/commitdev/zero/internal/constants" "github.com/commitdev/zero/pkg/util/exit" "github.com/manifoldco/promptui" "github.com/spf13/cobra" @@ -14,7 +14,7 @@ var applyConfigPath string var applyEnvironments []string func init() { - applyCmd.PersistentFlags().StringVarP(&applyConfigPath, "config", "c", configs.ZeroProjectYml, "config path") + applyCmd.PersistentFlags().StringVarP(&applyConfigPath, "config", "c", constants.ZeroProjectYml, "config path") applyCmd.PersistentFlags().StringSliceVarP(&applyEnvironments, "env", "e", []string{}, "environments to set up (staging, production) - specify multiple times for multiple") rootCmd.AddCommand(applyCmd) diff --git a/cmd/init.go b/cmd/init.go index 32952ef40..8054b81ce 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -1,7 +1,7 @@ package cmd import ( - "github.com/commitdev/zero/internal/config" + "github.com/commitdev/zero/internal/config/projectconfig" "github.com/commitdev/zero/internal/context" "github.com/commitdev/zero/pkg/util/exit" "github.com/spf13/cobra" @@ -20,7 +20,7 @@ var initCmd = &cobra.Command{ } projectName := args[0] - projectContext := context.Init(projectName, config.RootDir) - config.Init(config.RootDir, projectName, projectContext) + projectContext := context.Init(projectName, projectconfig.RootDir) + projectconfig.Init(projectconfig.RootDir, projectName, projectContext) }, } diff --git a/internal/api/generate_api.go b/internal/api/generate_api.go index eab2e3df9..475dc738a 100644 --- a/internal/api/generate_api.go +++ b/internal/api/generate_api.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - "github.com/commitdev/zero/internal/config" + "github.com/commitdev/zero/internal/config/projectconfig" "github.com/gorilla/handlers" "github.com/gorilla/mux" ) @@ -15,13 +15,13 @@ func generateProject(w http.ResponseWriter, req *http.Request) { switch req.Method { case "POST": decoder := json.NewDecoder(req.Body) - var projectConfig config.ZeroProjectConfig - err := decoder.Decode(&projectConfig) + var config projectconfig.ZeroProjectConfig + err := decoder.Decode(&config) if err != nil { panic(err) } - log.Println(projectConfig.Name) - // createProject(projectConfig) + log.Println(config.Name) + // createProject(config) w.WriteHeader(http.StatusCreated) w.Write([]byte(`{"message": "Post successful"}`)) diff --git a/internal/config/global_config.go b/internal/config/globalconfig/global_config.go similarity index 93% rename from internal/config/global_config.go rename to internal/config/globalconfig/global_config.go index 4f266380b..5a4ae5e6a 100644 --- a/internal/config/global_config.go +++ b/internal/config/globalconfig/global_config.go @@ -1,4 +1,4 @@ -package config +package globalconfig import ( "bytes" @@ -8,7 +8,7 @@ import ( "os/user" "path" - "github.com/commitdev/zero/configs" + "github.com/commitdev/zero/internal/constants" "github.com/commitdev/zero/pkg/util/exit" yaml "gopkg.in/yaml.v2" ) @@ -69,9 +69,9 @@ func getCredentialsPath() string { exit.Fatal("Failed to get user directory path: %v", err) } - rootDir := path.Join(usr.HomeDir, configs.ZeroHomeDirectory) + rootDir := path.Join(usr.HomeDir, constants.ZeroHomeDirectory) os.MkdirAll(rootDir, os.ModePerm) - filePath := path.Join(rootDir, configs.UserCredentials) + filePath := path.Join(rootDir, constants.UserCredentials) return filePath } diff --git a/internal/config/global_config_test.go b/internal/config/globalconfig/global_config_test.go similarity index 73% rename from internal/config/global_config_test.go rename to internal/config/globalconfig/global_config_test.go index 92921a3ae..0a4737fcd 100644 --- a/internal/config/global_config_test.go +++ b/internal/config/globalconfig/global_config_test.go @@ -1,4 +1,4 @@ -package config_test +package globalconfig_test import ( "fmt" @@ -8,11 +8,11 @@ import ( "path" "testing" - "github.com/commitdev/zero/internal/config" + "github.com/commitdev/zero/internal/config/globalconfig" "github.com/stretchr/testify/assert" ) -const baseTestFixturesDir = "../../tests/test_data/configs/" +const baseTestFixturesDir = "../../../tests/test_data/configs/" var testCredentialFile = func() (func() string, func()) { tmpConfigPath := getTmpConfig() @@ -40,16 +40,16 @@ func copyFile(from string, to string) { } } func TestReadOrCreateUserCredentialsFile(t *testing.T) { - config.GetCredentialsPath = func() string { + globalconfig.GetCredentialsPath = func() string { return path.Join(baseTestFixturesDir, "does-not-exist.yml") } - credPath := config.GetCredentialsPath() + credPath := globalconfig.GetCredentialsPath() defer os.RemoveAll(credPath) _, fileStateErr := os.Stat(credPath) assert.True(t, os.IsNotExist(fileStateErr), "File should not exist") // attempting to read the file should create the file - config.GetUserCredentials("any-project") + globalconfig.GetUserCredentials("any-project") stats, err := os.Stat(credPath) assert.False(t, os.IsNotExist(err), "File should be created") @@ -58,12 +58,12 @@ func TestReadOrCreateUserCredentialsFile(t *testing.T) { func TestGetUserCredentials(t *testing.T) { var teardownFn func() - config.GetCredentialsPath, teardownFn = testCredentialFile() + globalconfig.GetCredentialsPath, teardownFn = testCredentialFile() defer teardownFn() t.Run("Fixture file should have existing project with creds", func(t *testing.T) { projectName := "my-project" - project := config.GetUserCredentials(projectName) + project := globalconfig.GetUserCredentials(projectName) // Reading from fixtures: tests/test_data/configs/credentials.yml assert.Equal(t, "AKIAABCD", project.AWSResourceConfig.AccessKeyId) @@ -74,30 +74,30 @@ func TestGetUserCredentials(t *testing.T) { t.Run("Fixture file should support multiple projects", func(t *testing.T) { projectName := "another-project" - project := config.GetUserCredentials(projectName) + project := globalconfig.GetUserCredentials(projectName) assert.Equal(t, "654", project.GithubResourceConfig.AccessToken) }) } func TestEditUserCredentials(t *testing.T) { var teardownFn func() - config.GetCredentialsPath, teardownFn = testCredentialFile() + globalconfig.GetCredentialsPath, teardownFn = testCredentialFile() defer teardownFn() t.Run("Should create new project if not exist", func(t *testing.T) { projectName := "test-project3" - project := config.GetUserCredentials(projectName) + project := globalconfig.GetUserCredentials(projectName) project.AWSResourceConfig.AccessKeyId = "TEST_KEY_ID_1" - config.Save(project) - newKeyID := config.GetUserCredentials(projectName).AWSResourceConfig.AccessKeyId + globalconfig.Save(project) + newKeyID := globalconfig.GetUserCredentials(projectName).AWSResourceConfig.AccessKeyId assert.Equal(t, "TEST_KEY_ID_1", newKeyID) }) t.Run("Should edit old project if already exist", func(t *testing.T) { projectName := "my-project" - project := config.GetUserCredentials(projectName) + project := globalconfig.GetUserCredentials(projectName) project.AWSResourceConfig.AccessKeyId = "EDITED_ACCESS_KEY_ID" - config.Save(project) - newKeyID := config.GetUserCredentials(projectName).AWSResourceConfig.AccessKeyId + globalconfig.Save(project) + newKeyID := globalconfig.GetUserCredentials(projectName).AWSResourceConfig.AccessKeyId assert.Equal(t, "EDITED_ACCESS_KEY_ID", newKeyID) }) } diff --git a/internal/config/init_test.go b/internal/config/init_test.go deleted file mode 100644 index 216231f8f..000000000 --- a/internal/config/init_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package config_test - -import ( - "os" - "path" - "testing" - - "github.com/commitdev/zero/configs" - "github.com/commitdev/zero/internal/config" -) - -func TestInit(t *testing.T) { - const testDir = "../../test-sandbox" - projectName := "test-project" - - config.SetRootDir(testDir) - defer os.RemoveAll(testDir) - - testDirPath := path.Join(config.RootDir, projectName) - // create sandbox dir - err := os.MkdirAll(testDirPath, os.ModePerm) - if err != nil { - t.Fatal(err) - } - - projectConfig := config.ZeroProjectConfig{} - config.Init(config.RootDir, projectName, &projectConfig) - - if _, err := os.Stat(path.Join(testDirPath, configs.ZeroProjectYml)); err != nil { - t.Fatal(err) - } -} diff --git a/internal/config/module_config.go b/internal/config/moduleconfig/module_config.go similarity index 97% rename from internal/config/module_config.go rename to internal/config/moduleconfig/module_config.go index 1e1c790a0..e472c42b8 100644 --- a/internal/config/module_config.go +++ b/internal/config/moduleconfig/module_config.go @@ -1,4 +1,4 @@ -package config +package moduleconfig import ( "io/ioutil" diff --git a/internal/config/init.go b/internal/config/projectconfig/init.go similarity index 78% rename from internal/config/init.go rename to internal/config/projectconfig/init.go index 1b524b618..bcded1bf7 100644 --- a/internal/config/init.go +++ b/internal/config/projectconfig/init.go @@ -1,11 +1,11 @@ -package config +package projectconfig import ( "fmt" "io/ioutil" "path" - "github.com/commitdev/zero/configs" + "github.com/commitdev/zero/internal/constants" "github.com/commitdev/zero/pkg/util/exit" ) @@ -36,8 +36,8 @@ func Init(dir string, projectName string, projectContext *ZeroProjectConfig) { // TODO: template the zero-project.yml with projectContext content := []byte(fmt.Sprintf(exampleConfig, projectName)) - err := ioutil.WriteFile(path.Join(dir, projectName, configs.ZeroProjectYml), content, 0644) + err := ioutil.WriteFile(path.Join(dir, projectName, constants.ZeroProjectYml), content, 0644) if err != nil { - exit.Fatal(fmt.Sprintf("Failed to create example %s", configs.ZeroProjectYml)) + exit.Fatal(fmt.Sprintf("Failed to create example %s", constants.ZeroProjectYml)) } } diff --git a/internal/config/projectconfig/init_test.go b/internal/config/projectconfig/init_test.go new file mode 100644 index 000000000..a34c8d464 --- /dev/null +++ b/internal/config/projectconfig/init_test.go @@ -0,0 +1,32 @@ +package projectconfig_test + +import ( + "os" + "path" + "testing" + + "github.com/commitdev/zero/internal/config/projectconfig" + "github.com/commitdev/zero/internal/constants" +) + +func TestInit(t *testing.T) { + const testDir = "../../test-sandbox" + projectName := "test-project" + + projectconfig.SetRootDir(testDir) + defer os.RemoveAll(testDir) + + testDirPath := path.Join(projectconfig.RootDir, projectName) + // create sandbox dir + err := os.MkdirAll(testDirPath, os.ModePerm) + if err != nil { + t.Fatal(err) + } + + config := projectconfig.ZeroProjectConfig{} + projectconfig.Init(projectconfig.RootDir, projectName, &config) + + if _, err := os.Stat(path.Join(testDirPath, constants.ZeroProjectYml)); err != nil { + t.Fatal(err) + } +} diff --git a/internal/config/context_config.go b/internal/config/projectconfig/project_config.go similarity index 97% rename from internal/config/context_config.go rename to internal/config/projectconfig/project_config.go index 99e253085..40520c285 100644 --- a/internal/config/context_config.go +++ b/internal/config/projectconfig/project_config.go @@ -1,4 +1,4 @@ -package config +package projectconfig import ( "io/ioutil" diff --git a/configs/configs.go b/internal/constants/constants.go similarity index 92% rename from configs/configs.go rename to internal/constants/constants.go index 6084e1aa6..1f5a00901 100644 --- a/configs/configs.go +++ b/internal/constants/constants.go @@ -1,4 +1,4 @@ -package configs +package constants const ( TemplatesDir = "tmp/templates" diff --git a/internal/context/init.go b/internal/context/init.go index ea961c54a..e212e4f87 100644 --- a/internal/context/init.go +++ b/internal/context/init.go @@ -10,6 +10,8 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sts" "github.com/commitdev/zero/internal/config" + "github.com/commitdev/zero/internal/config/globalconfig" + "github.com/commitdev/zero/internal/config/projectconfig" "github.com/commitdev/zero/internal/module" project "github.com/commitdev/zero/pkg/credentials" "github.com/commitdev/zero/pkg/util/exit" @@ -20,7 +22,7 @@ import ( type Registry map[string][]string // Create cloud provider context -func Init(projectName string, outDir string) *config.ZeroProjectConfig { +func Init(projectName string, outDir string) *projectconfig.ZeroProjectConfig { rootDir := path.Join(outDir, projectName) flog.Infof(":tada: Creating project %s.", projectName) @@ -51,7 +53,7 @@ func Init(projectName string, outDir string) *config.ZeroProjectConfig { return &projectConfig } -func promptAllModules(projectConfig *config.ZeroProjectConfig) { +func promptAllModules(projectConfig *projectconfig.ZeroProjectConfig) { // TODO: do we need to run through the modules and extract first // or we need to run through twice, potentially still need to pre-process for global auths for _, moduleSource := range projectConfig.Modules { @@ -93,7 +95,7 @@ func promptGithubRootOrg() string { func promptGithubPersonalToken(projectName string) string { defaultToken := "" - project := config.GetUserCredentials(projectName) + project := globalconfig.GetUserCredentials(projectName) if project.GithubResourceConfig.AccessToken != "" { defaultToken = project.GithubResourceConfig.AccessToken } @@ -110,7 +112,7 @@ func promptGithubPersonalToken(projectName string) string { // If its different from saved token, update it if project.GithubResourceConfig.AccessToken != result { project.GithubResourceConfig.AccessToken = result - config.Save(project) + globalconfig.Save(project) } return result } @@ -128,7 +130,7 @@ func promptProjectName(projectName string) string { return result } -func chooseCloudProvider(projectConfig *config.ZeroProjectConfig) { +func chooseCloudProvider(projectConfig *projectconfig.ZeroProjectConfig) { // @TODO move options into configs providerPrompt := promptui.Select{ Label: "Select Cloud Provider", @@ -180,7 +182,7 @@ func chooseStack(registry Registry) []string { } -func fillProviderDetails(projectConfig *config.ZeroProjectConfig, s project.Secrets) { +func fillProviderDetails(projectConfig *projectconfig.ZeroProjectConfig, s project.Secrets) { if projectConfig.Infrastructure.AWS != nil { sess, err := session.NewSession(&aws.Config{ Region: aws.String(projectConfig.Infrastructure.AWS.Region), @@ -208,10 +210,10 @@ func fillProviderDetails(projectConfig *config.ZeroProjectConfig, s project.Secr } } -func defaultProjConfig(projectName string) config.ZeroProjectConfig { - return config.ZeroProjectConfig{ +func defaultProjConfig(projectName string) projectconfig.ZeroProjectConfig { + return projectconfig.ZeroProjectConfig{ Name: projectName, - Infrastructure: config.Infrastructure{ + Infrastructure: projectconfig.Infrastructure{ AWS: nil, }, Context: map[string]string{}, diff --git a/internal/generate/generate_infrastructure.go b/internal/generate/generate_infrastructure.go index 1454e59dd..063832445 100644 --- a/internal/generate/generate_infrastructure.go +++ b/internal/generate/generate_infrastructure.go @@ -5,7 +5,7 @@ import ( "os/exec" "path/filepath" - "github.com/commitdev/zero/internal/config" + "github.com/commitdev/zero/internal/config/projectconfig" "github.com/commitdev/zero/internal/util" "github.com/commitdev/zero/pkg/credentials" project "github.com/commitdev/zero/pkg/credentials" @@ -22,7 +22,7 @@ var amiLookup = map[string]string{ } // GetOutputs captures the terraform output for the specific variables -func GetOutputs(cfg *config.ZeroProjectConfig, pathPrefix string, outputs []string) map[string]string { +func GetOutputs(cfg *projectconfig.ZeroProjectConfig, pathPrefix string, outputs []string) map[string]string { outputsMap := make(map[string]string) envars := credentials.MakeAwsEnvars(cfg, project.GetSecrets(util.GetCwd())) pathPrefix = filepath.Join(pathPrefix, "environments/staging") @@ -36,7 +36,7 @@ func GetOutputs(cfg *config.ZeroProjectConfig, pathPrefix string, outputs []stri } // Init sets up anything required by Execute -func Init(cfg *config.ZeroProjectConfig, pathPrefix string) { +func Init(cfg *projectconfig.ZeroProjectConfig, pathPrefix string) { if cfg.Infrastructure.AWS.AccountID != "" { flog.Infof("Preparing aws environment...") @@ -56,7 +56,7 @@ func Init(cfg *config.ZeroProjectConfig, pathPrefix string) { } // Execute terrafrom init & plan. May modify the config passed in -func Execute(cfg *config.ZeroProjectConfig, pathPrefix string) { +func Execute(cfg *projectconfig.ZeroProjectConfig, pathPrefix string) { if cfg.Infrastructure.AWS.AccountID != "" { log.Println("Preparing aws environment...") diff --git a/internal/generate/generate_modules.go b/internal/generate/generate_modules.go index f47808681..0ffaf14d8 100644 --- a/internal/generate/generate_modules.go +++ b/internal/generate/generate_modules.go @@ -10,13 +10,13 @@ import ( "text/template" "github.com/commitdev/zero/internal/config" + "github.com/commitdev/zero/internal/constants" "github.com/commitdev/zero/internal/module" "github.com/commitdev/zero/internal/util" "github.com/commitdev/zero/pkg/util/exit" "github.com/commitdev/zero/pkg/util/flog" "github.com/k0kubun/pp" - "github.com/commitdev/zero/configs" "github.com/commitdev/zero/pkg/util/fs" ) @@ -92,15 +92,15 @@ func NewTemplates(moduleDir string, outputDir string, overwrite bool) []*Templat } for _, path := range paths { - ignoredPaths, _ := regexp.Compile(configs.IgnoredPaths) + ignoredPaths, _ := regexp.Compile(constants.IgnoredPaths) if ignoredPaths.MatchString(path) { continue } _, file := filepath.Split(path) - hasTmpltSuffix := strings.HasSuffix(file, configs.TemplateExtn) + hasTmpltSuffix := strings.HasSuffix(file, constants.TemplateExtn) if hasTmpltSuffix { - file = strings.Replace(file, configs.TemplateExtn, "", -1) + file = strings.Replace(file, constants.TemplateExtn, "", -1) } outputPath := fs.ReplacePath(path, moduleDir, outputDir) diff --git a/internal/module/module.go b/internal/module/module.go index de3db9c9a..d465e913f 100644 --- a/internal/module/module.go +++ b/internal/module/module.go @@ -12,8 +12,9 @@ import ( "regexp" "sync" - "github.com/commitdev/zero/configs" "github.com/commitdev/zero/internal/config" + "github.com/commitdev/zero/internal/config/moduleconfig" + "github.com/commitdev/zero/internal/constants" "github.com/commitdev/zero/internal/util" "github.com/hashicorp/go-getter" "github.com/manifoldco/promptui" @@ -21,8 +22,8 @@ import ( // TemplateModule merges a module instance params with the static configs type TemplateModule struct { - config.ModuleInstance - Config config.ModuleConfig + config.ModuleInstance // @TODO Move this + Config moduleconfig.ModuleConfig } type ProgressTracking struct { @@ -49,7 +50,7 @@ func NewTemplateModule(moduleCfg config.ModuleInstance) (*TemplateModule, error) } configPath := path.Join(sourcePath, "zero-module.yml") - moduleConfig := config.LoadModuleConfig(configPath) + moduleConfig := moduleconfig.LoadModuleConfig(configPath) templateModule.Config = *moduleConfig return &templateModule, nil @@ -131,7 +132,7 @@ func GetSourceDir(source string) string { h := md5.New() io.WriteString(h, source) source = base64.StdEncoding.EncodeToString(h.Sum(nil)) - return path.Join(configs.TemplatesDir, source) + return path.Join(constants.TemplatesDir, source) } else { return source } diff --git a/pkg/credentials/credentials.go b/pkg/credentials/credentials.go index a55a4c2f4..060b4b44a 100644 --- a/pkg/credentials/credentials.go +++ b/pkg/credentials/credentials.go @@ -11,7 +11,7 @@ import ( "regexp" "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/commitdev/zero/internal/config" + "github.com/commitdev/zero/internal/config/projectconfig" "github.com/manifoldco/promptui" "gopkg.in/yaml.v2" ) @@ -28,7 +28,7 @@ type AWS struct { SecretAccessKey string } -func MakeAwsEnvars(cfg *config.ZeroProjectConfig, awsSecrets Secrets) []string { +func MakeAwsEnvars(cfg *projectconfig.ZeroProjectConfig, awsSecrets Secrets) []string { env := os.Environ() env = append(env, fmt.Sprintf("AWS_ACCESS_KEY_ID=%s", awsSecrets.AWS.AccessKeyID)) env = append(env, fmt.Sprintf("AWS_SECRET_ACCESS_KEY=%s", awsSecrets.AWS.SecretAccessKey)) diff --git a/tests/integration/ci/ci_test.go b/tests/integration/ci/ci_test.go index eb6d9fce8..bfdb35055 100644 --- a/tests/integration/ci/ci_test.go +++ b/tests/integration/ci/ci_test.go @@ -34,7 +34,7 @@ package ci_test // var waitgroup sync.WaitGroup -// testConf := &config.ZeroProjectConfig{} +// testConf := &projectconfig.ZeroProjectConfig{} // testCI := config.CI{ // System: "jenkins", // BuildImage: "golang/golang", @@ -72,7 +72,7 @@ package ci_test // var waitgroup sync.WaitGroup -// testConf := &config.ZeroProjectConfig{} +// testConf := &projectconfig.ZeroProjectConfig{} // testCI := config.CI{ // System: "circleci", // BuildImage: "golang/golang", @@ -110,7 +110,7 @@ package ci_test // var waitgroup sync.WaitGroup -// testConf := &config.ZeroProjectConfig{} +// testConf := &projectconfig.ZeroProjectConfig{} // testCI := config.CI{ // System: "travisci", // Language: "go", From 71695cd4150e5d9c6f6f50cd788f643c107ce42b Mon Sep 17 00:00:00 2001 From: Bill Monkman Date: Wed, 3 Jun 2020 11:28:20 -0700 Subject: [PATCH 2/2] Moved zero module yaml file name to constant --- internal/config/globalconfig/global_config.go | 2 +- internal/constants/constants.go | 13 +++++++------ internal/module/module.go | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/config/globalconfig/global_config.go b/internal/config/globalconfig/global_config.go index 5a4ae5e6a..7371d81af 100644 --- a/internal/config/globalconfig/global_config.go +++ b/internal/config/globalconfig/global_config.go @@ -71,7 +71,7 @@ func getCredentialsPath() string { rootDir := path.Join(usr.HomeDir, constants.ZeroHomeDirectory) os.MkdirAll(rootDir, os.ModePerm) - filePath := path.Join(rootDir, constants.UserCredentials) + filePath := path.Join(rootDir, constants.UserCredentialsYml) return filePath } diff --git a/internal/constants/constants.go b/internal/constants/constants.go index 1f5a00901..907ad9f60 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -1,10 +1,11 @@ package constants const ( - TemplatesDir = "tmp/templates" - ZeroProjectYml = "zero-project.yml" - ZeroHomeDirectory = ".zero" - UserCredentials = "credentials.yml" - IgnoredPaths = "(?i)zero.module.yml|.git/" - TemplateExtn = ".tmpl" + TemplatesDir = "tmp/templates" + ZeroProjectYml = "zero-project.yml" + ZeroModuleYml = "zero-module.yml" + UserCredentialsYml = "credentials.yml" + ZeroHomeDirectory = ".zero" + IgnoredPaths = "(?i)zero.module.yml|.git/" + TemplateExtn = ".tmpl" ) diff --git a/internal/module/module.go b/internal/module/module.go index d465e913f..4babb1810 100644 --- a/internal/module/module.go +++ b/internal/module/module.go @@ -49,7 +49,7 @@ func NewTemplateModule(moduleCfg config.ModuleInstance) (*TemplateModule, error) } } - configPath := path.Join(sourcePath, "zero-module.yml") + configPath := path.Join(sourcePath, constants.ZeroModuleYml) moduleConfig := moduleconfig.LoadModuleConfig(configPath) templateModule.Config = *moduleConfig