-
Notifications
You must be signed in to change notification settings - Fork 75
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
Add validation of viz objects #554
Add validation of viz objects #554
Conversation
All contributors have signed the CLA ✍️ ✅ |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #554 +/- ##
=======================================
Coverage 94.87% 94.87%
=======================================
Files 35 35
Lines 2107 2107
=======================================
Hits 1999 1999
Misses 89 89
Partials 19 19 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure that test are also included with changes. This is important to ensure behaviour is kept between versions and error cases are correctly handled.
@@ -812,6 +813,16 @@ func getDashboardFilters(d *schema.ResourceData) []*dashboard.ChartsSingleFilter | |||
return filterList | |||
} | |||
|
|||
func dashboardValidate(ctx context.Context, dashboardObject *schema.ResourceDiff, config interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func dashboardValidate(ctx context.Context, dashboardObject *schema.ResourceDiff, config interface{}) error { | |
func dashboardValidate(ctx context.Context, dashboardObject *schema.ResourceDiff, config any) error { |
signalfx/util.go
Outdated
type ResourceDataAccess interface { | ||
Get(key string) interface{} | ||
GetOk(key string) (interface{}, bool) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to not add an interface within the utility file here, it will make it hard to maintain since it is somewhat hidden within the file of all the things that don't exactly fit within a resource object.
To be clear, the interface is fine but move it to a seperate file to make it easier to maintain and discover later on.
Moreover, Go doc style should take the form of:
// <Definition> ...
<Definition>
Please update to be reflect the go doc style.
signalfx/util.go
Outdated
return err | ||
} | ||
|
||
return config.(*signalfxConfig).Client.ValidateChart(ctx, payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to be conscious of is that if the type isn't the expected value, this code will panic, not expecting that it will but if it were to, it is a terrible user experience.
I would suggest looking at type checking here.
signalfx/util.go
Outdated
GetOk(key string) (interface{}, bool) | ||
} | ||
|
||
func chartValidate(ctx context.Context, chartResource *schema.ResourceDiff, config interface{}, getPayload func(ResourceDataAccess) (*chart.CreateUpdateChartRequest, error)) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it is more worthwhile to abstract this further instead of passing in placed type params.
Something like:
type ChartValidatorFunc func(input) (ChartRequest, error)
func (fn ChartValidatorFunc) Validate(ctx, resource, config) error {
if fn == nil {
return errors.New("no data parser provided")
}
payload, err := fn(resource)
if err != nil {
return err
}
return config.ValidateChart(ctx, payload)
}
This is something that the standard lib does with http.HandlerFunc
as a more concrete example.
I've added tests and implemented the suggested changes. Please let me know if there are any areas that need further improvement. |
Please make sure you sign the CLA. |
I have read the CLA Document and I hereby sign the CLA |
Adding validation for dashboards, dashboard groups and charts: terraform provider should fail on
plan
if the payload is faulty.