Пример #1
0
    def __init__(self):
        super(_SectionCore, self).__init__('core')
        self.account = self._Add(
            'account', callbacks=[c_devshell.DefaultAccount, _GetGCEAccount])
        self.disable_color = self._Add('disable_color')
        self.disable_command_lazy_loading = self._Add(
            'disable_command_lazy_loading', hidden=True)
        self.disable_prompts = self._Add('disable_prompts')
        self.disable_usage_reporting = self._Add('disable_usage_reporting')
        self.api_host = self._Add(
            'api_host',
            hidden=True,
            callbacks=[lambda: 'https://www.googleapis.com'])
        self.verbosity = self._Add('verbosity')
        self.user_output_enabled = self._Add('user_output_enabled')
        self.log_http = self._Add('log_http')
        self.check_gce_metadata = self._Add('check_gce_metadata',
                                            hidden=True,
                                            callbacks=[lambda: True])

        def ProjectValidator(project):
            """Checks to see if the project string is valid."""
            if project is None:
                return
            if _VALID_PROJECT_REGEX.match(project):
                return

            if not isinstance(project, basestring):
                raise InvalidValueError('project must be a string')
            if project == '':  # pylint: disable=g-explicit-bool-comparison
                raise InvalidProjectError('The project property is set to the '
                                          'empty string, which is invalid.')
            if project.isdigit():
                raise InvalidProjectError(
                    'The project property must be set to a valid project ID, not the '
                    'project number [{value}]'.format(value=project))
            if _LooksLikeAProjectName(project):
                raise InvalidProjectError(
                    'The project property must be set to a valid project ID, not the '
                    'project name [{value}]'.format(value=project))
            # Non heuristics for a better error message.
            raise InvalidProjectError(
                'The project property must be set to a valid project ID, '
                '[{value}] is not a valid project ID.'.format(value=project))

        # pylint: disable=unnecessary-lambda, We don't want to call Metadata()
        # unless we really have to.
        self.project = self._Add(
            'project',
            validator=ProjectValidator,
            callbacks=[lambda: c_devshell.Project(), _GetGCEProject])
        self.credentialed_hosted_repo_domains = self._Add(
            'credentialed_hosted_repo_domains')
Пример #2
0
    def __init__(self):
        super(_SectionCore, self).__init__('core')
        # pylint: disable=unnecessary-lambda, We don't want to call Metadata()
        # unless we really have to.
        self.account = self._Add(
            'account',
            callbacks=[lambda: c_devshell.DefaultAccount(), _GetGCEAccount])
        self.disable_color = self._Add('disable_color')
        self.disable_command_lazy_loading = self._Add(
            'disable_command_lazy_loading', hidden=True)
        self.disable_prompts = self._Add('disable_prompts')
        self.disable_usage_reporting = self._Add('disable_usage_reporting')
        # pylint: disable=unnecessary-lambda, Just a value return.
        self.api_host = self._Add(
            'api_host',
            hidden=True,
            callbacks=[lambda: 'https://www.googleapis.com'])
        self.verbosity = self._Add('verbosity')
        self.user_output_enabled = self._Add('user_output_enabled')
        self.check_gce_metadata = self._Add('check_gce_metadata',
                                            hidden=True,
                                            callbacks=[lambda: True])

        def ProjectValidator(project):
            """Checks to see if the project string is valid."""
            if project is None:
                return
            if not isinstance(project, basestring):
                raise InvalidValueError('project must be a string')
            if project == '':  # pylint: disable=g-explicit-bool-comparison
                raise InvalidValueError("""\
The project property is set to the empty string, which is invalid.
To set your project, run:

  $ gcloud config set project PROJECT_ID

or to unset it, run:

  $ gcloud config unset project""")
            if project.isdigit():
                raise InvalidValueError(
                    'The project property must be set to a valid project ID, not the '
                    'project number [{value}]'.format(value=project))

        # pylint: disable=unnecessary-lambda, We don't want to call Metadata()
        # unless we really have to.
        self.project = self._Add(
            'project',
            validator=ProjectValidator,
            callbacks=[lambda: c_devshell.Project(), _GetGCEProject])
        self.credentialed_hosted_repo_domains = self._Add(
            'credentialed_hosted_repo_domains')
Пример #3
0
    def __init__(self):
        super(_SectionCore, self).__init__('core')
        # pylint: disable=unnecessary-lambda, We don't want to call Metadata()
        # unless we really have to.
        self.account = self._Add('account',
                                 callbacks=[
                                     lambda: c_devshell.DefaultAccount(),
                                     lambda: c_gce.Metadata().DefaultAccount()
                                 ])
        self.disable_color = self._Add('disable_color')
        self.disable_command_lazy_loading = self._Add(
            'disable_command_lazy_loading', hidden=True)
        self.disable_prompts = self._Add('disable_prompts')
        self.disable_usage_reporting = self._Add('disable_usage_reporting')
        # pylint: disable=unnecessary-lambda, Just a value return.
        self.api_host = self._Add(
            'api_host',
            hidden=True,
            callbacks=[lambda: 'https://www.googleapis.com'])
        self.verbosity = self._Add('verbosity')
        self.user_output_enabled = self._Add('user_output_enabled')

        def ProjectValidator(project):
            if not project:
                return
            if not isinstance(project, basestring):
                raise InvalidValueError('project must be a string')
            if project.isdigit():
                raise InvalidValueError(
                    'project must be the project ID, not the project number')

        # pylint: disable=unnecessary-lambda, We don't want to call Metadata()
        # unless we really have to.
        self.project = self._Add('project',
                                 validator=ProjectValidator,
                                 callbacks=[
                                     lambda: c_devshell.Project(),
                                     lambda: c_gce.Metadata().Project()
                                 ])
        self.credentialed_hosted_repo_domains = self._Add(
            'credentialed_hosted_repo_domains')
Пример #4
0
 def GetProject(self):
     return c_devshell.Project()