def DisplayProposedDeployment(app, project, app_config, version, promote): """Prints the details of the proposed deployment. Args: app: Application resource for the current application (required if any services are deployed, otherwise ignored). project: The name of the current project. app_config: yaml_parsing.AppConfigSet, The configurations being deployed. version: The version identifier of the application to be deployed. promote: Whether the newly deployed version will receive all traffic (this affects deployed URLs). Returns: dict (str->str), a mapping of service names to deployed service URLs This includes information on to-be-deployed services (including service name, version number, and deployed URLs) as well as configurations. """ deployed_urls = {} if app_config.Services(): if app is None: raise TypeError( 'If services are deployed, must provide `app` parameter.') deploy_messages = [] for service, info in app_config.Services().iteritems(): use_ssl = deploy_command_util.UseSsl(info.parsed.handlers) deploy_message = DEPLOY_MESSAGE_TEMPLATE.format( project=project, service=service, version=version, file=console_attr.DecodeFromInput(info.file)) url = deploy_command_util.GetAppHostname( app=app, service=info.module, version=None if promote else version, use_ssl=use_ssl) deployed_urls[service] = url deploy_message += DEPLOYED_URL_TEMPLATE.format(url=url) if not promote: default_url = deploy_command_util.GetAppHostname( app=app, service=info.module, use_ssl=use_ssl) deploy_message += PROMOTE_MESSAGE_TEMPLATE.format( default_url=default_url) deploy_messages.append(deploy_message) fmt = 'list[title="You are about to deploy the following services:"]' resource_printer.Print(deploy_messages, fmt, out=log.status) if app_config.Configs(): fmt = 'list[title="You are about to deploy the following configurations:"]' resource_printer.Print([ u'{0}/{1} (from [{2}])'.format(project, c.config, c.file) for c in app_config.Configs().values() ], fmt, out=log.status) return deployed_urls
def _DisplayProposedDeployment(project, app_config, version, promote): """Prints the details of the proposed deployment. Args: project: the name of the current project app_config: the application configuration to be deployed version: the version identifier of the application to be deployed promote: whether the newly deployed version will receive all traffic (this affects deployed URLs) Returns: dict (str->str), a mapping of module names to deployed module URLs This includes information on to-be-deployed modules (including module name, version number, and deployed URLs) as well as configurations. """ # TODO(user): Have modules and configs be able to print themselves. We # do this right now because we actually need to pass a yaml file to appcfg. # Until we can make a call with the correct values for project and version # it is weird to override those values in the yaml parsing code (because # it does not carry through to the actual file contents). deployed_urls = {} if app_config.Modules(): printer = console_io.ListPrinter( 'You are about to deploy the following modules:') deploy_messages = [] for module, info in app_config.Modules().iteritems(): use_ssl = deploy_command_util.UseSsl(info.parsed.handlers) version = None if promote else version if ':' in project: deploy_message = DEPLOY_MESSAGE_DOMAIN_SCOPED_TEMPLATE.format( project=project, module=module, file=info.file) else: url = deploy_command_util.GetAppHostname(project, module=info.module, version=version, use_ssl=use_ssl) deployed_urls[module] = url deploy_message = DEPLOY_MESSAGE_TEMPLATE.format( project=project, module=module, file=info.file, url=url) if not promote: default_url = deploy_command_util.GetAppHostname( project, module=info.module, use_ssl=use_ssl) deploy_message += PROMOTE_MESSAGE.format( default_url=default_url) deploy_messages.append(deploy_message) printer.Print(deploy_messages, output_stream=log.status) if app_config.Configs(): printer = console_io.ListPrinter( 'You are about to deploy the following configurations:') printer.Print([ '{0}/{1} (from [{2}])'.format(project, c.config, c.file) for c in app_config.Configs().values() ], output_stream=log.status) return deployed_urls
def DisplayProposedDeployment(app, project, services, configs, version, promote, service_account): """Prints the details of the proposed deployment. Args: app: Application resource for the current application (required if any services are deployed, otherwise ignored). project: The name of the current project. services: [deployables.Service], The services being deployed. configs: [yaml_parsing.ConfigYamlInfo], The configurations being updated. version: The version identifier of the application to be deployed. promote: Whether the newly deployed version will receive all traffic (this affects deployed URLs). service_account: The service account that the deployed version will run as. Returns: dict (str->str), a mapping of service names to deployed service URLs This includes information on to-be-deployed services (including service name, version number, and deployed URLs) as well as configurations. """ deployed_urls = {} if services: if app is None: raise TypeError( 'If services are deployed, must provide `app` parameter.') log.status.Print('Services to deploy:\n') for service in services: use_ssl = deploy_command_util.UseSsl(service.service_info) url = deploy_command_util.GetAppHostname( app=app, service=service.service_id, version=None if promote else version, use_ssl=use_ssl) deployed_urls[service.service_id] = url log.status.Print( DEPLOY_SERVICE_MESSAGE_TEMPLATE.format( project=project, service=service.service_id, version=version, descriptor=service.descriptor, source=service.source, url=url, service_account=service_account if service_account else 'App Engine default service account')) if not promote: default_url = deploy_command_util.GetAppHostname( app=app, service=service.service_id, use_ssl=use_ssl) log.status.Print( PROMOTE_MESSAGE_TEMPLATE.format(default_url=default_url)) if configs: DisplayProposedConfigDeployments(project, configs) return deployed_urls
def BrowseApp(project, service, version, launch_browser): """Let you browse the given service at the given version. Args: project: str, project ID. service: str, specific service, 'default' if None version: str, specific version, latest if None launch_browser: boolean, if False only print url Returns: None if the browser should open the URL The relevant output as a dict for calliope format to print if not Raises: MissingApplicationError: If an app does not exist. """ try: url = deploy_command_util.GetAppHostname(app_id=project, service=service, version=version, use_ssl=appinfo.SECURE_HTTPS, deploy=False) except api_lib_exceptions.NotFoundError: log.debug('No app found:', exc_info=True) raise exceptions.MissingApplicationError(project) if check_browser.ShouldLaunchBrowser(launch_browser): OpenURL(url) return None else: return { 'url': url, 'service': service or 'default', 'version': version, }
def Run(self, args): if ':' in properties.VALUES.core.project.Get(required=True): raise UnsupportedAppIdError( '`browse` command is currently unsupported for app IDs with custom ' 'domains.') client = appengine_client.AppengineClient() versions = version_util.GetMatchingVersions(client.ListVersions(), args.versions, args.service, client.project) if not args.service and not any('/' in v for v in args.versions): # If no resource paths were provided and the service was not specified, # assume the default service. versions = [v for v in versions if v.service == 'default'] if not versions: log.warn('No matching versions found.') for version in versions: # Assume HTTPS. There's not enough information to determine based on the # results of ListVersions, but HTTPS is always more secure (though HTTP # will work in all cases, since it will redirect to HTTPS). url = deploy_command_util.GetAppHostname( version.project, version.service, version.version, use_ssl=appinfo.SECURE_HTTPS) log.status.Print( 'Opening [{0}] in a new tab in your default browser.'.format( url)) OpenInBrowser(url)
def BrowseApp(project, service=None, version=None): """Open the app in a browser, optionally with given service and version. Args: project: str, project ID. service: str, (optional) specific service, defaults to 'default' version: str, (optional) specific version, defaults to latest """ url = deploy_command_util.GetAppHostname( project, service, version, use_ssl=appinfo.SECURE_HTTPS) OpenURL(url)
def BrowseApp(project, service=None, version=None): """Open the app in a browser, optionally with given service and version. Args: project: str, project ID. service: str, (optional) specific service, defaults to 'default' version: str, (optional) specific version, defaults to latest Raises: UnsupportedAppIdError: If the app is domain scoped. """ if ':' in project: raise UnsupportedAppIdError( '`browse` command is currently unsupported for app IDs with custom ' 'domains.') url = deploy_command_util.GetAppHostname( project, service, version, use_ssl=appinfo.SECURE_HTTPS) OpenURL(url)
def BrowseApp(project, service=None, version=None): """Open the app in a browser, optionally with given service and version. Args: project: str, project ID. service: str, (optional) specific service, defaults to 'default' version: str, (optional) specific version, defaults to latest Raises: MissingApplicationError: If an app does not exist. """ try: url = deploy_command_util.GetAppHostname(app_id=project, service=service, version=version, use_ssl=appinfo.SECURE_HTTPS, deploy=False) except api_lib_exceptions.NotFoundError: log.debug('No app found:', exc_info=True) raise exceptions.MissingApplicationError(project) OpenURL(url)
def DisplayProposedDeployment(app, project, services, configs, version, promote, service_account, api_version='v1'): """Prints the details of the proposed deployment. Args: app: Application resource for the current application (required if any services are deployed, otherwise ignored). project: The name of the current project. services: [deployables.Service], The services being deployed. configs: [yaml_parsing.ConfigYamlInfo], The configurations being updated. version: The version identifier of the application to be deployed. promote: Whether the newly deployed version will receive all traffic (this affects deployed URLs). service_account: The service account that the deployed version will run as. api_version: Version of the yaml file parser to use. Use 'v1' by default. Returns: dict (str->str), a mapping of service names to deployed service URLs This includes information on to-be-deployed services (including service name, version number, and deployed URLs) as well as configurations. """ deployed_urls = {} if services: if app is None: raise TypeError('If services are deployed, must provide `app` parameter.') log.status.Print('Services to deploy:\n') for service in services: use_ssl = deploy_command_util.UseSsl(service.service_info) url = deploy_command_util.GetAppHostname( app=app, service=service.service_id, version=None if promote else version, use_ssl=use_ssl) deployed_urls[service.service_id] = url schema_parser = convert_yaml.GetSchemaParser(api_version) service_account_from_yaml = '' try: service_account_from_yaml = schema_parser.ConvertValue( service.service_info.parsed.ToDict()).get('serviceAccount', None) except ValueError as e: raise exceptions.ConfigError( '[{f}] could not be converted to the App Engine configuration ' 'format for the following reason: {msg}'.format( f=service.service_info, msg=six.text_type(e))) display_service_account = 'App Engine default service account' if service_account: display_service_account = service_account elif service_account_from_yaml: display_service_account = service_account_from_yaml log.status.Print( DEPLOY_SERVICE_MESSAGE_TEMPLATE.format( project=project, service=service.service_id, version=version, descriptor=service.descriptor, source=service.source, url=url, service_account=display_service_account)) if not promote: default_url = deploy_command_util.GetAppHostname( app=app, service=service.service_id, use_ssl=use_ssl) log.status.Print(PROMOTE_MESSAGE_TEMPLATE.format( default_url=default_url)) if configs: DisplayProposedConfigDeployments(project, configs) return deployed_urls