Skip to content

Commit

Permalink
Replace path.Join with filepath.Join
Browse files Browse the repository at this point in the history
  • Loading branch information
samtholiya committed Dec 14, 2024
1 parent c0e7054 commit b8d214c
Show file tree
Hide file tree
Showing 25 changed files with 120 additions and 127 deletions.
6 changes: 3 additions & 3 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -403,13 +403,13 @@ func printMessageForMissingAtmosConfig(cliConfig schema.CliConfiguration) {
u.PrintMessageInColor("atmos.yaml", c1)
fmt.Println(" CLI config file was not found.")
fmt.Print("\nThe default Atmos stacks directory is set to ")
u.PrintMessageInColor(path.Join(cliConfig.BasePath, cliConfig.Stacks.BasePath), c1)
u.PrintMessageInColor(filepath.Join(cliConfig.BasePath, cliConfig.Stacks.BasePath), c1)
fmt.Println(",\nbut the directory does not exist in the current path.")
} else {
// If Atmos found an `atmos.yaml` config file, but it defines invalid paths to Atmos stacks and components
u.PrintMessageInColor("atmos.yaml", c1)
fmt.Print(" CLI config file specifies the directory for Atmos stacks as ")
u.PrintMessageInColor(path.Join(cliConfig.BasePath, cliConfig.Stacks.BasePath), c1)
u.PrintMessageInColor(filepath.Join(cliConfig.BasePath, cliConfig.Stacks.BasePath), c1)
fmt.Println(",\nbut the directory does not exist.")
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"

"github.com/charmbracelet/glamour"
Expand Down Expand Up @@ -59,7 +59,7 @@ var docsCmd = &cobra.Command{
}

// Construct the full path to the Terraform component by combining the Atmos base path, Terraform base path, and component name
componentPath := path.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, info.Component)
componentPath := filepath.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, info.Component)
componentPathExists, err := u.IsDirectory(componentPath)
if err != nil {
u.LogErrorAndExit(schema.CliConfiguration{}, err)
Expand All @@ -68,7 +68,7 @@ var docsCmd = &cobra.Command{
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("Component '%s' not found in path: '%s'", info.Component, componentPath))
}

