Skip to content

Commit

Permalink
fix linter errors config.go
Browse files Browse the repository at this point in the history
  • Loading branch information
haitham911 committed Mar 9, 2025
1 parent 9ab9d3c commit eff1fd7
Showing 1 changed file with 52 additions and 37 deletions.
89 changes: 52 additions & 37 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"path/filepath"

log "github.com/charmbracelet/log"
"github.com/pkg/errors"

"github.com/cloudposse/atmos/pkg/schema"
Expand All @@ -15,97 +16,112 @@ import (
// https://dev.to/techschoolguru/load-config-from-file-environment-variables-in-golang-with-viper-2j2d
// https://medium.com/@bnprashanth256/reading-configuration-files-and-environment-variables-in-go-golang-c2607f912b63
func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks bool) (schema.AtmosConfiguration, error) {

Check failure on line 18 in pkg/config/config.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] pkg/config/config.go#L18

hugeParam: configAndStacksInfo is heavy (1088 bytes); consider passing it by pointer (gocritic)
Raw output
pkg/config/config.go:18:20: hugeParam: configAndStacksInfo is heavy (1088 bytes); consider passing it by pointer (gocritic)
func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks bool) (schema.AtmosConfiguration, error) {
                   ^
atmosConfig, err := LoadConfig(&configAndStacksInfo)
atmosConfig, err := processAtmosConfigs(&configAndStacksInfo)
if err != nil {
return atmosConfig, err
}
// Process ENV vars
err = processEnvVars(&atmosConfig)
// Process the base path specified in the Terraform provider (which calls into the atmos code)
// This overrides all other atmos base path configs (`atmos.yaml`, ENV var `ATMOS_BASE_PATH`)
if configAndStacksInfo.AtmosBasePath != "" {
atmosConfig.BasePath = configAndStacksInfo.AtmosBasePath

Check warning on line 26 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L26

Added line #L26 was not covered by tests
}

// After unmarshalling, ensure AppendUserAgent is set if still empty
if atmosConfig.Components.Terraform.AppendUserAgent == "" {
atmosConfig.Components.Terraform.AppendUserAgent = fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version)

Check warning on line 31 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L31

Added line #L31 was not covered by tests
}

// Check config
err = checkConfig(atmosConfig, processStacks)
if err != nil {
return atmosConfig, err
}

// Process command-line args
err = processCommandLineArgs(&atmosConfig, configAndStacksInfo)
err = atmosConfigAbsolutePaths(&atmosConfig)
if err != nil {
return atmosConfig, err
}

// Process stores config
err = processStoreConfig(&atmosConfig)
if processStacks {
err = processStackConfigs(&atmosConfig, &configAndStacksInfo, atmosConfig.IncludeStackAbsolutePaths, atmosConfig.ExcludeStackAbsolutePaths)

Check warning on line 46 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L46

Added line #L46 was not covered by tests
if err != nil {
return atmosConfig, err
}
}

atmosConfig.Initialized = true
return atmosConfig, nil
}

