Skip to content

Commit

Permalink
Set Default Schema to Remote Schema (#777)
Browse files Browse the repository at this point in the history
* feat: set default Atmos manifest URL if not specified in configuration

* feat: log trace message when using default Atmos JSON Schema file

* fix: improve error message for missing Atmos JSON Schema file

* Update internal/exec/validate_stacks.go

* fix: change log level from trace to info for default Atmos JSON Schema message

* fix: change log level from info to trace for default Atmos JSON Schema message

---------

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
Co-authored-by: Andriy Knysh <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 1020645 commit 39cf094
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions internal/exec/validate_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
u "github.com/cloudposse/atmos/pkg/utils"
)

const atmosManifestDefault = "https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json"

// ExecuteValidateStacksCmd executes `validate stacks` command
func ExecuteValidateStacksCmd(cmd *cobra.Command, args []string) error {
info, err := processCommandLineArgs("", cmd, args, nil)
Expand Down Expand Up @@ -84,27 +86,30 @@ func ValidateStacks(cliConfig schema.CliConfiguration) error {
// The path to the Atmos manifest JSON Schema can be absolute path or a path relative to the `base_path` setting in `atmos.yaml`
var atmosManifestJsonSchemaFilePath string

if cliConfig.Schemas.Atmos.Manifest != "" {
atmosManifestJsonSchemaFileAbsPath := path.Join(cliConfig.BasePath, cliConfig.Schemas.Atmos.Manifest)

if u.FileExists(cliConfig.Schemas.Atmos.Manifest) {
atmosManifestJsonSchemaFilePath = cliConfig.Schemas.Atmos.Manifest
} else if u.FileExists(atmosManifestJsonSchemaFileAbsPath) {
atmosManifestJsonSchemaFilePath = atmosManifestJsonSchemaFileAbsPath
} else if u.IsURL(cliConfig.Schemas.Atmos.Manifest) {
atmosManifestJsonSchemaFilePath, err = downloadSchemaFromURL(cliConfig.Schemas.Atmos.Manifest)
if err != nil {
return err
}
} else {
return fmt.Errorf("the Atmos JSON Schema file '%s' does not exist.\n"+
"It can be configured in the 'schemas.atmos.manifest' section in 'atmos.yaml', or provided using the 'ATMOS_SCHEMAS_ATMOS_MANIFEST' "+
"ENV variable or '--schemas-atmos-manifest' command line argument.\n"+
"The path to the schema file should be an absolute path or a path relative to the 'base_path' setting in 'atmos.yaml'. \n"+
"Alternatively, you can specify a schema file using a URL that will be downloaded automatically.",
cliConfig.Schemas.Atmos.Manifest)
if cliConfig.Schemas.Atmos.Manifest == "" {
cliConfig.Schemas.Atmos.Manifest = atmosManifestDefault
u.LogTrace(cliConfig, fmt.Sprintf("The Atmos JSON Schema file is not configured. Using the default schema '%s'", atmosManifestDefault))
}
atmosManifestJsonSchemaFileAbsPath := path.Join(cliConfig.BasePath, cliConfig.Schemas.Atmos.Manifest)

if u.FileExists(cliConfig.Schemas.Atmos.Manifest) {
atmosManifestJsonSchemaFilePath = cliConfig.Schemas.Atmos.Manifest
} else if u.FileExists(atmosManifestJsonSchemaFileAbsPath) {
atmosManifestJsonSchemaFilePath = atmosManifestJsonSchemaFileAbsPath
} else if u.IsURL(cliConfig.Schemas.Atmos.Manifest) {
atmosManifestJsonSchemaFilePath, err = downloadSchemaFromURL(cliConfig.Schemas.Atmos.Manifest)
if err != nil {
return err
}
} else {
return fmt.Errorf("Schema file '%s' not found. Configure via:\n"+
"1. 'schemas.atmos.manifest' in atmos.yaml\n"+
"2. ATMOS_SCHEMAS_ATMOS_MANIFEST env var\n"+
"3. --schemas-atmos-manifest flag\n\n"+
"Accepts: absolute path, paths relative to base_path, or URL",
cliConfig.Schemas.Atmos.Manifest)
}

// Include (process and validate) all YAML files in the `stacks` folder in all subfolders
includedPaths := []string{"**/*"}
// Don't exclude any YAML files for validation
Expand Down

0 comments on commit 39cf094

Please sign in to comment.