Skip to content

Commit

Permalink
Move packages from internal to pkg folder (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
aknysh authored Nov 2, 2021
1 parent d8f4fcf commit 302aa83
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 97 deletions.
26 changes: 1 addition & 25 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cloudposse/atmos

go 1.17
go 1.16

require (
github.com/bmatcuk/doublestar v1.3.4
Expand All @@ -14,27 +14,3 @@ require (
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/text v0.3.6 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
26 changes: 13 additions & 13 deletions internal/exec/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package exec

import (
"fmt"
c "github.com/cloudposse/atmos/internal/config"
g "github.com/cloudposse/atmos/internal/globals"
"github.com/cloudposse/atmos/pkg/config"
g "github.com/cloudposse/atmos/pkg/globals"
s "github.com/cloudposse/atmos/pkg/stack"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/fatih/color"
Expand All @@ -24,15 +24,15 @@ func ExecuteDescribeComponent(cmd *cobra.Command, args []string) error {
return err
}

var configAndStacksInfo c.ConfigAndStacksInfo
var configAndStacksInfo config.ConfigAndStacksInfo
configAndStacksInfo.Stack = stack

err = c.InitConfig()
err = config.InitConfig()
if err != nil {
return err
}

err = c.ProcessConfig(configAndStacksInfo)
err = config.ProcessConfig(configAndStacksInfo)
if err != nil {
return err
}
Expand All @@ -43,22 +43,22 @@ func ExecuteDescribeComponent(cmd *cobra.Command, args []string) error {
if g.LogVerbose {
fmt.Println()
var msg string
if c.ProcessedConfig.StackType == "Directory" {
if config.ProcessedConfig.StackType == "Directory" {
msg = "Found the config file for the provided stack:"
} else {
msg = "Found config files:"
}
color.Cyan(msg)

err = u.PrintAsYAML(c.ProcessedConfig.StackConfigFilesRelativePaths)
err = u.PrintAsYAML(config.ProcessedConfig.StackConfigFilesRelativePaths)
if err != nil {
return err
}
}

_, stacksMap, err := s.ProcessYAMLConfigFiles(
c.ProcessedConfig.StacksBaseAbsolutePath,
c.ProcessedConfig.StackConfigFilesAbsolutePaths,
config.ProcessedConfig.StacksBaseAbsolutePath,
config.ProcessedConfig.StackConfigFilesAbsolutePaths,
true,
true)

Expand All @@ -70,7 +70,7 @@ func ExecuteDescribeComponent(cmd *cobra.Command, args []string) error {
var componentVarsSection map[interface{}]interface{}

// Check and process stacks
if c.ProcessedConfig.StackType == "Directory" {
if config.ProcessedConfig.StackType == "Directory" {
componentSection,
componentVarsSection,
_, _, _, _,
Expand All @@ -89,12 +89,12 @@ func ExecuteDescribeComponent(cmd *cobra.Command, args []string) error {
color.Cyan("Searching for stack config where the component '%s' is defined\n", component)
}

if len(c.Config.Stacks.NamePattern) < 1 {
if len(config.Config.Stacks.NamePattern) < 1 {
return errors.New("stack name pattern must be provided in 'stacks.name_pattern' config or 'ATMOS_STACKS_NAME_PATTERN' ENV variable")
}

stackParts := strings.Split(stack, "-")
stackNamePatternParts := strings.Split(c.Config.Stacks.NamePattern, "-")
stackNamePatternParts := strings.Split(config.Config.Stacks.NamePattern, "-")

var tenant string
var environment string
Expand Down Expand Up @@ -168,7 +168,7 @@ func ExecuteDescribeComponent(cmd *cobra.Command, args []string) error {
"Are the component and stack names correct? Did you forget an import?",
component,
stack,
c.Config.Stacks.NamePattern,
config.Config.Stacks.NamePattern,
))
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/helmfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package exec

import (
"fmt"
c "github.com/cloudposse/atmos/internal/config"
c "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/utils"
"github.com/fatih/color"
"github.com/pkg/errors"
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exec

import (
"fmt"
c "github.com/cloudposse/atmos/internal/config"
c "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/utils"
"github.com/fatih/color"
"github.com/pkg/errors"
Expand Down
28 changes: 14 additions & 14 deletions internal/exec/terraform_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package exec

import (
"fmt"
c "github.com/cloudposse/atmos/internal/config"
g "github.com/cloudposse/atmos/internal/globals"
"github.com/cloudposse/atmos/pkg/config"
g "github.com/cloudposse/atmos/pkg/globals"
s "github.com/cloudposse/atmos/pkg/stack"
"github.com/cloudposse/atmos/pkg/utils"
"github.com/fatih/color"
Expand All @@ -24,15 +24,15 @@ func ExecuteTerraformGenerateBackend(cmd *cobra.Command, args []string) error {
return err
}

var configAndStacksInfo c.ConfigAndStacksInfo
var configAndStacksInfo config.ConfigAndStacksInfo
configAndStacksInfo.Stack = stack

err = c.InitConfig()
err = config.InitConfig()
if err != nil {
return err
}

err = c.ProcessConfig(configAndStacksInfo)
err = config.ProcessConfig(configAndStacksInfo)
if err != nil {
return err
}
Expand All @@ -43,22 +43,22 @@ func ExecuteTerraformGenerateBackend(cmd *cobra.Command, args []string) error {
if g.LogVerbose {
fmt.Println()
var msg string
if c.ProcessedConfig.StackType == "Directory" {
if config.ProcessedConfig.StackType == "Directory" {
msg = "Found the config file for the provided stack:"
} else {
msg = "Found config files:"
}
color.Cyan(msg)

err = utils.PrintAsYAML(c.ProcessedConfig.StackConfigFilesRelativePaths)
err = utils.PrintAsYAML(config.ProcessedConfig.StackConfigFilesRelativePaths)
if err != nil {
return err
}
}

_, stacksMap, err := s.ProcessYAMLConfigFiles(
c.ProcessedConfig.StacksBaseAbsolutePath,
c.ProcessedConfig.StackConfigFilesAbsolutePaths,
config.ProcessedConfig.StacksBaseAbsolutePath,
config.ProcessedConfig.StackConfigFilesAbsolutePaths,
false,
false)

Expand All @@ -72,7 +72,7 @@ func ExecuteTerraformGenerateBackend(cmd *cobra.Command, args []string) error {
var componentBackendType string

// Check and process stacks
if c.ProcessedConfig.StackType == "Directory" {
if config.ProcessedConfig.StackType == "Directory" {
componentSection,
componentVarsSection,
componentBackendSection,
Expand All @@ -85,12 +85,12 @@ func ExecuteTerraformGenerateBackend(cmd *cobra.Command, args []string) error {
} else {
color.Cyan("Searching for stack config where the component '%s' is defined\n", component)

if len(c.Config.Stacks.NamePattern) < 1 {
if len(config.Config.Stacks.NamePattern) < 1 {
return errors.New("stack name pattern must be provided in 'stacks.name_pattern' config or 'ATMOS_STACKS_NAME_PATTERN' ENV variable")
}

stackParts := strings.Split(stack, "-")
stackNamePatternParts := strings.Split(c.Config.Stacks.NamePattern, "-")
stackNamePatternParts := strings.Split(config.Config.Stacks.NamePattern, "-")

var tenant string
var environment string
Expand Down Expand Up @@ -158,7 +158,7 @@ func ExecuteTerraformGenerateBackend(cmd *cobra.Command, args []string) error {
"Are the component and stack names correct? Did you forget an import?",
component,
stack,
c.Config.Stacks.NamePattern,
config.Config.Stacks.NamePattern,
))
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func ExecuteTerraformGenerateBackend(cmd *cobra.Command, args []string) error {
}

// Write backend to file
var varFileName = fmt.Sprintf("%s/%s/backend.tf.json", c.Config.Components.Terraform.BasePath, finalComponent)
var varFileName = fmt.Sprintf("%s/%s/backend.tf.json", config.Config.Components.Terraform.BasePath, finalComponent)

color.Cyan("\nWriting backend config to file:")
fmt.Println(varFileName)
Expand Down
46 changes: 23 additions & 23 deletions internal/exec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package exec
import (
"errors"
"fmt"
c "github.com/cloudposse/atmos/internal/config"
g "github.com/cloudposse/atmos/internal/globals"
"github.com/cloudposse/atmos/pkg/config"
g "github.com/cloudposse/atmos/pkg/globals"
s "github.com/cloudposse/atmos/pkg/stack"
"github.com/cloudposse/atmos/pkg/utils"
"github.com/fatih/color"
Expand Down Expand Up @@ -90,8 +90,8 @@ func findComponentConfig(
}

// processConfigAndStacks processes CLI config and stacks
func processConfigAndStacks(componentType string, cmd *cobra.Command, args []string) (c.ConfigAndStacksInfo, error) {
var configAndStacksInfo c.ConfigAndStacksInfo
func processConfigAndStacks(componentType string, cmd *cobra.Command, args []string) (config.ConfigAndStacksInfo, error) {
var configAndStacksInfo config.ConfigAndStacksInfo

if len(args) < 1 {
return configAndStacksInfo, errors.New("invalid number of arguments")
Expand Down Expand Up @@ -132,20 +132,20 @@ func processConfigAndStacks(componentType string, cmd *cobra.Command, args []str
}

// Process and merge CLI configurations
err = c.InitConfig()
err = config.InitConfig()
if err != nil {
return configAndStacksInfo, err
}

err = c.ProcessConfig(configAndStacksInfo)
err = config.ProcessConfig(configAndStacksInfo)
if err != nil {
return configAndStacksInfo, err
}

// Process stack config file(s)
_, stacksMap, err := s.ProcessYAMLConfigFiles(
c.ProcessedConfig.StacksBaseAbsolutePath,
c.ProcessedConfig.StackConfigFilesAbsolutePaths,
config.ProcessedConfig.StacksBaseAbsolutePath,
config.ProcessedConfig.StackConfigFilesAbsolutePaths,
false,
true)

Expand All @@ -157,27 +157,27 @@ func processConfigAndStacks(componentType string, cmd *cobra.Command, args []str
if g.LogVerbose {
fmt.Println()
var msg string
if c.ProcessedConfig.StackType == "Directory" {
if config.ProcessedConfig.StackType == "Directory" {
msg = "Found the config file for the provided stack:"
} else {
msg = "Found config files:"
}
color.Cyan(msg)
err = utils.PrintAsYAML(c.ProcessedConfig.StackConfigFilesRelativePaths)
err = utils.PrintAsYAML(config.ProcessedConfig.StackConfigFilesRelativePaths)
if err != nil {
return configAndStacksInfo, err
}
}

if len(c.Config.Stacks.NamePattern) < 1 {
if len(config.Config.Stacks.NamePattern) < 1 {
return configAndStacksInfo,
errors.New("stack name pattern must be provided in 'stacks.name_pattern' config or 'ATMOS_STACKS_NAME_PATTERN' ENV variable")
}

stackNamePatternParts := strings.Split(c.Config.Stacks.NamePattern, "-")
stackNamePatternParts := strings.Split(config.Config.Stacks.NamePattern, "-")

// Check and process stacks
if c.ProcessedConfig.StackType == "Directory" {
if config.ProcessedConfig.StackType == "Directory" {
_, configAndStacksInfo.ComponentVarsSection,
configAndStacksInfo.ComponentBackendSection,
configAndStacksInfo.ComponentBackendType,
Expand All @@ -196,7 +196,7 @@ func processConfigAndStacks(componentType string, cmd *cobra.Command, args []str
return configAndStacksInfo,
errors.New(fmt.Sprintf("Stack '%s' does not match the stack name pattern '%s'",
configAndStacksInfo.Stack,
c.Config.Stacks.NamePattern))
config.Config.Stacks.NamePattern))
}

var tenant string
Expand Down Expand Up @@ -267,7 +267,7 @@ func processConfigAndStacks(componentType string, cmd *cobra.Command, args []str
"Are the component and stack names correct? Did you forget an import?",
configAndStacksInfo.ComponentFromArg,
configAndStacksInfo.Stack,
c.Config.Stacks.NamePattern,
config.Config.Stacks.NamePattern,
))
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func processConfigAndStacks(componentType string, cmd *cobra.Command, args []str
if len(configAndStacksInfo.Context.Tenant) == 0 {
return configAndStacksInfo,
errors.New(fmt.Sprintf("The stack name pattern '%s' specifies 'tenant`, but the stack %s does not have a tenant defined",
c.Config.Stacks.NamePattern,
config.Config.Stacks.NamePattern,
configAndStacksInfo.Stack,
))
}
Expand All @@ -329,7 +329,7 @@ func processConfigAndStacks(componentType string, cmd *cobra.Command, args []str
if len(configAndStacksInfo.Context.Environment) == 0 {
return configAndStacksInfo,
errors.New(fmt.Sprintf("The stack name pattern '%s' specifies 'environment`, but the stack %s does not have an environment defined",
c.Config.Stacks.NamePattern,
config.Config.Stacks.NamePattern,
configAndStacksInfo.Stack,
))
}
Expand All @@ -342,7 +342,7 @@ func processConfigAndStacks(componentType string, cmd *cobra.Command, args []str
if len(configAndStacksInfo.Context.Stage) == 0 {
return configAndStacksInfo,
errors.New(fmt.Sprintf("The stack name pattern '%s' specifies 'stage`, but the stack %s does not have a stage defined",
c.Config.Stacks.NamePattern,
config.Config.Stacks.NamePattern,
configAndStacksInfo.Stack,
))
}
Expand All @@ -359,8 +359,8 @@ func processConfigAndStacks(componentType string, cmd *cobra.Command, args []str
}

// processArgsAndFlags removes common args and flags from the provided list of arguments/flags
func processArgsAndFlags(inputArgsAndFlags []string) (c.ArgsAndFlagsInfo, error) {
var info c.ArgsAndFlagsInfo
func processArgsAndFlags(inputArgsAndFlags []string) (config.ArgsAndFlagsInfo, error) {
var info config.ArgsAndFlagsInfo
var additionalArgsAndFlags []string
var globalOptions []string

Expand Down Expand Up @@ -509,8 +509,8 @@ func execCommand(command string, args []string, dir string, env []string) error
return cmd.Run()
}

func getContextFromVars(vars map[interface{}]interface{}) c.Context {
var context c.Context
func getContextFromVars(vars map[interface{}]interface{}) config.Context {
var context config.Context

if namespace, ok := vars["namespace"].(string); ok {
context.Namespace = namespace
Expand All @@ -535,7 +535,7 @@ func getContextFromVars(vars map[interface{}]interface{}) c.Context {
return context
}

func replaceContextTokens(context c.Context, pattern string) string {
func replaceContextTokens(context config.Context, pattern string) string {
return strings.Replace(
strings.Replace(
strings.Replace(
Expand Down
Loading

0 comments on commit 302aa83

Please sign in to comment.