readmePath := path.Join(componentPath, "README.md")
readmePath := filepath.Join(componentPath, "README.md")
if _, err := os.Stat(readmePath); err != nil {
if os.IsNotExist(err) {
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("No README found for component: %s", info.Component))
Expand Down
3 changes: 1 addition & 2 deletions internal/exec/atlantis_generate_repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package exec

import (
"fmt"
"path"
"path/filepath"
"reflect"
"strings"
Expand Down Expand Up @@ -339,7 +338,7 @@ func ExecuteAtlantisGenerateRepoConfig(
}

// Absolute path to the terraform component
terraformComponentPath := path.Join(
terraformComponentPath := filepath.Join(
cliConfig.BasePath,
cliConfig.Components.Terraform.BasePath,
terraformComponent,
Expand Down
9 changes: 5 additions & 4 deletions internal/exec/aws_eks_update_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package exec

import (
"fmt"
"path/filepath"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"path"
"strings"

cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
Expand Down Expand Up @@ -157,11 +158,11 @@ func ExecuteAwsEksUpdateKubeconfig(kubeconfigContext schema.AwsEksUpdateKubeconf

configAndStacksInfo.ComponentType = "terraform"
configAndStacksInfo, err = ProcessStacks(cliConfig, configAndStacksInfo, true, true)
shellCommandWorkingDir = path.Join(cliConfig.TerraformDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
shellCommandWorkingDir = filepath.Join(cliConfig.TerraformDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
if err != nil {
configAndStacksInfo.ComponentType = "helmfile"
configAndStacksInfo, err = ProcessStacks(cliConfig, configAndStacksInfo, true, true)
shellCommandWorkingDir = path.Join(cliConfig.HelmfileDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
shellCommandWorkingDir = filepath.Join(cliConfig.HelmfileDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
if err != nil {
return err
}
Expand Down
16 changes: 8 additions & 8 deletions internal/exec/describe_affected_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,12 @@ func executeDescribeAffected(
}

// Update paths to point to the cloned remote repo dir
cliConfig.StacksBaseAbsolutePath = path.Join(remoteRepoFileSystemPath, basePath, cliConfig.Stacks.BasePath)
cliConfig.TerraformDirAbsolutePath = path.Join(remoteRepoFileSystemPath, basePath, cliConfig.Components.Terraform.BasePath)
cliConfig.HelmfileDirAbsolutePath = path.Join(remoteRepoFileSystemPath, basePath, cliConfig.Components.Helmfile.BasePath)
cliConfig.StacksBaseAbsolutePath = filepath.Join(remoteRepoFileSystemPath, basePath, cliConfig.Stacks.BasePath)
cliConfig.TerraformDirAbsolutePath = filepath.Join(remoteRepoFileSystemPath, basePath, cliConfig.Components.Terraform.BasePath)
cliConfig.HelmfileDirAbsolutePath = filepath.Join(remoteRepoFileSystemPath, basePath, cliConfig.Components.Helmfile.BasePath)

cliConfig.StackConfigFilesAbsolutePaths, err = u.JoinAbsolutePathWithPaths(
path.Join(remoteRepoFileSystemPath, basePath, cliConfig.Stacks.BasePath),
filepath.Join(remoteRepoFileSystemPath, basePath, cliConfig.Stacks.BasePath),
cliConfig.StackConfigFilesRelativePaths,
)
if err != nil {
Expand Down Expand Up @@ -1182,9 +1182,9 @@ func isComponentFolderChanged(

switch componentType {
case "terraform":
componentPath = path.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, component)
componentPath = filepath.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, component)
case "helmfile":
componentPath = path.Join(cliConfig.BasePath, cliConfig.Components.Helmfile.BasePath, component)
componentPath = filepath.Join(cliConfig.BasePath, cliConfig.Components.Helmfile.BasePath, component)
}

componentPathAbs, err := filepath.Abs(componentPath)
Expand Down Expand Up @@ -1220,7 +1220,7 @@ func areTerraformComponentModulesChanged(
changedFiles []string,
) (bool, error) {

componentPath := path.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, component)
componentPath := filepath.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, component)

componentPathAbs, err := filepath.Abs(componentPath)
if err != nil {
Expand All @@ -1241,7 +1241,7 @@ func areTerraformComponentModulesChanged(
continue
}

modulePath := path.Join(path.Dir(moduleConfig.Pos.Filename), moduleConfig.Source)
modulePath := filepath.Join(path.Dir(moduleConfig.Pos.Filename), moduleConfig.Source)

modulePathAbs, err := filepath.Abs(modulePath)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions internal/exec/helmfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package exec
import (
"fmt"
"os"
"path"
"path/filepath"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -74,20 +74,20 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
}

// Check if the component exists as a helmfile component
componentPath := path.Join(cliConfig.HelmfileDirAbsolutePath, info.ComponentFolderPrefix, info.FinalComponent)
componentPath := filepath.Join(cliConfig.HelmfileDirAbsolutePath, info.ComponentFolderPrefix, info.FinalComponent)
componentPathExists, err := u.IsDirectory(componentPath)
if err != nil || !componentPathExists {
return fmt.Errorf("'%s' points to the Helmfile component '%s', but it does not exist in '%s'",
info.ComponentFromArg,
info.FinalComponent,
path.Join(cliConfig.Components.Helmfile.BasePath, info.ComponentFolderPrefix),
filepath.Join(cliConfig.Components.Helmfile.BasePath, info.ComponentFolderPrefix),
)
}

// Check if the component is allowed to be provisioned (`metadata.type` attribute)
if (info.SubCommand == "sync" || info.SubCommand == "apply" || info.SubCommand == "deploy") && info.ComponentIsAbstract {
return fmt.Errorf("abstract component '%s' cannot be provisioned since it's explicitly prohibited from being deployed "+
"by 'metadata.type: abstract' attribute", path.Join(info.ComponentFolderPrefix, info.Component))
"by 'metadata.type: abstract' attribute", filepath.Join(info.ComponentFolderPrefix, info.Component))
}

// Print component variables
Expand Down Expand Up @@ -192,7 +192,7 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
u.LogDebug(cliConfig, "Stack: "+info.StackFromArg)
} else {
u.LogDebug(cliConfig, "Stack: "+info.StackFromArg)
u.LogDebug(cliConfig, "Stack path: "+path.Join(cliConfig.BasePath, cliConfig.Stacks.BasePath, info.Stack))
u.LogDebug(cliConfig, "Stack path: "+filepath.Join(cliConfig.BasePath, cliConfig.Stacks.BasePath, info.Stack))
}

workingDir := constructHelmfileComponentWorkingDir(cliConfig, info)
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/oci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
Expand All @@ -30,7 +30,7 @@ func processOciImage(cliConfig schema.CliConfiguration, imageName string, destDi
defer removeTempDir(cliConfig, tempDir)

// Temp tarball file name
tempTarFileName := path.Join(tempDir, uuid.New().String()) + ".tar"
tempTarFileName := filepath.Join(tempDir, uuid.New().String()) + ".tar"

// Get the image reference from the OCI registry
ref, err := name.ParseReference(imageName)
Expand Down Expand Up @@ -91,7 +91,7 @@ func processOciImage(cliConfig schema.CliConfiguration, imageName string, destDi

// Extract the layers into the destination directory
for _, l := range manifest.Layers {
layerPath := path.Join(tempDir, l)
layerPath := filepath.Join(tempDir, l)

err = extractTarball(cliConfig, layerPath, destDir)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/exec/stack_processor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func ProcessYAMLConfigFile(

found := false
for _, extension := range extensions {
testPath := path.Join(basePath, imp+extension)
testPath := filepath.Join(basePath, imp+extension)
if _, err := os.Stat(testPath); err == nil {
impWithExt = imp + extension
found = true
Expand All @@ -372,12 +372,12 @@ func ProcessYAMLConfigFile(
} else if ext == u.YamlFileExtension || ext == u.YmlFileExtension {
// Check if there's a template version of this file
templatePath := impWithExt + u.TemplateExtension
if _, err := os.Stat(path.Join(basePath, templatePath)); err == nil {
if _, err := os.Stat(filepath.Join(basePath, templatePath)); err == nil {
impWithExt = templatePath
}
}

impWithExtPath := path.Join(basePath, impWithExt)
impWithExtPath := filepath.Join(basePath, impWithExt)

if impWithExtPath == filePath {
errorMessage := fmt.Sprintf("invalid import in the manifest '%s'\nThe file imports itself in '%s'",
Expand Down Expand Up @@ -2180,7 +2180,7 @@ func ProcessBaseComponentConfig(
if checkBaseComponentExists {
// Check if the base component exists as Terraform/Helmfile component
// If it does exist, don't throw errors if it is not defined in YAML config
componentPath := path.Join(componentBasePath, baseComponent)
componentPath := filepath.Join(componentBasePath, baseComponent)
componentPathExists, err := u.IsDirectory(componentPath)
if err != nil || !componentPathExists {
return errors.New("The component '" + component + "' inherits from the base component '" +
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/stack_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exec

import (
"fmt"
"path"
"path/filepath"
"strings"

cfg "github.com/cloudposse/atmos/pkg/config"
Expand Down Expand Up @@ -163,9 +163,9 @@ func BuildComponentPath(

if stackComponentSection, ok := componentSectionMap[cfg.ComponentSectionName].(string); ok {
if componentType == "terraform" {
componentPath = path.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, stackComponentSection)
componentPath = filepath.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, stackComponentSection)
} else if componentType == "helmfile" {
componentPath = path.Join(cliConfig.BasePath, cliConfig.Components.Helmfile.BasePath, stackComponentSection)
componentPath = filepath.Join(cliConfig.BasePath, cliConfig.Components.Helmfile.BasePath, stackComponentSection)
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/exec/terraform_generate_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exec

import (
"fmt"
"path"
"path/filepath"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -75,7 +75,7 @@ func ExecuteTerraformGenerateBackendCmd(cmd *cobra.Command, args []string) error
}

// Write backend config to file
var backendFilePath = path.Join(
var backendFilePath = filepath.Join(
cliConfig.BasePath,
cliConfig.Components.Terraform.BasePath,
info.ComponentFolderPrefix,
Expand Down
5 changes: 2 additions & 3 deletions internal/exec/terraform_generate_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package exec
import (
"errors"
"fmt"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -161,7 +160,7 @@ func ExecuteTerraformGenerateBackends(
}

// Path to the terraform component
terraformComponentPath := path.Join(
terraformComponentPath := filepath.Join(
cliConfig.BasePath,
cliConfig.Components.Terraform.BasePath,
terraformComponent,
Expand Down Expand Up @@ -291,7 +290,7 @@ func ExecuteTerraformGenerateBackends(

processedTerraformComponents[terraformComponent] = terraformComponent

backendFilePath = path.Join(
backendFilePath = filepath.Join(
terraformComponentPath,
"backend.tf",
)
Expand Down
3 changes: 1 addition & 2 deletions internal/exec/terraform_generate_varfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package exec
import (
"errors"
"fmt"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -160,7 +159,7 @@ func ExecuteTerraformGenerateVarfiles(
}

// Absolute path to the terraform component
terraformComponentPath := path.Join(
terraformComponentPath := filepath.Join(
cliConfig.BasePath,
cliConfig.Components.Terraform.BasePath,
terraformComponent,
Expand Down
5 changes: 2 additions & 3 deletions internal/exec/terraform_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"time"

Expand Down Expand Up @@ -88,7 +87,7 @@ func execTerraformOutput(cliConfig schema.CliConfiguration, component string, st

// Auto-generate backend file
if cliConfig.Components.Terraform.AutoGenerateBackendFile {
backendFileName := path.Join(componentPath, "backend.tf.json")
backendFileName := filepath.Join(componentPath, "backend.tf.json")

u.LogTrace(cliConfig, "\nWriting the backend config to file:")
u.LogTrace(cliConfig, backendFileName)
Expand Down Expand Up @@ -121,7 +120,7 @@ func execTerraformOutput(cliConfig schema.CliConfiguration, component string, st
providersSection, ok := sections["providers"].(map[string]any)

if ok && len(providersSection) > 0 {
providerOverrideFileName := path.Join(componentPath, "providers_override.tf.json")
providerOverrideFileName := filepath.Join(componentPath, "providers_override.tf.json")

u.LogTrace(cliConfig, "\nWriting the provider overrides to file:")
u.LogTrace(cliConfig, providerOverrideFileName)
Expand Down
8 changes: 4 additions & 4 deletions internal/exec/validate_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package exec
import (
"fmt"
"os"
"path"
"path/filepath"

"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
Expand Down Expand Up @@ -197,11 +197,11 @@ func validateComponentInternal(
switch schemaType {
case "jsonschema":
{
filePath = path.Join(cliConfig.BasePath, cliConfig.Schemas.JsonSchema.BasePath, schemaPath)
filePath = filepath.Join(cliConfig.BasePath, cliConfig.Schemas.JsonSchema.BasePath, schemaPath)
}
case "opa":
{
filePath = path.Join(cliConfig.BasePath, cliConfig.Schemas.Opa.BasePath, schemaPath)
filePath = filepath.Join(cliConfig.BasePath, cliConfig.Schemas.Opa.BasePath, schemaPath)
}
}

Expand All @@ -228,7 +228,7 @@ func validateComponentInternal(
}
case "opa":
{
modulePathsAbsolute, err := u.JoinAbsolutePathWithPaths(path.Join(cliConfig.BasePath, cliConfig.Schemas.Opa.BasePath), modulePaths)
modulePathsAbsolute, err := u.JoinAbsolutePathWithPaths(filepath.Join(cliConfig.BasePath, cliConfig.Schemas.Opa.BasePath), modulePaths)
if err != nil {
return false, err
}
Expand Down
Loading

0 comments on commit b8d214c

Please sign in to comment.