func processAtmosConfigs(configAndStacksInfo *schema.ConfigAndStacksInfo) (schema.AtmosConfiguration, error) {
atmosConfig, err := LoadConfig(configAndStacksInfo)
if err != nil {
return atmosConfig, err
}

// Process the base path specified in the Terraform provider (which calls into the atmos code)
// This overrides all other atmos base path configs (`atmos.yaml`, ENV var `ATMOS_BASE_PATH`)
if configAndStacksInfo.AtmosBasePath != "" {
atmosConfig.BasePath = configAndStacksInfo.AtmosBasePath
// Process ENV vars
err = processEnvVars(&atmosConfig)
if err != nil {
return atmosConfig, err
}

// After unmarshalling, ensure AppendUserAgent is set if still empty
if atmosConfig.Components.Terraform.AppendUserAgent == "" {
atmosConfig.Components.Terraform.AppendUserAgent = fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version)
// Process command-line args
err = processCommandLineArgs(&atmosConfig, *configAndStacksInfo)
if err != nil {
return atmosConfig, err
}

// Check config
err = checkConfig(atmosConfig, processStacks)
// Process stores config
err = processStoreConfig(&atmosConfig)
if err != nil {
return atmosConfig, err
}
return atmosConfig, nil
}

// atmosConfigAbsolutePaths Convert paths to absolute path.
func atmosConfigAbsolutePaths(atmosConfig *schema.AtmosConfiguration) error {
// Convert stacks base path to absolute path
stacksBasePath := filepath.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath)
stacksBaseAbsPath, err := filepath.Abs(stacksBasePath)
if err != nil {
return atmosConfig, err
return err

Check warning on line 87 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L87

Added line #L87 was not covered by tests
}
atmosConfig.StacksBaseAbsolutePath = stacksBaseAbsPath

// Convert the included stack paths to absolute paths
includeStackAbsPaths, err := u.JoinAbsolutePathWithPaths(stacksBaseAbsPath, atmosConfig.Stacks.IncludedPaths)
if err != nil {
return atmosConfig, err
return err

Check warning on line 94 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L94

Added line #L94 was not covered by tests
}
atmosConfig.IncludeStackAbsolutePaths = includeStackAbsPaths

// Convert the excluded stack paths to absolute paths
excludeStackAbsPaths, err := u.JoinAbsolutePathWithPaths(stacksBaseAbsPath, atmosConfig.Stacks.ExcludedPaths)
if err != nil {
return atmosConfig, err
return err

Check warning on line 101 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L101

Added line #L101 was not covered by tests
}
atmosConfig.ExcludeStackAbsolutePaths = excludeStackAbsPaths

// Convert terraform dir to absolute path
terraformBasePath := filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath)
terraformDirAbsPath, err := filepath.Abs(terraformBasePath)
if err != nil {
return atmosConfig, err
return err

Check warning on line 109 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L109

Added line #L109 was not covered by tests
}
atmosConfig.TerraformDirAbsolutePath = terraformDirAbsPath

// Convert helmfile dir to absolute path
helmfileBasePath := filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath)
helmfileDirAbsPath, err := filepath.Abs(helmfileBasePath)
if err != nil {
return atmosConfig, err
return err

Check warning on line 117 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L117

Added line #L117 was not covered by tests
}
atmosConfig.HelmfileDirAbsolutePath = helmfileDirAbsPath

if processStacks {
if processStacks {
err = processStackConfigs(&atmosConfig, configAndStacksInfo, includeStackAbsPaths, excludeStackAbsPaths)
if err != nil {
return atmosConfig, err
}
}
}

atmosConfig.Initialized = true
return atmosConfig, nil
return nil
}

func processStackConfigs(atmosConfig *schema.AtmosConfiguration, configAndStacksInfo schema.ConfigAndStacksInfo, includeStackAbsPaths, excludeStackAbsPaths []string) error {
func processStackConfigs(atmosConfig *schema.AtmosConfiguration, configAndStacksInfo *schema.ConfigAndStacksInfo, includeStackAbsPaths, excludeStackAbsPaths []string) error {
// If the specified stack name is a logical name, find all stack manifests in the provided paths
stackConfigFilesAbsolutePaths, stackConfigFilesRelativePaths, stackIsPhysicalPath, err := FindAllStackConfigsInPathsForStack(
*atmosConfig,
Expand All @@ -132,10 +148,9 @@ func processStackConfigs(atmosConfig *schema.AtmosConfiguration, configAndStacks
atmosConfig.StackConfigFilesRelativePaths = stackConfigFilesRelativePaths

if stackIsPhysicalPath {
u.LogTrace(fmt.Sprintf("\nThe stack '%s' matches the stack manifest %s\n",
log.Debug(fmt.Sprintf("\nThe stack '%s' matches the stack manifest %s\n",
configAndStacksInfo.Stack,
stackConfigFilesRelativePaths[0]),
)
stackConfigFilesRelativePaths[0]))
atmosConfig.StackType = "Directory"
} else {
// The stack is a logical name
Expand Down

0 comments on commit eff1fd7

Please sign in to comment.