Skip to content

Commit 607c12a

Browse files
authored
Merge branch 'main' into fix/nested-list
2 parents d876261 + c87cd51 commit 607c12a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4552
-13
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ linters-settings:
115115
- name: add-constant
116116
arguments:
117117
- maxLitCount: "3"
118-
allowStrs: '"","image","error","path","import","path","%w","%s"'
118+
allowStrs: '"","image","error","path","import","path","%w","%s","file","/"'
119119
allowInts: "0,1,2,3,4"
120120
allowFloats: "0.0,0.,1.0,1.,2.0,2."
121121
- name: argument-limit

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ testacc: get
6161

6262
testacc-cover: get
6363
@echo "Running tests with coverage"
64-
go test $(TEST) -v $(TESTARGS) -timeout 20m -coverprofile=coverage.out
64+
go test $(TEST) -v $(TESTARGS) -timeout 20m -coverprofile=coverage.out.tmp
65+
cat coverage.out.tmp | grep -v "mock_" > coverage.out
6566

6667
# Run acceptance tests with coverage report
6768
testacc-coverage: testacc-cover
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- Validate all the schemas
2+
3+
```bash
4+
$ atmos validate schema
5+
```
6+
7+
- Validate specific schema
8+
9+
```
10+
$ atmos validate schema [schemaToValidate]
11+
```

cmd/validate_schema.go

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
6+
log "github.com/charmbracelet/log"
7+
"github.com/cloudposse/atmos/internal/exec"
8+
u "github.com/cloudposse/atmos/pkg/utils"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// ValidateSchemaCmd represents the 'atmos validate schema' command.
13+
//
14+
// This command reads the 'schemas' section from the atmos.yaml configuration file,
15+
// where each schema entry specifies a JSON schema path and a glob pattern for matching YAML files.
16+
//
17+
// For each entry:
18+
// - The JSON schema is loaded.
19+
// - All YAML files matching the glob pattern are discovered.
20+
// - Each YAML file is converted to JSON and validated against the schema.
21+
//
22+
// This command ensures that configuration files conform to expected structures and helps
23+
// catch errors early in the development or deployment process.
24+
var ValidateSchemaCmd = &cobra.Command{
25+
Use: "schema",
26+
Short: "Validate YAML files against JSON schemas defined in atmos.yaml",
27+
Long: `The validate schema command reads the ` + "`" + `schemas` + "`" + ` section of the atmos.yaml file
28+
and validates matching YAML files against their corresponding JSON schemas.
29+
30+
Each entry under ` + "`" + `schemas` + "`" + ` should define:
31+
- ` + "`" + `schema` + "`" + `: The path to the JSON schema file.
32+
- ` + "`" + `matches` + "`" + `: A glob pattern that specifies which YAML files to validate.
33+
34+
For every schema entry:
35+
- The JSON schema is loaded from the specified path.
36+
- All files matching the glob pattern are collected.
37+
- Each matching YAML file is parsed and converted to JSON.
38+
- The converted YAML is validated against the schema.
39+
40+
This command helps ensure that configuration files follow a defined structure
41+
and are compliant with expected formats, reducing configuration drift and runtime errors.
42+
`,
43+
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
44+
Args: cobra.MaximumNArgs(1),
45+
Run: func(cmd *cobra.Command, args []string) {
46+
// Check Atmos configuration
47+
checkAtmosConfig()
48+
schema := ""
49+
key := ""
50+
if len(args) > 0 {
51+
key = args[0] // Use provided argument
52+
}
53+
54+
if cmd.Flags().Changed("schemas-atmos-manifest") {
55+
schema, _ = cmd.Flags().GetString("schemas-atmos-manifest")
56+
}
57+
58+
if key == "" && schema != "" {
59+
log.Error("key not provided for the schema to be used")
60+
u.OsExit(1)
61+
}
62+
63+
if err := exec.NewAtmosValidatorExecutor(&atmosConfig).ExecuteAtmosValidateSchemaCmd(key, schema); err != nil {
64+
if errors.Is(err, exec.ErrInvalidYAML) {
65+
u.OsExit(1)
66+
}
67+
u.PrintErrorMarkdownAndExit("", err, "")
68+
}
69+
},
70+
}
71+
72+
func init() {
73+
ValidateSchemaCmd.PersistentFlags().String("schemas-atmos-manifest", "", "Specifies the path to a JSON schema file used to validate the structure and content of the Atmos manifest file")
74+
validateCmd.AddCommand(ValidateSchemaCmd)
75+
}

