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

fix: fix resource path args for paths with =** #1089

Merged
merged 3 commits into from Nov 18, 2021

Conversation

busunkim96
Copy link
Contributor

@busunkim96 busunkim96 commented Nov 17, 2021

Some resources have =** in the segment. . A segment with =** is not matched by the current regex:

Python 3.9.5 (default, Jul 27 2021, 22:06:04) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> pattern = re.compile(r"\{([a-zA-Z0-9_-]+)\}")
>>> pattern.search("projects/{project}/metricDescriptors/{metric_descriptor=**}").groups()
('project',)

This pattern shows up in the some real APIs (monitoring protos, google/cloud/iap/v1, google/cloud/iap/v1beta1, google/cloud/recommendationengine/v1beta1, google/devtools/remoteworkers/v1test2, google/home/graph/v1, google/iam/v1). ** is mentioned in passing in Resource Names. I was not able to find an explanation of what wildcards are considered valid in https://google.aip.dev/122 or https://google.aip.dev/client-libraries/4231.

Monitoring Proto Example:

option (google.api.resource_definition) = {
  type: "monitoring.googleapis.com/MetricDescriptor"
  pattern: "projects/{project}/metricDescriptors/{metric_descriptor=**}"
  pattern: "organizations/{organization}/metricDescriptors/{metric_descriptor=**}"
  pattern: "folders/{folder}/metricDescriptors/{metric_descriptor=**}"
  pattern: "*"
  history: ORIGINALLY_SINGLE_PATTERN
};

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 17, 2021
@busunkim96 busunkim96 changed the title fix(snippetgen): fix resource path args for paths with =** fix: fix resource path args for paths with =** Nov 17, 2021
@busunkim96 busunkim96 marked this pull request as ready for review November 17, 2021 16:26
@busunkim96 busunkim96 requested review from a team as code owners November 17, 2021 16:26
@@ -110,7 +110,7 @@ class TransformedRequest:

# Resource patterns look something like
# kingdom/{kingdom}/phylum/{phylum}/class/{class}
RESOURCE_RE = re.compile(r"\{([^}/]+)\}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This regex seemed to be serving the same purpose as the one in wrappers.py

@busunkim96 busunkim96 added the automerge Merge the pull request once unit tests and other checks pass. label Nov 18, 2021
@busunkim96 busunkim96 removed the automerge Merge the pull request once unit tests and other checks pass. label Nov 18, 2021
@busunkim96 busunkim96 added the automerge Merge the pull request once unit tests and other checks pass. label Nov 18, 2021
@gcf-merge-on-green gcf-merge-on-green bot merged commit 309cc66 into master Nov 18, 2021
@gcf-merge-on-green gcf-merge-on-green bot deleted the fix-snippetgen-resource-pattern branch November 18, 2021 18:34
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Nov 18, 2021
gcf-merge-on-green bot pushed a commit that referenced this pull request Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants