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

get atmos config and vendor from .yaml or .yml #736

Merged
merged 5 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 3 additions & 2 deletions internal/exec/vendor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ func ReadAndProcessVendorConfigFile(cliConfig schema.CliConfiguration, vendorCon
}

foundVendorConfigFile := vendorConfigFile

// Look for the vendoring manifest in the current directory
if !u.FileExists(vendorConfigFile) {
foundVendorConfigFile, fileExists := u.SearchConfigFile(foundVendorConfigFile)

if !fileExists {
// Look for the vendoring manifest in the directory pointed to by the `base_path` setting in the `atmos.yaml`
pathToVendorConfig := path.Join(cliConfig.BasePath, vendorConfigFile)

Expand Down
9 changes: 5 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,20 @@ func processConfigFile(
path string,
v *viper.Viper,
) (bool, error) {
if !u.FileExists(path) {
// Check if the config file exists
configPath, fileExists := u.SearchConfigFile(path)
if !fileExists {
return false, nil
}

reader, err := os.Open(path)
reader, err := os.Open(configPath)
if err != nil {
return false, err
}

defer func(reader *os.File) {
err := reader.Close()
if err != nil {
u.LogWarning(cliConfig, fmt.Sprintf("error closing file '"+path+"'. "+err.Error()))
u.LogWarning(cliConfig, fmt.Sprintf("error closing file '"+configPath+"'. "+err.Error()))
}
}(reader)

Expand Down
15 changes: 15 additions & 0 deletions pkg/utils/file_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,18 @@ func IsSocket(path string) (bool, error) {
isSocket := fileInfo.Mode().Type() == fs.ModeSocket
return isSocket, nil
}

// search for a config file in the provided path with the provided extensions .yaml, .yml
func SearchConfigFile(path string) (string, bool) {
// Define the possible config file extensions
configExtensions := []string{".yaml", ".yml"}
// remove extension from path
path = strings.TrimSuffix(path, filepath.Ext(path))
for _, ext := range configExtensions {
filePath := path + ext
if FileExists(filePath) {
return filePath, true
}
}
return "", false
}
haitham911 marked this conversation as resolved.
Show resolved Hide resolved