def DisplayProposedConfigDeployments(project, configs): """Prints the details of the proposed config deployments. Args: project: The name of the current project. configs: [yaml_parsing.ConfigYamlInfo], The configurations being deployed. """ log.status.Print('Configurations to update:\n') for c in configs: log.status.Print( DEPLOY_CONFIG_MESSAGE_TEMPLATE.format(project=project, type=CONFIG_TYPES[c.config], descriptor=c.file)) if c.name == yaml_parsing.ConfigYamlInfo.QUEUE: # If useful, this logic can be broken out and moved to enable_api.py, # under IsServiceMaybeEnabled(...) or similar. try: api_maybe_enabled = enable_api.IsServiceEnabled( project, 'cloudtasks.googleapis.com') except sm_exceptions.ListServicesPermissionDeniedException: api_maybe_enabled = True # We can't know, so presume it is enabled if api_maybe_enabled: # Display this warning with a false positive rate for when the Service # Manangement API is not enabled or accessible. log.warn(QUEUE_TASKS_WARNING)
def Run(self, args): """Create a GCP repository to the current directory. Args: args: argparse.Namespace, the arguments this command is run with. Returns: (sourcerepo_v1_messages.Repo) The created respository. Raises: ToolException: on project initialization errors, on missing billing account, and when the repo name is already in use. """ project_id = resolvers.FromProperty(properties.VALUES.core.project) res = resources.REGISTRY.Parse( args.name, params={'projectsId': project_id}, collection='sourcerepo.projects.repos') # check that the name does not have forbidden characters. # we'd like to do this by putting the validator in the flag type, but # we cannot for now because it needs to work on the parsed name. flags.REPO_NAME_VALIDATOR(res.Name()) source_handler = sourcerepo.Source() # This service enabled check can be removed when cl/148491846 is ready if not enable_api.IsServiceEnabled(res.projectsId, _SOURCEREPO_SERVICE_NAME): message = ('{api} is required for repository creation and is not ' 'enabled.'.format(api=_SOURCEREPO_SERVICE_NAME)) if console_io.PromptContinue( message=message, prompt_string='Would you like to enable it?', default=True): operation = enable_api.EnableServiceApiCall(res.projectsId, _SOURCEREPO_SERVICE_NAME) # wait for the operation to complete, will raise an exception if the # operation fails. services_util.ProcessOperationResult(operation, async=False) else: error_message = ('Cannot create a repository without enabling ' '{api}'.format(api=_SOURCEREPO_SERVICE_NAME)) raise exceptions.Error(error_message) try: repo = source_handler.CreateRepo(res) if repo: log.CreatedResource(res.Name()) log.Print('You may be billed for this repository. ' 'See {url} for details.'.format(url=_BILLING_URL)) return repo except exceptions.HttpError as error: exc = c_exc.HttpException(error) exc.error_format = _ERROR_FORMAT raise exc
def DisplayProposedConfigDeployments(project, configs): """Prints the details of the proposed config deployments. Args: project: The name of the current project. configs: [yaml_parsing.ConfigYamlInfo], The configurations being deployed. """ log.status.Print('Configurations to update:\n') for c in configs: log.status.Print( DEPLOY_CONFIG_MESSAGE_TEMPLATE.format(project=project, type=CONFIG_TYPES[c.config], descriptor=c.file)) if (c.name == yaml_parsing.ConfigYamlInfo.QUEUE and enable_api.IsServiceEnabled(project, 'cloudtasks.googleapis.com')): log.warn(QUEUE_TASKS_WARNING)