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

validate fields for property refs and produce config errors repoty #805

Merged
merged 3 commits into from
Dec 7, 2023

Conversation

jhsinger-klotho
Copy link
Contributor

  • Ensures each type validates that if set with a property ref, that ref is of the correct type and that refs value passes validation (if deploy time then it automatically passes if the correct type)

  • produces a config_errors.json for failed config

  • Going to add failure if the failed config matches something that was an input constraint

Standard checks

  • Unit tests: Any special considerations?
  • Docs: Do we need to update any docs, internal or public?
  • Backwards compatibility: Will this break existing apps? If so, what would be the extra work required to keep them working?

Copy link
Contributor

@gordon-klotho gordon-klotho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main blocking Q is the UI flow

Comment on lines 73 to 79
stringVal := `{
"resource": "%s",
"property": "%s",
"value": "%s",
"error": "%s"
}`
return []byte(fmt.Sprintf(stringVal, d.Resource, d.Property.Details().Path, d.Value, d.Error)), nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't do any escaping or anything. Might be safer to just return json.Marshal(map[string]any{ ... })

@@ -107,7 +109,10 @@ func (a *AnyProperty) Type() string {
return "any"
}

func (a *AnyProperty) Validate(resource *construct.Resource, value any) error {
func (a *AnyProperty) Validate(resource *construct.Resource, value any, ctx knowledgebase.DynamicContext) error {
if a.Required && value == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the infracopilot UI flow, it might not be possible to do required checks until we figure that out (unless that's something you're already doing). In other words, the resource has to be present to configure it in the UI, so if the validation fails on adding the resource, the user can't configure it to resolve that validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah validation can fail, but the engine wont fail unless its correlated with an incoming resource constraint. This prevents the user from dragging in a lambda and the engine failing, but still gives us the validation info for the images BaseImage so we can block clicking export IAC until all fields pass

Comment on lines +305 to +308
graph := construct.NewGraph()
for _, r := range tt.testResources {
graph.AddVertex(r)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Use graphtest and []any to make it easier (no tests use this atm though, so it doesn't matter). Same in a couple of the other tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its because i needed properties on my resources in some tests, cant remember which test this is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, right now i havent added the test for this, only for string and the isolated property ref tests, but it needs the entire resource because its going to trace back the property ref on the other resource to ensure the value of the field its referencing passes validation

return fmt.Errorf(knowledgebase.ErrRequiredProperty, f.Path, resource.ID)
}
return nil
}
floatVal, ok := value.(float64)
if !ok {
return fmt.Errorf("invalid int value %v", value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("invalid int value %v", value)
return fmt.Errorf("invalid float value %v", value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -12,6 +12,6 @@ resources:
parent: vpc/vpc-0

ecs_service/ecs_service_0 -> rds_instance/rds-instance-2:
path: aws:ecs_task_definition:ecs_service_0,aws:iam_role:ecs_service_0-rds-instance-2
path: aws:ecs_task_definition:ecs_service_0,aws:iam_role:ecs_service_0-execution-role
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 fixed the bug w/ path expand vertex dependencies so this gets set by the op rule instead of expansion

@jhsinger-klotho jhsinger-klotho merged commit 8e25773 into main Dec 7, 2023
6 checks passed
@jhsinger-klotho jhsinger-klotho deleted the config_errors branch December 7, 2023 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants