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

Add back requireds on stripquery #3443

Merged
merged 5 commits into from
May 1, 2020

Conversation

slevenick
Copy link
Contributor

Reverts changes from #3378 to prevent empty blocks from being valid.

Adds required to the same field that was added in a duplicate object in #3379

This should be cherry-picked into 3.20.0

Release Note Template for Downstream PRs (will be copied)


@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 4 files changed, 54 insertions(+), 60 deletions(-))
Terraform Beta: Diff ( 4 files changed, 54 insertions(+), 60 deletions(-))
Ansible: Diff ( 4 files changed, 41 insertions(+), 42 deletions(-))

@@ -9452,11 +9452,11 @@ objects:
- :TEMPORARY_REDIRECT
- !ruby/object:Api::Type::Boolean
name: 'stripQuery'
default_value: false
required: true
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be 8 occurrences of stripQuery in total:

  • pathMatchers.routeRules.urlRedirect.stripQuery
  • pathMatchers.pathRules.urlRedirect.stripQuery
  • pathMatchers.pathRules.defaultUrlRedirect.stripQuery
  • defaultUrlRedirect.stripQuery

And these for both for RegionUrlMap and UrlMap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are, but two of them were not marked as required before. Marking them as required would be a breaking change that can't happen on a minor version

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. But then it should be noted somewhere, that these two blocks where the non-required stripQuery properties appear exhibit the "empty block" problem that @danawillow pointed out.

@slevenick slevenick requested a review from danawillow April 30, 2020 15:27
@slevenick slevenick force-pushed the stripQuery-required branch from 375fb90 to bcc53f2 Compare April 30, 2020 16:14
@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 4 files changed, 54 insertions(+), 60 deletions(-))
Terraform Beta: Diff ( 4 files changed, 54 insertions(+), 60 deletions(-))
Ansible: Diff ( 4 files changed, 41 insertions(+), 42 deletions(-))

description: |
If set to true, any accompanying query portion of the original URL is removed
prior to redirecting the request. If set to false, the query portion of the
original URL is retained.
original URL is retained. The default value is false.
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is required, it can't have a default

(here and elsewhere)

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 was going for saying the default so that people who don't want to specify this field but are required to have an idea of what the default normally is. But can remove

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion, but my guess is it would be more confusing to specify it. @ctavan, what do you think?

Copy link
Contributor

@ctavan ctavan Apr 30, 2020

Choose a reason for hiding this comment

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

I just played a bit with the API explorer at https://cloud.google.com/compute/docs/reference/rest/v1/urlMaps/insert

The API does not accept empty defaultUrlRedirect objects, I assume the same is true for the urlRedirect blocks although I didn't double check.

If I try to insert a new urlMap with these contents:

{
  "name": "empty-url-map",
  "defaultUrlRedirect": {}
}

I get an error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid value for field 'resource.defaultUrlRedirect': ''. No fields set for UrlRedirect"
   }
  ],
  "code": 400,
  "message": "Invalid value for field 'resource.defaultUrlRedirect': ''. No fields set for UrlRedirect"
 }
}

As soon as I set any field the insert works, e.g.:

{
  "name": "empty-url-map",
  "defaultUrlRedirect": {
    "hostRedirect": "example.com"
  }
}

I believe instead of making an arbitrary field mandatory I suggest that the correct way of handling this would be to specify

at_least_one_of:
  - host_redirect
  - path_redirect
  - prefix_redirect
  - redirect_response_code
  - https_redirect
  - strip_query

for all urlRedirect/defaultUrlRedirect blocks.

This should also be backwards-compatible for people who did specify strip_query and it should also be "forward compatible" with those blocks that currently don't specify mandatory stripQuery fields because empty blocks are not accepted by the compute API anyways.

WDYT?

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, that sounds reasonable.

Copy link
Contributor Author

@slevenick slevenick Apr 30, 2020

Choose a reason for hiding this comment

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

Ah, unfortunately because these fields are nested within lists we cannot enforce at_least_one_of on them at this point.

We would definitely like to be able to enforce at_least_one_of on nested objects within lists, but the current implementation does not support this

@@ -9871,11 +9871,11 @@ objects:
- :TEMPORARY_REDIRECT
- !ruby/object:Api::Type::Boolean
name: 'stripQuery'
default_value: false
required: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Idea: does it make sense to do these as overrides in terraform.yaml instead? I don't think inspec/ansible have the same constraints around non-empty blocks, and so putting it there would make it easier to call out why we're doing this (we could group them all together more easily)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. Do you think it is a good idea to explicitly say in the description "This is only required to ensure we do not allow an empty block in a terraform config"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure!

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 4 files changed, 74 insertions(+), 62 deletions(-))
Terraform Beta: Diff ( 4 files changed, 74 insertions(+), 62 deletions(-))
Ansible: Diff ( 4 files changed, 26 insertions(+), 29 deletions(-))
Inspec: Diff ( 1 file changed, 1 insertion(+), 1 deletion(-))

@slevenick slevenick force-pushed the stripQuery-required branch from 180880f to 8cb10e7 Compare April 30, 2020 19:34
@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 4 files changed, 74 insertions(+), 62 deletions(-))
Terraform Beta: Diff ( 4 files changed, 74 insertions(+), 62 deletions(-))
Ansible: Diff ( 4 files changed, 26 insertions(+), 29 deletions(-))
Inspec: Diff ( 1 file changed, 1 insertion(+), 1 deletion(-))

@slevenick slevenick force-pushed the stripQuery-required branch from 8cb10e7 to ed03897 Compare April 30, 2020 22:43
@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 4 files changed, 67 insertions(+), 61 deletions(-))
Terraform Beta: Diff ( 4 files changed, 67 insertions(+), 61 deletions(-))
Ansible: Diff ( 4 files changed, 23 insertions(+), 31 deletions(-))
Inspec: Diff ( 1 file changed, 1 insertion(+), 1 deletion(-))

@slevenick slevenick requested a review from danawillow April 30, 2020 22:55
@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 4 files changed, 66 insertions(+), 60 deletions(-))
Terraform Beta: Diff ( 4 files changed, 66 insertions(+), 60 deletions(-))
Ansible: Diff ( 4 files changed, 17 insertions(+), 28 deletions(-))
Inspec: Diff ( 1 file changed, 1 insertion(+), 1 deletion(-))

@@ -14437,11 +14434,10 @@ objects:
- :TEMPORARY_REDIRECT
- !ruby/object:Api::Type::Boolean
name: 'stripQuery'
default_value: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add these back so that ansible still has them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not?

If we have a default value specified in api.yaml we cannot override it with a nil value that I know of

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, but I can add them to ansible.yaml

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 4 files changed, 66 insertions(+), 60 deletions(-))
Terraform Beta: Diff ( 4 files changed, 66 insertions(+), 60 deletions(-))
Ansible: Diff ( 4 files changed, 17 insertions(+), 22 deletions(-))
Inspec: Diff ( 1 file changed, 1 insertion(+), 1 deletion(-))

@slevenick slevenick merged commit 29d82f2 into GoogleCloudPlatform:master May 1, 2020
nathkn pushed a commit to nathkn/magic-modules that referenced this pull request May 18, 2020
* Add back requireds on stripquery

* Move required to terraform.yaml, add description on empty blocks'

* Fixed to preserve backwards compatibility

* Remove last default in description

* Default back to false in ansible urlmaps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants