def Filter(self, context, args): del context, args # Intentionally disable the user project override. Cloud Shell is inteded # to be able to be used without first creating a GCP project. # Additionally, Cloud Shell is a free product with per user quota, so # enabling the API on gcloud will not cost gcloud money. base.DisableUserProjectQuota()
def Filter(self, unused_tool_context, args): base.DisableUserProjectQuota() if config.INSTALLATION_CONFIG.IsAlternateReleaseChannel(): log.warning('You are using alternate release channel: [%s]', config.INSTALLATION_CONFIG.release_channel) # Always show the URL if using a non standard release channel. log.warning('Snapshot URL for this release channel is: [%s]', config.INSTALLATION_CONFIG.snapshot_url)
def Run(self, args): """Allows user to select configuration, and initialize it.""" if args.obsolete_project_arg: raise c_exc.InvalidArgumentException( args.obsolete_project_arg, '`gcloud init` has changed and no longer takes a PROJECT argument. ' 'Please use `gcloud source repos clone` to clone this ' 'project\'s source repositories.') log.status.write('Welcome! This command will take you through ' 'the configuration of gcloud.\n\n') if properties.VALUES.core.disable_prompts.GetBool(): raise c_exc.InvalidArgumentException( 'disable_prompts/--quiet', 'gcloud init command cannot run with disabled prompts.') configuration_name = self._PickConfiguration() if not configuration_name: return log.status.write( 'Your current configuration has been set to: [{0}]\n\n'.format( configuration_name)) if not args.skip_diagnostics: log.status.write('You can skip diagnostics next time by using the ' 'following flag:\n') log.status.write(' gcloud init --skip-diagnostics\n\n') network_passed = network_diagnostics.NetworkDiagnostic().RunChecks( ) if not network_passed: if not console_io.PromptContinue( message='Network errors detected.', prompt_string='Would you like to continue anyway', default=False): log.status.write( 'You can re-run diagnostics with the following ' 'command:\n') log.status.write(' gcloud info --run-diagnostics\n\n') return # User project quota is now the global default, but this command calls # legacy APIs where it should be disabled. It must happen after the config # settings are persisted so this temporary value doesn't get persisted as # well. base.DisableUserProjectQuota() if not self._PickAccount(args.console_only, preselected=args.account): return if not self._PickProject(preselected=args.project): return self._PickDefaultRegionAndZone() self._CreateBotoConfig() self._Summarize(configuration_name)
def Filter(self, context, args): # TODO(b/190528585): Determine if command group works with project number base.RequireProjectID(args) del context, args # Intentionally disable the user project override. Cloud Shell is inteded # to be able to be used without first creating a GCP project. # Additionally, Cloud Shell is a free product with per user quota, so # enabling the API on gcloud will not cost gcloud money. base.DisableUserProjectQuota()
def Filter(self, context, args): """Initialize context for source commands. Args: context: The current context. args: The argparse namespace that was specified on the CLI or API. Returns: The updated context. """ base.DisableUserProjectQuota()
def Filter(self, context, args): """Initialize context for source commands. Args: context: The current context. args: The argparse namespace that was specified on the CLI or API. Returns: The updated context. """ # TODO(b/190539713): Determine if command group works with project number base.RequireProjectID(args) base.DisableUserProjectQuota()
def Run(self, args): """Executes the given docker command, after refreshing our credentials. Args: args: An argparse.Namespace that contains the values for the arguments specified in the .Args() method. Raises: exceptions.ExitCodeNoError: The docker command execution failed. """ if args.account: # Since the docker binary invokes `gcloud auth docker-helper` through # `docker-credential-gcloud`, it cannot forward the command line # arguments. Subsequently, we are unable to set the account (or any # flag for that matter) used by `docker-credential-gcloud` with # the global `--account` flag. log.warning('Docker uses the account from the gcloud config.' 'To set the account in the gcloud config, run ' '`gcloud config set account <account_name>`.') base.DisableUserProjectQuota() force_refresh = True for server in args.server: if server not in _DEFAULT_REGISTRIES: log.warning( 'Authenticating to a non-default server: {server}.'.format( server=server)) docker.UpdateDockerCredentials(server, refresh=force_refresh) # Only force a refresh for the first server we authorize force_refresh = False if args.authorize_only: # NOTE: We don't know at this point how long the access token we have # placed in the docker configuration will last. More information needs # to be exposed from all credential kinds in order for us to have an # accurate awareness of lifetime here. log.err.Print('Short-lived access for {server} configured.'.format( server=args.server)) return docker_args = args.docker_args or [] docker_args = (docker_args if not args.docker_host else ['-H', args.docker_host] + docker_args) result = docker_client_utils.Execute(docker_args) # Explicitly avoid displaying an error message that might # distract from the docker error message already displayed. if result: raise exceptions.ExitCodeNoError(exit_code=result) return
def Filter(self, context, args): """Modify the context that will be given to this group's commands when run. Args: context: {str:object}, A set of key-value pairs that can be used for common initialization among commands. args: argparse.Namespace: The same namespace given to the corresponding .Run() invocation. Returns: The refined command context. """ base.DisableUserProjectQuota() context['api_adapter'] = api_adapter.NewAPIAdapter('v1alpha1') return context
def Filter(self, context, args): del context, args base.DisableUserProjectQuota() if self.ReleaseTrack() == base.ReleaseTrack.GA: if not properties.VALUES.dataproc.region.Get(): log.warning( 'Dataproc --region flag will become required in January 2020. ' 'Please either specify this flag, or set default by running ' '\'gcloud config set dataproc/region <your-default-region>\'' ) properties.VALUES.dataproc.region.Set('global') else: # Enfore flag or default value is required. properties.VALUES.dataproc.region.GetOrFail()
def Filter(self, context, args): del context base.DisableUserProjectQuota() if hasattr(args, 'region') and not args.region: if self.ReleaseTrack() == base.ReleaseTrack.GA: if not properties.VALUES.dataproc.region.Get(): log.warning( 'Specifying a Cloud Dataproc region will become required in ' 'January 2020. Please either specify --region=<your-region>, or ' 'set a default Cloud Dataproc region by running ' '\'gcloud config set dataproc/region <your-default-region>\'' ) properties.VALUES.dataproc.region.Set('global') else: # Enfore flag or default value is required. properties.VALUES.dataproc.region.GetOrFail()
def Filter(self, context, args): """Context() is a filter function that can update the context. Args: context: The current context. args: The argparse namespace that was specified on the CLI or API. Returns: The updated context. """ base.DisableUserProjectQuota() context['servicemanagement-v1'] = apis.GetClientInstance( 'servicemanagement', 'v1') context['servicemanagement-v1-messages'] = apis.GetMessagesModule( 'servicemanagement', 'v1') return context
def Filter(self, context, args): """Modify the context that will be given to this group's commands when run. Args: context: The current context. args: The argparse namespace given to the corresponding .Run() invocation. Returns: The updated context. """ base.DisableUserProjectQuota() context['clouderrorreporting_client_v1beta1'] = apis.GetClientInstance( 'clouderrorreporting', 'v1beta1') context[ 'clouderrorreporting_messages_v1beta1'] = apis.GetMessagesModule( 'clouderrorreporting', 'v1beta1') context['clouderrorreporting_resources'] = resources return context
def Filter(self, context, args): """Modify the context that will be given to this group's commands when run. Args: context: {str:object}, A set of key-value pairs that can be used for common initialization among commands. args: argparse.Namespace: The same namespace given to the corresponding .Run() invocation. Returns: The refined command context. """ base.DisableUserProjectQuota() if container_command_util.GetUseV1APIProperty(): api_version = 'v1' else: api_version = 'v1beta1' context['api_adapter'] = api_adapter.NewAPIAdapter(api_version) return context
def Filter(self, context, args): """Context() is a filter function that can update the context. Args: context: The current context. args: The argparse namespace that was specified on the CLI or API. Returns: The updated context. """ # Don't ever take this off. Use gcloud quota so that you can enable APIs # on your own project before you have API access on that project. base.DisableUserProjectQuota() context['servicemanagement-v1'] = apis.GetClientInstance( 'servicemanagement', 'v1') context['servicemanagement-v1-messages'] = apis.GetMessagesModule( 'servicemanagement', 'v1') return context
def Filter(self, context, args): """Context() is a filter function that can update the context. Args: context: The current context. args: The argparse namespace that was specified on the CLI or API. Returns: The updated context. """ # TODO(b/190533981): Determine if command group works with project number base.RequireProjectID(args) base.DisableUserProjectQuota() context['servicemanagement-v1'] = apis.GetClientInstance( 'servicemanagement', 'v1') context['servicemanagement-v1-messages'] = apis.GetMessagesModule( 'servicemanagement', 'v1') return context
def Filter(self, context, args): """Modify the context that will be given to this group's commands when run. Args: context: {str:object}, A set of key-value pairs that can be used for common initialization among commands. args: argparse.Namespace: The same namespace given to the corresponding .Run() invocation. Returns: The refined command context. """ # The Composer API performs quota checking based on the resource project, so # user project overrides are not needed. The 'environments run' command # spawns a call to the Kubernetes Engine API, and the 'container' command # group also disables user project quota; removing this line will break # 'composer environments run.' base.DisableUserProjectQuota() return context
def Run(self, args): """Executes the given docker command, after refreshing our credentials. Args: args: An argparse.Namespace that contains the values for the arguments specified in the .Args() method. Raises: exceptions.ExitCodeNoError: The docker command execution failed. """ base.DisableUserProjectQuota() force_refresh = True for server in args.server: if server not in _DEFAULT_REGISTRIES: log.warning( 'Authenticating to a non-default server: {server}.'.format( server=server)) docker.UpdateDockerCredentials(server, refresh=force_refresh) # Only force a refresh for the first server we authorize force_refresh = False if args.authorize_only: # NOTE: We don't know at this point how long the access token we have # placed in the docker configuration will last. More information needs # to be exposed from all credential kinds in order for us to have an # accurate awareness of lifetime here. log.err.Print('Short-lived access for {server} configured.'.format( server=args.server)) return docker_args = args.docker_args or [] docker_args = (docker_args if not args.docker_host else ['-H', args.docker_host] + docker_args) result = docker_client_utils.Execute(docker_args) # Explicitly avoid displaying an error message that might # distract from the docker error message already displayed. if result: raise exceptions.ExitCodeNoError(exit_code=result) return
def _WarnIfSettingProjectWithNoAccess(scope, project): """Warn if setting 'core/project' config to inaccessible project.""" # Only display a warning if the following conditions are true: # # * The current scope is USER (not occurring in the context of installation). # * The 'core/account' value is set (a user has authed). # # If the above conditions are met, check that the project being set exists # and is accessible to the current user, otherwise show a warning. if (scope == properties.Scope.USER and properties.VALUES.core.account.Get()): project_ref = command_lib_util.ParseProject(project) base.DisableUserProjectQuota() try: projects_api.Get(project_ref) except (apitools_exceptions.HttpError, c_store.NoCredentialsForAccountException): log.warning('You do not appear to have access to project [{}] or' ' it does not exist.'.format(project)) finally: base.EnableUserProjectQuota()
def Filter(self, context, args): # TODO(b/190524392): Determine if command group works with project number base.RequireProjectID(args) del context, args base.DisableUserProjectQuota() resources.REGISTRY.RegisterApiByName('apigateway', 'v1')
def Filter(self, context, args): del context, args base.DisableUserProjectQuota()
def Filter(self, context, args): # TODO(b/190534642): Determine if command group works with project number base.RequireProjectID(args) del context, args base.DisableUserProjectQuota()
def Filter(self, context, args): del context, args base.DisableUserProjectQuota() base.OptOutRequests( ) # TODO(b/168048260): Remove to migrate to requests.
def Filter(self, context, args): del context, args # Don't ever take this off. Use gcloud quota for projects operations so # you can create a project before you have a project. base.DisableUserProjectQuota()
def Filter(self, context, args): del context, args base.DisableUserProjectQuota() base.OptInRequests() resources.REGISTRY.RegisterApiByName('ml', 'v1')
def Filter(self, context, args): del context, args base.DisableUserProjectQuota() log.warning( 'The Dataflow Alpha CLI is now deprecated and will soon be ' 'removed. Please use the new `gcloud beta dataflow` commands.')
def Filter(self, context, args): del context, args base.DisableUserProjectQuota() base.OptInRequests()
def Filter(self, context, args): # TODO(b/190524958): Determine if command group works with project number base.RequireProjectID(args) del context, args base.DisableUserProjectQuota() base.OptOutRequests() # TODO(b/168048260): Remove to migrate to requests.
def Filter(self, context, args): del context, args # Don't ever take this off. Use gcloud quota so that you can enable APIs # on your own project before you have API access on that project. base.DisableUserProjectQuota()
def Filter(self, context, args): base.DisableUserProjectQuota() context['iam-client'] = apis.GetClientInstance('iam', 'v1') context['iam-messages'] = apis.GetMessagesModule('iam', 'v1') context['iam-resources'] = resources
def Filter(self, context, args): del context, args base.DisableUserProjectQuota() resources.REGISTRY.RegisterApiByName('apigateway', 'v1alpha1')