codecov.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ coverage:
99
threshold: 2% # Allow a small drop in coverage
1010
base: auto
1111
ignore:
12+
- "**/mock_*.go" # Adjust this pattern based on your project structure
1213
- "mock_*.go" # Adjust this pattern based on your project structure
1314

1415
comment:

examples/demo-schemas/atmos.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
schemas:
2+
schemaFromFile:
3+
manifest: ./manifest.json
4+
matches:
5+
- config.yaml
6+
schemaFromInternet:
7+
manifest: https://json.schemastore.org/bower.json
8+
matches:
9+
- bower.yaml
10+
schemaFromInline:
11+
manifest: |
12+
{
13+
"type": "object",
14+
"properties": {
15+
"name": { "type": "string" },
16+
"age": { "type": "integer" }
17+
},
18+
"required": ["name"]
19+
}
20+
matches:
21+
- inline.yaml

examples/demo-schemas/bower.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: "my-project"
2+
version: "1.0.0"
3+
description: "A sample project to demonstrate bower.json schema validation."
4+
main: "index.js"
5+
authors:
6+
- "Jane Doe <[email protected]>"
7+
license: "MIT"
8+
dependencies:
9+
jquery: "^3.5.1"
10+
lodash: "^4.17.20"

examples/demo-schemas/config.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "MyApp"
2+
version: "1.0.0"
3+
enabled: true
4+
settings:
5+
timeout: 30
6+
debug: false
7+
users:
8+
- id: 1
9+
name: "Alice"
10+
role: "admin"
11+
- id: 2
12+
name: "Bob"
13+
role: "user"
14+
- id: 3
15+
name: "Charlie"
16+
role: "guest"

examples/demo-schemas/inline.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: John
2+
age: 30

examples/demo-schemas/manifest.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"name": {
6+
"type": "string"
7+
},
8+
"version": {
9+
"type": "string",
10+
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
11+
},
12+
"enabled": {
13+
"type": "boolean"
14+
},
15+
"settings": {
16+
"type": "object",
17+
"properties": {
18+
"timeout": {
19+
"type": "integer",
20+
"minimum": 1
21+
},
22+
"debug": {
23+
"type": "boolean"
24+
}
25+
},
26+
"required": ["timeout"]
27+
},
28+
"users": {
29+
"type": "array",
30+
"items": {
31+
"type": "object",
32+
"properties": {
33+
"id": {
34+
"type": "integer"
35+
},
36+
"name": {
37+
"type": "string"
38+
},
39+
"role": {
40+
"type": "string",
41+
"enum": ["admin", "user", "guest"]
42+
}
43+
},
44+
"required": ["id", "name", "role"]
45+
}
46+
}
47+
},
48+
"required": ["name", "version", "enabled", "settings"]
49+
}
50+

go.mod

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.sum

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/exec/describe_stacks.go

+2
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ func ExecuteDescribeStacks(
347347
}
348348

349349
// Atmos component, stack, and stack manifest file
350+
configAndStacksInfo.Stack = stackName
350351
componentSection["atmos_component"] = componentName
351352
componentSection["atmos_stack"] = stackName
352353
componentSection["stack"] = stackName
@@ -539,6 +540,7 @@ func ExecuteDescribeStacks(
539540
finalStacksMap[stackName] = make(map[string]any)
540541
}
541542

543+
configAndStacksInfo.Stack = stackName
542544
configAndStacksInfo.ComponentSection["atmos_component"] = componentName
543545
configAndStacksInfo.ComponentSection["atmos_stack"] = stackName
544546
configAndStacksInfo.ComponentSection["stack"] = stackName

0 commit comments

Comments
 (0)