Skip to content

Storage: ProjectID Regex - #4543

Merged
chemelnucfin merged 2 commits into
googleapis:masterfrom
chemelnucfin:issue4447-projectregex
Dec 13, 2017
Merged

Storage: ProjectID Regex#4543
chemelnucfin merged 2 commits into
googleapis:masterfrom
chemelnucfin:issue4447-projectregex

Conversation

@chemelnucfin

@chemelnucfinchemelnucfin commented Dec 7, 2017

Copy link
Copy Markdown
Contributor

@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 7, 2017
@chemelnucfin

Copy link
Copy Markdown
ContributorAuthor

Hmm. it is locally 100%. Investigating

@chemelnucfinchemelnucfin added api: storage Issues related to the Cloud Storage API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Dec 7, 2017
@chemelnucfin

chemelnucfin commented Dec 7, 2017

Copy link
Copy Markdown
ContributorAuthor

Strange. Let's see if #4544 fixes it.


name = match.group('name')
project = match.group('project')
if project and len(project) > 30:

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


class TestProjectID(unittest.TestCase):

from google.cloud.storage import notification

This comment was marked as spam.

PROJECT = notification._PROJECT_PATTERN

def test_min_length_fail(self):
import re

This comment was marked as spam.


def test_leading_digit_fail(self):
import re
project = re.match(self.PROJECT, '1''a' * 5)

This comment was marked as spam.

This comment was marked as spam.

@chemelnucfin
chemelnucfinforce-pushed the issue4447-projectregex branch 3 times, most recently from a5a865b to 563bcc2CompareDecember 7, 2017 18:17

_TOPIC_REF_FMT = '//pubsub.googleapis.com/projects/{}/topics/{}'
_PROJECT_PATTERN = r'(?P<project>[a-z][a-z0-9-]{4,28}[a-z0-9])'
_PROJECT_PATTERN = r'(?P<project>\A[a-z][a-z0-9-]{4,28}[a-z0-9]\Z)'

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@chemelnucfin
chemelnucfinforce-pushed the issue4447-projectregex branch 3 times, most recently from 21ac69c to 1ae80fdCompareDecember 7, 2017 20:41
_TOPIC_NAME_PATTERN = r'(?P<name>[A-Za-z](\w|[-_.~+%])+)'
_TOPIC_REF_PATTERN = _TOPIC_REF_FMT.format(
_PROJECT_PATTERN, _TOPIC_NAME_PATTERN)
_PROJECT_PATTERN.replace(r'^', '').replace(r'$', ''),

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@dhermesdhermes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@chemelnucfin Let's make sure to get this merged tomorrow?

_TOPIC_NAME_PATTERN = r'(?P<name>[A-Za-z](\w|[-_.~+%])+)'
_TOPIC_REF_PATTERN = _TOPIC_REF_FMT.format(
_PROJECT_PATTERN, _TOPIC_NAME_PATTERN)
_PROJECT_PATTERN.replace(r'\A', '').replace(r'\Z', ''),

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

import mock


class TestProjectID(unittest.TestCase):

This comment was marked as spam.

pattern = notification._PROJECT_PATTERN
project = re.match(pattern, 'z0123456789\nmalicious', re.M)
self.assertIsNone(project)

This comment was marked as spam.

@dhermes
dhermesforce-pushed the issue4447-projectregex branch from 40335cf to 89e5c89CompareDecember 12, 2017 22:47
@googlebot

Copy link
Copy Markdown

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebotgooglebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Dec 12, 2017
@dhermes

Copy link
Copy Markdown
Contributor

@chemelnucfin I did a small re-factor to push this over the finish line.

Some things worth noting:

  • Setting self.TOPIC_REF in those test cases will leave lingering shared state, which we avoid as much as we can (at least in unit tests)
  • Since the number of from_api_repr tests overwhelmed the rest, I feel it is much easier to read by putting it in a standalone helper (note how much shorter each test case became)
  • We should probably use @pytest.mark.parametrize here, but that's for another day, another PR (I collapsed all of the "success" cases into one)

@chemelnucfin

Copy link
Copy Markdown
ContributorAuthor

@dhermes

  1. Hmm. I guess I was just using what was there before. My bad for not paying attention to assigning to self.TOPIC_REF

2, 3. ok. Sometimes I'm hesitant to refactor for fear of breaking things.

So is it ok to merge?

@dhermes

Copy link
Copy Markdown
Contributor

@chemelnucfin Yes go ahead and merge (make sure to squash).

chemelnucfinand others added 2 commits December 12, 2017 18:13
Made the regex check in `BucketNotification.from_api_repr`
into a standalone helper. This way all the tests can be in
"one place".
@chemelnucfin
chemelnucfin merged commit fd1b3fd into googleapis:masterDec 13, 2017
@chemelnucfin
chemelnucfin deleted the issue4447-projectregex branch December 13, 2017 03:50
@tseavertseaver mentioned this pull request Jan 10, 2018
parthea pushed a commit that referenced this pull request Mar 9, 2026
* Storage: ProjectID Regex from https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects#Project.FIELDS.project_id
* Re-factor as part of review process.
Made the regex check in `BucketNotification.from_api_repr`
into a standalone helper. This way all the tests can be in
"one place".
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storageIssues related to the Cloud Storage API.cla: noThis human has *not* signed the Contributor License Agreement.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@chemelnucfin@googlebot@dhermes@lukesneeringer