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

provider/aws: Add JSON validation to the aws_cloudwatch_event_rule resource. #8897

Conversation

kwilczynski
Copy link
Contributor

This commit adds support for new helper function which is used to
normalise and validate JSON string. Also adds new validation function
to wrap around the aforementioned helper.

Signed-off-by: Krzysztof Wilczynski krzysztof.wilczynski@linux.com

This commit adds support for new helper function which is used to
normalise and validate JSON string. Also adds new validation function
to wrap around the aforementioned helper.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
@kwilczynski
Copy link
Contributor Author

Part of work which began in #8028.

@kwilczynski kwilczynski changed the title Add JSON validation to the aws_cloudwatch_event_rule resource. provider/aws: Add JSON validation to the aws_cloudwatch_event_rule resource. Sep 17, 2016
@kwilczynski
Copy link
Contributor Author

kwilczynski commented Sep 17, 2016

Tests are passing:

(unit)

$ make test TEST=./builtin/providers/aws TESTARGS='-v -run=TestResourceAWSCloudWatchEventRule_validateEventPatternValue'
==> Checking that code complies with gofmt requirements...
==> Checking AWS provider for unchecked errors...
==> NOTE: at this time we only look for uncheck errors in the AWS package
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/09/14 22:40:23 Generated command/internal_plugin_list.go
TF_ACC= go test ./builtin/providers/aws -v -run=TestResourceAWSCloudWatchEventRule_validateEventPatternValue -timeout=30s -parallel=4
=== RUN   TestResourceAWSCloudWatchEventRule_validateEventPatternValue
--- PASS: TestResourceAWSCloudWatchEventRule_validateEventPatternValue (0.00s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    0.021s

(acceptance)

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCloudWatchEventRule'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/09/14 19:36:21 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCloudWatchEventRule -timeout 120m
=== RUN   TestAccAWSCloudWatchEventRule_importBasic
--- PASS: TestAccAWSCloudWatchEventRule_importBasic (15.01s)
=== RUN   TestAccAWSCloudWatchEventRule_basic
--- PASS: TestAccAWSCloudWatchEventRule_basic (25.89s)
=== RUN   TestAccAWSCloudWatchEventRule_full
--- PASS: TestAccAWSCloudWatchEventRule_full (15.08s)
=== RUN   TestAccAWSCloudWatchEventRule_enable
--- PASS: TestAccAWSCloudWatchEventRule_enable (37.42s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    93.441s

}
if _, err := normalizeJsonString(value); err != nil {
errors = append(errors, fmt.Errorf("%q contains an invalid JSON: %s", k, err))
}
Copy link
Member

@radeksimko radeksimko Sep 18, 2016

Choose a reason for hiding this comment

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

We send the minified (normalized) JSON to the API which is the one that is limited to 2048 characters, not the original JSON string with spaces, newlines etc.

At this point we would prevent the user from sending minified JSON to the API which can be below 2048 chars after stripping whitespaces etc. Also I'm not sure if there is any point in checking length of invalid JSON.

It may be worth covering this particular edge case by a test.

@radeksimko
Copy link
Member

I'm happy to merge this once the mentioned edge case w/ normalization & length check is addressed - this otherwise looks good.

@radeksimko radeksimko added the waiting-response An issue/pull request is waiting for a response from the community label Sep 18, 2016
@kwilczynski
Copy link
Contributor Author

@radeksimko ah, that is a very good point! I will fix this right away.

This commit changes the logic of the function so that it would check length of
the normalised JSON string over the given string, plus short-circuit early
should JSON would not be valid.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
@kwilczynski
Copy link
Contributor Author

kwilczynski commented Sep 18, 2016

Unit test is passing:

$ make test TEST=./builtin/providers/aws TESTARGS='-v -run=TestResourceAWSCloudWatchEventRule_validateEventPatternValue'
==> Checking that code complies with gofmt requirements...
==> Checking AWS provider for unchecked errors...
==> NOTE: at this time we only look for uncheck errors in the AWS package
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/09/18 15:05:26 Generated command/internal_plugin_list.go
TF_ACC= go test ./builtin/providers/aws -v -run=TestResourceAWSCloudWatchEventRule_validateEventPatternValue -timeout=30s -parallel=4
=== RUN   TestResourceAWSCloudWatchEventRule_validateEventPatternValue
--- PASS: TestResourceAWSCloudWatchEventRule_validateEventPatternValue (0.00s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    0.015s

@kwilczynski
Copy link
Contributor Author

@radeksimko I have updated the ValidateFunc, it should do the right thing now. Thank you!

@radeksimko radeksimko removed the waiting-response An issue/pull request is waiting for a response from the community label Sep 19, 2016
@radeksimko radeksimko merged commit 9ef9956 into hashicorp:master Sep 19, 2016
@ghost
Copy link

ghost commented Apr 22, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants