-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from uselagoon/configmap-validation
Add configmap dump validation
- Loading branch information
Showing
5 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/uselagoon/lagoon-linter/internal/lagoonyml" | ||
) | ||
|
||
// ValidateConfigMapJSONCmd represents the validate command. | ||
type ValidateConfigMapJSONCmd struct { | ||
ConfigMapJSON string `kong:"default='configmap.json',help='Specify the configmap JSON file dump.'"` | ||
} | ||
|
||
// ConfigMap represents an individual configmap. | ||
type ConfigMap struct { | ||
Data map[string]string `json:"data"` | ||
Metadata map[string]interface{} `json:"metadata"` | ||
} | ||
|
||
// ConfigMapList represents a list of configmaps. | ||
type ConfigMapList struct { | ||
ConfigMaps []ConfigMap `json:"items"` | ||
} | ||
|
||
// Run the validation of the Lagoon YAML dumps. | ||
func (cmd *ValidateConfigMapJSONCmd) Run() error { | ||
// open the file | ||
rawJSON, err := os.ReadFile(cmd.ConfigMapJSON) | ||
if err != nil { | ||
return fmt.Errorf("couldn't read file: %v", err) | ||
} | ||
var cml ConfigMapList | ||
// unmarshal ConfigMapList | ||
if err := json.Unmarshal(rawJSON, &cml); err != nil { | ||
return fmt.Errorf("couldn't unmarshal JSON: %v", err) | ||
} | ||
// lint it | ||
for _, cm := range cml.ConfigMaps { | ||
if lagoonYAML, ok := cm.Data[".lagoon.yml"]; ok { | ||
err := lagoonyml.LintYAML([]byte(lagoonYAML), | ||
lagoonyml.RouteAnnotation()) | ||
if err != nil { | ||
fmt.Printf("bad .lagoon.yml: %s: %v\n", cm.Metadata["namespace"], err) | ||
} | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters