Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace path with filepath #900

Merged
merged 6 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/cmd_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"
"strings"
"time"
Expand Down Expand Up @@ -405,7 +404,8 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) {
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(atmosConfig.BasePath, atmosConfig.Stacks.BasePath), c1)

u.PrintMessageInColor(filepath.Join(atmosConfig.BasePath, atmosConfig.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
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(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, info.Component)
componentPath := filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, info.Component)
componentPathExists, err := u.IsDirectory(componentPath)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
Expand All @@ -68,7 +68,7 @@ var docsCmd = &cobra.Command{
u.LogErrorAndExit(schema.AtmosConfiguration{}, 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.AtmosConfiguration{}, 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(
atmosConfig.BasePath,
atmosConfig.Components.Terraform.BasePath,
terraformComponent,
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/aws_eks_update_kubeconfig.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"

"github.com/pkg/errors"
Expand Down Expand Up @@ -158,11 +158,11 @@ func ExecuteAwsEksUpdateKubeconfig(kubeconfigContext schema.AwsEksUpdateKubeconf

configAndStacksInfo.ComponentType = "terraform"
configAndStacksInfo, err = ProcessStacks(atmosConfig, configAndStacksInfo, true, true)
shellCommandWorkingDir = path.Join(atmosConfig.TerraformDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
shellCommandWorkingDir = filepath.Join(atmosConfig.TerraformDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
if err != nil {
configAndStacksInfo.ComponentType = "helmfile"
configAndStacksInfo, err = ProcessStacks(atmosConfig, configAndStacksInfo, true, true)
shellCommandWorkingDir = path.Join(atmosConfig.HelmfileDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
shellCommandWorkingDir = filepath.Join(atmosConfig.HelmfileDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
if err != nil {
return err
}
Expand Down
17 changes: 8 additions & 9 deletions internal/exec/describe_affected_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"reflect"
"strconv"
Expand Down Expand Up @@ -424,17 +423,17 @@ func executeDescribeAffected(
// Absolute base path can be set in the `base_path` attribute in `atmos.yaml`, or using the ENV var `ATMOS_BASE_PATH` (as it's done in `geodesic`)
// If the `atmos` base path is absolute, find the relative path between the local repo path and the `atmos` base path.
// This relative path (the difference) is then used below to join with the remote (cloned) target repo path.
if path.IsAbs(basePath) {
if filepath.IsAbs(basePath) {
basePath, err = filepath.Rel(localRepoFileSystemPathAbs, basePath)
if err != nil {
return nil, nil, nil, err
}
}

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

atmosConfig.StackConfigFilesAbsolutePaths, err = u.JoinAbsolutePathWithPaths(
filepath.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Stacks.BasePath),
Expand Down Expand Up @@ -1182,9 +1181,9 @@ func isComponentFolderChanged(

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

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

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

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

modulePath := path.Join(path.Dir(moduleConfig.Pos.Filename), moduleConfig.Source)
modulePath := filepath.Join(filepath.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 @@ -78,20 +78,20 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
}

// Check if the component exists as a helmfile component
componentPath := path.Join(atmosConfig.HelmfileDirAbsolutePath, info.ComponentFolderPrefix, info.FinalComponent)
componentPath := filepath.Join(atmosConfig.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(atmosConfig.Components.Helmfile.BasePath, info.ComponentFolderPrefix),
filepath.Join(atmosConfig.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 @@ -196,7 +196,7 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
u.LogDebug(atmosConfig, "Stack: "+info.StackFromArg)
} else {
u.LogDebug(atmosConfig, "Stack: "+info.StackFromArg)
u.LogDebug(atmosConfig, "Stack path: "+path.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath, info.Stack))
u.LogDebug(atmosConfig, "Stack path: "+filepath.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath, info.Stack))
}

workingDir := constructHelmfileComponentWorkingDir(atmosConfig, 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(atmosConfig schema.AtmosConfiguration, imageName string, de
defer removeTempDir(atmosConfig, 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(atmosConfig schema.AtmosConfiguration, imageName string, de

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

err = extractTarball(atmosConfig, layerPath, destDir)
if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions internal/exec/stack_processor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
"reflect"
"sort"
Expand Down Expand Up @@ -60,7 +59,7 @@ func ProcessYAMLConfigFiles(

stackBasePath := stacksBasePath
if len(stackBasePath) < 1 {
stackBasePath = path.Dir(p)
stackBasePath = filepath.Dir(p)
}

stackFileName := strings.TrimSuffix(
Expand Down Expand Up @@ -357,7 +356,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 +371,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 @@ -1826,7 +1825,7 @@ func CreateComponentStackMap(
componentStackMap["terraform"] = map[string][]string{}
componentStackMap["helmfile"] = map[string][]string{}

dir := path.Dir(filePath)
dir := filepath.Dir(filePath)

err := filepath.Walk(dir,
func(p string, info os.FileInfo, err error) error {
Expand Down Expand Up @@ -2180,7 +2179,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 @@ -164,9 +164,9 @@ func BuildComponentPath(

if stackComponentSection, ok := componentSectionMap[cfg.ComponentSectionName].(string); ok {
if componentType == "terraform" {
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, stackComponentSection)
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, stackComponentSection)
} else if componentType == "helmfile" {
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath, stackComponentSection)
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.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(
atmosConfig.BasePath,
atmosConfig.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(
atmosConfig.BasePath,
atmosConfig.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(
atmosConfig.BasePath,
atmosConfig.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(atmosConfig schema.AtmosConfiguration, component string

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

u.LogTrace(atmosConfig, "\nWriting the backend config to file:")
u.LogTrace(atmosConfig, backendFileName)
Expand Down Expand Up @@ -121,7 +120,7 @@ func execTerraformOutput(atmosConfig schema.AtmosConfiguration, component string
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(atmosConfig, "\nWriting the provider overrides to file:")
u.LogTrace(atmosConfig, providerOverrideFileName)
Expand Down
Loading
Loading