def GetAllowUnauth(args, operations, service_ref, service_exists): """Returns allow_unauth value for a service change. Args: args: argparse.Namespace, Command line arguments operations: serverless_operations.ServerlessOperations, Serverless client. service_ref: protorpc.messages.Message, A resource reference object for the service See googlecloudsdk.core.resources.Registry.ParseResourceId for details. service_exists: True if the service being changed already exists. Returns: allow_unauth value where True means to enable unauthenticated acess for the service. False means to disable unauthenticated access for the service. None means to retain the current value for the service. """ allow_unauth = None if flags.GetPlatform() == flags.PLATFORM_MANAGED: allow_unauth = flags.GetAllowUnauthenticated(args, operations, service_ref, not service_exists) # Avoid failure removing a policy binding for a service that # doesn't exist. if not service_exists and not allow_unauth: allow_unauth = None return allow_unauth
def Run(self, args): """Update configuration information about the service. Does not change the running code. Args: args: Args! """ conn_context = connection_context.GetConnectionContext(args) service_ref = flags.GetService(args) if conn_context.supports_one_platform: flags.VerifyOnePlatformFlags(args) else: flags.VerifyGKEFlags(args) with serverless_operations.Connect(conn_context) as client: changes = flags.GetConfigurationChanges(args) endpoint_visibility = flags.GetEndpointVisibility(args) allow_unauth = None if conn_context.supports_one_platform: allow_unauth = flags.GetAllowUnauthenticated( args, client, service_ref) if not changes and endpoint_visibility is None and allow_unauth is None: raise exceptions.NoConfigurationChangeError( 'No configuration change requested. ' 'Did you mean to include the flags `--update-env-vars`, ' '`--memory`, `--concurrency`, `--timeout`, `--connectivity`, ' 'or `--allow-unauthenticated`?') deployment_stages = stages.ServiceStages(allow_unauth is not None) with progress_tracker.StagedProgressTracker( 'Deploying...', deployment_stages, failure_message='Deployment failed', suppress_output=args. async) as tracker: client.ReleaseService(service_ref, changes, tracker, asyn=args. async, private_endpoint=endpoint_visibility, allow_unauthenticated=allow_unauth) if args. async: pretty_print.Success('Deploying asynchronously.') else: url = client.GetServiceUrl(service_ref) active_revs = client.GetActiveRevisions(service_ref) msg = ( '{{bold}}Service [{serv}] revision{plural} {rev_msg} is active' ' and serving traffic at{{reset}} {url}') rev_msg = ' '.join(['[{}]'.format(rev) for rev in active_revs]) msg = msg.format(serv=service_ref.servicesId, plural='s' if len(active_revs) > 1 else '', rev_msg=rev_msg, url=url) pretty_print.Success(msg)
def Run(self, args): """Deploy a container to Cloud Run.""" image = args.image conn_context = connection_context.GetConnectionContext(args) config_changes = flags.GetConfigurationChanges(args) if conn_context.supports_one_platform: flags.VerifyOnePlatformFlags(args) else: flags.VerifyGKEFlags(args) service_ref = flags.GetService(args) with serverless_operations.Connect(conn_context) as operations: image_change = config_changes_mod.ImageChange(image) changes = [image_change] if config_changes: changes.extend(config_changes) endpoint_visibility = flags.GetEndpointVisibility(args) exists = operations.GetService(service_ref) allow_unauth = None if conn_context.supports_one_platform: allow_unauth = flags.GetAllowUnauthenticated( args, operations, service_ref, not exists) # Don't try to remove a policy binding from a service that doesn't exist if not exists and not allow_unauth: allow_unauth = None msg = ('Deploying {dep_type} to {operator} ' 'service [{{bold}}{service}{{reset}}]' ' in {ns_label} [{{bold}}{ns}{{reset}}]') msg += conn_context.location_label pretty_print.Info( msg.format(operator=conn_context.operator, ns_label=conn_context.ns_label, dep_type='container', service=service_ref.servicesId, ns=service_ref.namespacesId)) deployment_stages = stages.ServiceStages(allow_unauth is not None) header = 'Deploying...' if exists else 'Deploying new service...' with progress_tracker.StagedProgressTracker( header, deployment_stages, failure_message='Deployment failed', suppress_output=args. async) as tracker: operations.ReleaseService(service_ref, changes, tracker, asyn=args. async, private_endpoint=endpoint_visibility, allow_unauthenticated=allow_unauth) if args. async: pretty_print.Success( 'Service [{{bold}}{serv}{{reset}}] is deploying ' 'asynchronously.'.format(serv=service_ref.servicesId)) else: url = operations.GetServiceUrl(service_ref) conf = operations.GetConfiguration(service_ref) msg = ('Service [{{bold}}{serv}{{reset}}] ' 'revision [{{bold}}{rev}{{reset}}] ' 'has been deployed and is serving traffic at ' '{{bold}}{url}{{reset}}') msg = msg.format(serv=service_ref.servicesId, rev=conf.status.latestReadyRevisionName, url=url) pretty_print.Success(msg)