Skip to content

Commit

Permalink
add validator command
Browse files Browse the repository at this point in the history
  • Loading branch information
drichelson committed May 31, 2024
1 parent 0684678 commit 2d6091a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
28 changes: 28 additions & 0 deletions cmd/validator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"github.com/dorklyorg/dorkly/internal/dorkly"
"os"
)

const (
dorklyYamlEnvVar = "DORKLY_YAML"
defaultDorklyYamlInputPath = "project"
)

var logger = dorkly.GetLogger().Named("Validator")

func main() {
dorklyYamlInputPath := os.Getenv(dorklyYamlEnvVar)
if dorklyYamlInputPath == "" {
logger.Debugf("Env var [%s] not set. Using default: %s", dorklyYamlEnvVar, defaultDorklyYamlInputPath)
dorklyYamlInputPath = defaultDorklyYamlInputPath
}
l := logger.With("dorklyYamlInputPath", dorklyYamlInputPath)

p, err := dorkly.ValidateYamlProject(dorklyYamlInputPath)
if err != nil {
l.Fatalf("Failed to validate project yaml files: %v", err)
}
l.With("project", p).Info("Project yaml files validated successfully")
}
7 changes: 7 additions & 0 deletions internal/dorkly/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dorkly

// ValidateYamlProject loads the project yaml files from the given path and validates them.
// It returns a Project struct if the yaml files are valid, otherwise it returns an error.
func ValidateYamlProject(path string) (*Project, error) {
return loadProjectYamlFiles(path)
}
3 changes: 1 addition & 2 deletions tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
- [ ] Terraform: github repo: set up protected branch + pull request checks
- [ ] yaml files validation: warn if flag is defined in the project but not an environment
- [ ] yaml files validation: error if flag is defined in an environment but not in the project
- [ ] yaml files validation: error if env flag type does not match project flag type (ie 'true' for a rollout flag)
- [x] yaml files validation: error if env flag type does not match project flag type (ie 'true' for a rollout flag). This will fail yaml unmarshaling.

### Maybe not required for MVP:
- [ ] Consider enabling configuring ld-relay client context (aka goals endpoint): https://github.com/launchdarkly/ld-relay/blob/1adf0dde5b11343d3bdf011c86e3f7116c4960fc/internal/relayenv/js_context.go#L7
- [ ] Terraform: validate variables (see TODOs in https://github.com/dorklyorg/terraform-aws-dorkly-flags/blob/main/variables.tf)
- [ ] Terraform: Consider a command line tool to quickly create new flags and maybe turn them off in all envs
- [ ] Terraform: Use freeform workflow with human input to create flags
- [ ] Use localstack to do end to end testing (if possible)
- [ ] Maybe never: Implement mobile key and client-side sdk setup (for now people should just use the client id)

### Pending DX tasks
- [ ] temporary files and archives: keep them in memory avoiding weird filesystem bugs/flaky tests.
Expand Down

0 comments on commit 2d6091a

Please sign in to comment.