Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scopes should have some validation #43

Open
spilliams opened this issue Feb 15, 2023 · 1 comment
Open

Scopes should have some validation #43

spilliams opened this issue Feb 15, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@spilliams
Copy link
Owner

spilliams commented Feb 15, 2023

as a safety feature. I would like terrascope to stop me if I've mistyped my scope values, or if I use a duplicate scope value, or if I put weird characters in my scope value that would not play nicely with the places that value ends up (e.g. state bucket path).

I would also like terrascope to stop me if I've misconstrued the scope patterns (for example, put a "Red" domain artifact in the "Gold" platform instead of the "Silver" platform)

The AC for this ticket is that:

  1. there is a schema for setting validation on a scope type
  2. when running a project, it will raise an error if any of the scope data does not conform to the validation

Other tickets will cover other topics about this feature.

@spilliams spilliams added the enhancement New feature or request label Feb 15, 2023
@spilliams spilliams added this to the scope-validation milestone Feb 15, 2023
@spilliams
Copy link
Owner Author

When parsing a block, you can set a context. If you give the context Values and Functions then you can use those during the decoding. Something like:

ctx := &hcl.EvalContext{
    Variables: map[string]cty.Value{
        "scope": cty.ObjectVal(map[string]cty.Value{
            "value":
        })
    },
    // shamelessly stolen from Terraform
    // https://github.com/hashicorp/terraform/blob/f8669d235174ebdaf503d1cd400e22eb51c74c3b/internal/lang/functions.go
    Functions: map[string]function.Function{
        "abs":             stdlib.AbsoluteFunc,
        "can":             tryfunc.CanFunc,
        "ceil":            stdlib.CeilFunc,
        "chomp":           stdlib.ChompFunc,
        "coalescelist":    stdlib.CoalesceListFunc,
        "compact":         stdlib.CompactFunc,
        "concat":          stdlib.ConcatFunc,
        "contains":        stdlib.ContainsFunc,
        "csvdecode":       stdlib.CSVDecodeFunc,
        "distinct":        stdlib.DistinctFunc,
        "element":         stdlib.ElementFunc,
        "chunklist":       stdlib.ChunklistFunc,
        "flatten":         stdlib.FlattenFunc,
        "floor":           stdlib.FloorFunc,
        "format":          stdlib.FormatFunc,
        "formatdate":      stdlib.FormatDateFunc,
        "formatlist":      stdlib.FormatListFunc,
        "indent":          stdlib.IndentFunc,
        "join":            stdlib.JoinFunc,
        "jsondecode":      stdlib.JSONDecodeFunc,
        "jsonencode":      stdlib.JSONEncodeFunc,
        "keys":            stdlib.KeysFunc,
        "log":             stdlib.LogFunc,
        "lower":           stdlib.LowerFunc,
        "max":             stdlib.MaxFunc,
        "merge":           stdlib.MergeFunc,
        "min":             stdlib.MinFunc,
        "parseint":        stdlib.ParseIntFunc,
        "pow":             stdlib.PowFunc,
        "range":           stdlib.RangeFunc,
        "regex":           stdlib.RegexFunc,
        "regexall":        stdlib.RegexAllFunc,
        "reverse":         stdlib.ReverseListFunc,
        "setintersection": stdlib.SetIntersectionFunc,
        "setproduct":      stdlib.SetProductFunc,
        "setsubtract":     stdlib.SetSubtractFunc,
        "setunion":        stdlib.SetUnionFunc,
        "signum":          stdlib.SignumFunc,
        "slice":           stdlib.SliceFunc,
        "sort":            stdlib.SortFunc,
        "split":           stdlib.SplitFunc,
        "strrev":          stdlib.ReverseFunc,
        "substr":          stdlib.SubstrFunc,
        "timeadd":         stdlib.TimeAddFunc,
        "title":           stdlib.TitleFunc,
        "trim":            stdlib.TrimFunc,
        "trimprefix":      stdlib.TrimPrefixFunc,
        "trimspace":       stdlib.TrimSpaceFunc,
        "trimsuffix":      stdlib.TrimSuffixFunc,
        "try":             tryfunc.TryFunc,
        "upper":           stdlib.UpperFunc,
        "values":          stdlib.ValuesFunc,
        "zipmap":          stdlib.ZipmapFunc,
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant