Skip to content

Commit

Permalink
atmos.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Listener430 committed Dec 24, 2024
1 parent 61df3aa commit 0f8f036
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"net/url"
"os"
"path/filepath"
"runtime"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/spf13/viper"

"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/utils"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/cloudposse/atmos/pkg/version"
)
Expand Down Expand Up @@ -99,6 +101,8 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks
// system dir (`/usr/local/etc/atmos` on Linux, `%LOCALAPPDATA%/atmos` on Windows)
// home dir (~/.atmos)
// current directory
// ENV var ATMOS_CLI_CONFIG_PATH
// ENV var ATMOS_REMOTE_CONFIG_URL from GITHUB
// ENV vars
// Command-line arguments

Expand Down Expand Up @@ -199,6 +203,18 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks
}
}

// Process remote config from a GITHUB URL from the path in ENV var `ATMOS_REMOTE_CONFIG_URL`
configFilePath6 := os.Getenv("ATMOS_REMOTE_CONFIG_URL")
if len(configFilePath6) > 0 {
found, err = processRemoteConfigFile(atmosConfig, configFilePath6, v)
if err != nil {
return atmosConfig, err
}
if found {
configFound = true
}
}

if !configFound {
// If `atmos.yaml` not found, use the default config
// Set `ATMOS_LOGS_LEVEL` ENV var to "Debug" to see the message about Atmos using the default CLI config
Expand Down Expand Up @@ -382,3 +398,34 @@ func processConfigFile(

return true, nil
}

// processRemoteConfigFile attempts to download and merge a remote atmos.yaml
// from a URL. It currently only supports GitHub URLs.
func processRemoteConfigFile(
atmosConfig schema.AtmosConfiguration,
rawURL string,
v *viper.Viper,
) (bool, error) {
parsedURL, err := url.Parse(rawURL)
if err != nil {
u.LogWarning(atmosConfig, fmt.Sprintf("Failed to parse remote config URL '%s': %s", rawURL, err.Error()))
return false, nil
}

if parsedURL.Scheme != "https" || parsedURL.Host != "github.com" {
return false, nil
}

data, err := utils.DownloadFileFromGitHub(rawURL)
if err != nil {
u.LogWarning(atmosConfig, fmt.Sprintf("Failed to download remote config from GitHub '%s': %s", rawURL, err.Error()))
return false, nil
}

err = v.MergeConfig(bytes.NewReader(data))
if err != nil {
return false, fmt.Errorf("failed to merge remote config from GitHub '%s': %w", rawURL, err)
}

return true, nil
}

0 comments on commit 0f8f036

Please sign in to comment.