8.2.34 | Linux | www-data (uid:33)
👁 View: detach.py
📁 /snap/google-cloud-cli/current/lib/surface/functions/detach.py
# -*- coding: utf-8 -*- # # Copyright 2024 Google LLC. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Detach GCF 2nd gen function from GCF and make it a native Cloud Run function.""" from googlecloudsdk.api_lib.functions.v2 import client as client_v2 from googlecloudsdk.api_lib.functions.v2 import exceptions from googlecloudsdk.api_lib.functions.v2 import util as api_util from googlecloudsdk.calliope import base from googlecloudsdk.command_lib.functions import flags from googlecloudsdk.command_lib.functions import run_util from googlecloudsdk.core import log from googlecloudsdk.core.console import console_io @base.DefaultUniverseOnly @base.ReleaseTracks(base.ReleaseTrack.GA) class Detach(base.Command): """Detach a Cloud Functions v2 function from its existing environment and make it a native Cloud Run function.""" @staticmethod def Args(parser): flags.AddFunctionResourceArg( parser, help_text_override=( 'The name of the Cloud Functions v2 function to detach.' ), ) def Run(self, args): """Detach a Cloud Functions v2 function from its existing environment. Detach a Cloud Functions v2 function from its existing environment and make it a native Cloud Run function. Args: args: The arguments of the command. Raises: FunctionsError: If the function does not exist or the Cloud Run service is not found. """ client = client_v2.FunctionsClient(self.ReleaseTrack()) function_ref = args.CONCEPTS.name.Parse() function_name = function_ref.RelativeName() message = ( # gcloud-disable-gdu-domain f'WARNING: This command detaches your function {function_name} from the' ' Cloud Functions API (cloudfunctions.googleapis.com). Detached' ' functions continue to serve traffic, and retain the' ' `cloudfunctions.net` URL. You can only manage your detached' ' functions using the Cloud Run Admin API or the `gcloud run' ' <command>`. ' ) if console_io.CanPrompt(): console_io.PromptContinue(message, default=True, cancel_on_no=True) function = client.GetFunction(function_name) if function is None: raise exceptions.FunctionsError( 'Function [{}] does not exist.'.format(function_name) ) operation = client.DetachFunction(function_name) description = ( # gcloud-disable-gdu-domain 'Detaching function from Google Cloud Functions API' ' (cloudfunctions.googleapis.com)' ) api_util.WaitForOperation( client.client, client.messages, operation, description ) # After detach, the function is a native Cloud Run service. service = run_util.GetService(function) if not service: raise exceptions.FunctionsError( 'Failed to get the Cloud Run service for the function' f' [{function_name}].' ) self._PrintSuccessMessage(function_name, service.urls) def _PrintSuccessMessage(self, function_name, urls): log.status.Print() log.status.Print( f'Function {function_name} has been detached successfully! Your' ' function will continue to be available at the following endpoints:' ) for url in urls: log.status.Print(f'* {url}') log.status.Print( 'Any existing event triggers associated with your function will' ' continue to work and can be managed through Eventarc API.\n' 'Reminder, your function can now be managed through the Cloud Run API. ' ) @base.ReleaseTracks(base.ReleaseTrack.BETA) class DetachBeta(Detach): """Detach a Cloud Functions v2 function from its existing environment and make it a native Cloud Run function.""" @base.ReleaseTracks(base.ReleaseTrack.ALPHA) class DetachAlpha(DetachBeta): """Detach a Cloud Functions v2 function from its existing environment and make it a native Cloud Run function."""
← Back
💻 Terminal
📤 Upload
📂
Click or Drag & Drop
📁 /snap/google-cloud-cli/current/lib/surface/functions
NameSizePermModifiedActions
📁 __pycache__/-07752026-09-29 12:17🗑 Delete
📁 event_types/-07752026-09-29 12:17🗑 Delete
📁 local/-07752026-09-29 12:17🗑 Delete
📁 logs/-07752026-09-29 12:17🗑 Delete
📁 regions/-07752026-09-29 12:17🗑 Delete
📁 runtimes/-07752026-09-29 12:17🗑 Delete
__init__.py1.4K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
add_iam_policy_binding.py2.2K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
add_iam_policy_binding.yaml92B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
add_invoker_policy_binding.py3.1K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
add_invoker_policy_binding.yaml92B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
call.py2.8K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
delete.py1.7K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
delete.yaml92B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
deploy.py6.3K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
deploy.yaml92B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
describe.py3.7K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
describe.yaml91B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
detach.py4.3K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
detach.yaml92B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
get_iam_policy.py1.9K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
get_iam_policy.yaml91B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
list.py4.8K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
list.yaml91B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
remove_iam_policy_binding.py2.3K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
remove_iam_policy_binding.yaml92B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
remove_invoker_policy_binding.py3.2K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
remove_invoker_policy_binding.yaml92B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
set_iam_policy.py2K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
set_iam_policy.yaml92B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
upgrade.py15.2K06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del
upgrade.yaml88B06441980-01-01 08:00👁 View ✏️ Edit 📝 Rename 📦 Move 🗑 Del