feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""The gcloud emulators command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Emulators(base.Group):
"""Set up your local development environment using emulators."""
category = base.SDK_TOOLS_CATEGORY
def Filter(self, context, args):
del context, args
base.DisableUserProjectQuota()

View File

@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 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.
"""The gcloud bigtable emulator group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import bigtable_util
from googlecloudsdk.command_lib.emulators import util
from googlecloudsdk.core import exceptions
from googlecloudsdk.core.util import platforms
class UnsupportedPlatformError(exceptions.Error):
pass
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Bigtable(base.Group):
"""Manage your local Bigtable emulator.
This set of commands allows you to start and use a local Bigtable emulator.
"""
detailed_help = {
'EXAMPLES':
"""\
To start a local Bigtable emulator, run:
$ {command} start
""",
}
# Override
def Filter(self, context, args):
util.EnsureComponentIsInstalled(bigtable_util.BIGTABLE,
bigtable_util.BIGTABLE_TITLE)

View File

@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""gcloud bigtable emulator env_init command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import bigtable_util
from googlecloudsdk.command_lib.emulators import util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class EnvInit(base.Command):
"""Print the commands required to export Bigtable emulator's env variables."""
detailed_help = {
'EXAMPLES': """\
To print the env variables exports for a Bigtable emulator, run:
$ {command}
""",
}
@staticmethod
def Args(parser):
parser.display_info.AddFormat('config[export]')
def Run(self, args):
data_dir = bigtable_util.GetDataDir()
return util.ReadEnvYaml(data_dir)

View File

@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 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.
"""gcloud bigtable emulator start command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import bigtable_util
from googlecloudsdk.command_lib.emulators import util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Start(base.Command):
"""Start a local Bigtable emulator.
This command starts a local Bigtable emulator.
"""
detailed_help = {
'EXAMPLES': """\
To start a local Bigtable emulator, run:
$ {command}
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'--host-port',
required=False,
type=lambda arg: arg_parsers.HostPort.Parse(arg, ipv6_enabled=True),
help='The host:port to which the emulator should be bound. The default '
'value is localhost:8086.')
# Override
def Run(self, args):
if not args.host_port:
args.host_port = arg_parsers.HostPort.Parse(util.GetHostPort(
bigtable_util.BIGTABLE), ipv6_enabled=True)
bigtable_util.Start(args)

View File

@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""The gcloud datastore emulator group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import actions
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import datastore_util
from googlecloudsdk.command_lib.emulators import flags
from googlecloudsdk.command_lib.emulators import util
from googlecloudsdk.command_lib.util import java
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Datastore(base.Group):
"""Manage your local datastore emulator.
This set of commands allows you to start and use a local datastore emulator.
"""
detailed_help = {
'EXAMPLES': """\
To start a local datastore emulator, run:
$ {command} start
""",
}
@staticmethod
def Args(parser):
flags.AddDataDirFlag(parser, datastore_util.DATASTORE)
def Filter(self, context, args):
java.RequireJavaInstalled(datastore_util.DATASTORE_TITLE, min_version=8)
util.EnsureComponentIsInstalled('cloud-datastore-emulator',
datastore_util.DATASTORE_TITLE)
if not args.data_dir:
args.data_dir = datastore_util.GetDataDir()

View File

@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""gcloud datastore emulator env-init command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class EnvInit(base.Command):
"""Print the commands required to export env variables of a datastore.
Prints the commands but does not execute them. It will output
in shell syntax or on Windows it will be in cmd.exe syntax.
## EXAMPLES
To print the env variables exports for a datastore emulator, run:
$ {command} --data-dir=DATA-DIR
You can use this command to set env vars in a bash script by adding the below
line in the script.
eval $({command} --data-dir=DATA-DIR)
"""
@staticmethod
def Args(parser):
parser.display_info.AddFormat('config[export]')
def Run(self, args):
return util.ReadEnvYaml(args.data_dir)

View File

@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""gcloud datastore emulator env-unset command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class EnvUnset(base.Command):
"""Print the commands required to unset a datastore emulators env variables.
"""
detailed_help = {
'EXAMPLES': """
To print the commands necessary to unset the env variables for
a datastore emulator, run:
$ {command} --data-dir=DATA-DIR
""",
}
@staticmethod
def Args(parser):
parser.display_info.AddFormat('config[unset]')
def Run(self, args):
return util.ReadEnvYaml(args.data_dir)

View File

@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""gcloud datastore emulator start command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import socket
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import datastore_util
from googlecloudsdk.command_lib.emulators import util
from googlecloudsdk.command_lib.util import java
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class Start(base.Command):
"""Start a local datastore emulator.
This command starts a local datastore emulator.
"""
detailed_help = {
'EXAMPLES': """
To start a local datastore emulator, run:
$ {command} --data-dir=DATA-DIR
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'--host-port',
required=False,
type=lambda arg: arg_parsers.HostPort.Parse(arg, ipv6_enabled=True),
help='The host:port to which the emulator should be bound. Can '
'take the form of a single address (hostname, IPv4, or IPv6) and/or '
'port:\n\n [ADDRESS][:PORT]\n\n'
'In this format you must enclose IPv6 addresses in square brackets: '
'e.g.\n\n'
' [2001:db8:0:0:0:ff00:42:8329]:8080\n\n'
'The default value is localhost:8081.')
parser.add_argument(
'--store-on-disk',
default=True,
action='store_true',
help='Whether data should be persisted to disk.')
group = parser.add_mutually_exclusive_group()
group.add_argument(
'--consistency',
required=False,
type=float,
default=0.9,
help='Fraction of eventually consistent operations that '
'should succeed immediately. Setting to 1.0 can be useful '
'for unit tests, but may mask incorrect assumptions about '
'non-ancestor queries which are eventually consistent.')
group.add_argument(
'--use-firestore-in-datastore-mode',
default=False,
action='store_true',
help='Runs the emulator in Cloud Firestore in Datastore Mode. '
'Reads are always strongly consistent and --consistency flag may not '
'be specified.')
def Run(self, args):
if not args.host_port:
args.host_port = arg_parsers.HostPort.Parse(
datastore_util.GetHostPort(), ipv6_enabled=socket.has_ipv6)
args.host_port.host = args.host_port.host or 'localhost'
args.host_port.port = args.host_port.port or '8081'
java.RequireJavaInstalled(datastore_util.DATASTORE_TITLE, min_version=21)
datastore_util.PrepareGCDDataDir(args)
with datastore_util.StartGCDEmulator(args) as proc:
datastore_util.WriteGCDEnvYaml(args)
util.PrefixOutput(proc, 'datastore')

View File

@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""The gcloud firestore emulator group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import firestore_util
from googlecloudsdk.command_lib.emulators import flags
from googlecloudsdk.command_lib.emulators import util
from googlecloudsdk.command_lib.util import java
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Firestore(base.Group):
"""Manage your local Firestore emulator.
This set of commands allows you to start and use a local Firestore emulator.
"""
detailed_help = {
'EXAMPLES':
"""\
To start the local Firestore emulator, run:
$ {command} start
""",
}
def Filter(self, context, args):
java.RequireJavaInstalled(firestore_util.FIRESTORE_TITLE, min_version=8)
util.EnsureComponentIsInstalled('cloud-firestore-emulator',
firestore_util.FIRESTORE_TITLE)

View File

@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""gcloud datastore emulator start command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import socket
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import firestore_util
from googlecloudsdk.command_lib.emulators import util
from googlecloudsdk.command_lib.util import java
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Start(base.Command):
"""Start a local Firestore emulator.
This command starts a local Firestore emulator.
"""
detailed_help = {
'EXAMPLES':
"""\
To start the local Firestore emulator, run:
$ {command}
To bind to a specific host and port, run:
$ {command} --host-port=0.0.0.0:8080
To run the local Firestore emulator with a Firebase Rules set, run:
$ {command} --rules=firestore.rules
To run the local Firestore emulator in Datastore Mode, run:
$ {command} --database-mode=datastore-mode
To import data at the start of the Firestore emulator, run:
$ {command} --import-data=<path/to/file>
To export emulator data upon emulator shutdown, run:
$ {command} --export-on-exit=<path/to/directory>
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'--rules',
required=False,
help='If set, all projects will use the security rules in this file. '
'More information on Firebase Rules and the syntax for this file '
'is available at https://firebase.google.com/docs/rules.')
parser.add_argument(
'--host-port',
required=False,
type=lambda arg: arg_parsers.HostPort.Parse(arg, ipv6_enabled=True),
help='The host:port to which the emulator should be bound. Can '
'take the form of a single address (hostname, IPv4, or IPv6) and/or '
'port:\n\n [ADDRESS][:PORT]\n\n'
'In this format you must enclose IPv6 addresses in square brackets: '
'e.g.\n\n'
' [2001:db8:0:0:0:ff00:42:8329]:8080\n\n'
'The default value is localhost:8080.')
parser.add_argument(
'--database-mode',
required=False,
help='The database mode to start the Firestore Emulator in. The valid '
'options are: \n\n'
' `firestore-native` (default): start the emulator in Firestore '
'Native\n'
' `datastore-mode`: start the emulator in Datastore Mode')
parser.add_argument(
'--use-firestore-in-datastore-mode',
default=False,
action='store_true',
hidden=True,
help='Runs the emulator in Datastore Mode.')
parser.add_argument(
'--import-data',
required=False,
help='File path to the data to be loaded into the emulator upon start '
'up. Example:`/home/user/myexports/sampleExport/sampleExport.overall_export_metadata.`')
parser.add_argument(
'--export-on-exit',
required=False,
help='Directory path in which emulator data will be saved upon '
'shutdown. Example:`/home/user/myexports/2024-03-26/`')
parser.add_argument(
'--licenses',
default=False,
action='store_true',
help='If set, the emulator will print open-source dependencies and '
'licenses, then exit.')
def Run(self, args):
if not args.host_port:
args.host_port = arg_parsers.HostPort.Parse(
firestore_util.GetHostPort(), ipv6_enabled=socket.has_ipv6)
args.host_port.host = args.host_port.host or 'localhost'
args.host_port.port = args.host_port.port or '8080'
args.database_mode = args.database_mode or 'firestore-native'
firestore_util.ValidateStartArgs(args)
java.RequireJavaInstalled(firestore_util.FIRESTORE_TITLE, min_version=21)
with firestore_util.StartFirestoreEmulator(args) as proc:
util.PrefixOutput(proc, 'firestore')

View File

@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""The gcloud pubsub emulator group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import flags
from googlecloudsdk.command_lib.emulators import pubsub_util
from googlecloudsdk.command_lib.emulators import util
from googlecloudsdk.command_lib.util import java
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class PubSub(base.Group):
"""Manage your local pubsub emulator.
This set of commands allows you to start and use a local Pub/Sub emulator to
produce a local emulation of your production Google Pub/Sub environment. In
addition to having Java JRE (of version 7 or higher) installed and an
application built with Google Cloud Client libraries, you must have your
emulator configured (have it started with environment variables set) for
it to run successfully. The underlying commands help to set up this
configuration.
To stop the emulator, press Ctrl+C.
For a more comprehensive overview of Pub/Sub, see
https://cloud.google.com/pubsub/docs/overview. For Pub/Sub emulator specific
documentation, see https://cloud.google.com/pubsub/docs/emulator
"""
detailed_help = {
'EXAMPLES': """\
To start a local pubsub emulator with the default directory for
configuration data, run:
$ {command} start
After starting the emulator, if your application and
emulator run on the same machine, set environment variables
automatically by running:
$ {command} env-init
If you're running your emulator on a different machine, run the above
command and use its resulting output to set the environment variables
on the machine that runs your application. This might look like:
$ export PUBSUB_EMULATOR_HOST=localhost:8538
$ export PUBSUB_PROJECT_ID=my-project-id
Your emulator is now ready for use.
""",
}
@staticmethod
def Args(parser):
flags.AddDataDirFlag(parser, pubsub_util.PUBSUB)
# Override
def Filter(self, context, args):
java.RequireJavaInstalled(pubsub_util.PUBSUB_TITLE)
util.EnsureComponentIsInstalled('pubsub-emulator', pubsub_util.PUBSUB_TITLE)
if not args.data_dir:
args.data_dir = pubsub_util.GetDataDir()

View File

@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""gcloud pubsub emulator env_init command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class EnvInit(base.Command):
"""Print the commands required to export pubsub emulator's env variables.
After starting the emulator, you need to set environment variables so that
your application connects to the emulator instead of the production
environment. Environment variables need to be set each time you start the
emulator. The environment variables depend on dynamically assigned port
numbers that could change when you restart the emulator.
"""
detailed_help = {
'EXAMPLES': """
To print the env variables exports for a pubsub emulator, run:
$ {command} --data-dir=DATA-DIR
For a detailed walkthrough of setting Pub/Sub emulator environment
variables, see https://cloud.google.com/pubsub/docs/emulator#env.
""",
}
@staticmethod
def Args(parser):
parser.display_info.AddFormat('config[export]')
def Run(self, args):
return util.ReadEnvYaml(args.data_dir)

View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""gcloud pubsub emulator start command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import pubsub_util
from googlecloudsdk.command_lib.emulators import util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Start(base.Command):
"""Start a local pubsub emulator.
This command starts a local pubsub emulator.
On successful start up, you should expect to see:
```
...
[pubsub] This is the Google Pub/Sub fake.
[pubsub] Implementation may be incomplete or differ from the real system.
...
[pubsub] INFO: Server started, listening on 8538
```
"""
detailed_help = {
'EXAMPLES': """
To start a local pubsub emulator, run:
$ {command} --data-dir=DATA-DIR
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'--host-port',
required=False,
type=lambda arg: arg_parsers.HostPort.Parse(arg, ipv6_enabled=True),
help='The host:port to which the emulator should be bound. The default '
'value is [::1]:8085.')
# Override
def Run(self, args):
if not args.host_port:
args.host_port = arg_parsers.HostPort.Parse(util.GetHostPort(
pubsub_util.PUBSUB), ipv6_enabled=True)
with pubsub_util.Start(args) as pubsub_process:
util.WriteEnvYaml(pubsub_util.GetEnv(args), args.data_dir)
util.PrefixOutput(pubsub_process, pubsub_util.PUBSUB)

View File

@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""The gcloud emulators spanner group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import spanner_util
from googlecloudsdk.command_lib.emulators import util
from googlecloudsdk.core import exceptions
from googlecloudsdk.core.util import files
from googlecloudsdk.core.util import platforms
class UnsupportedPlatformError(exceptions.Error):
pass
class DockerNotFoundError(exceptions.Error):
pass
def _RequireDockerInstalled():
docker_path = files.FindExecutableOnPath('docker')
if not docker_path:
raise DockerNotFoundError(
'To use the Cloud Spanner Emulator on {platform}, '
'docker must be installed on your system PATH'.format(
platform=platforms.OperatingSystem.Current().name))
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Spanner(base.Group):
"""Manage your local Spanner emulator.
This set of commands allows you to start and use a local Spanner emulator.
"""
detailed_help = {
'EXAMPLES':
"""\
To start a local Cloud Spanner emulator, run:
$ {command} start
""",
}
# Override
def Filter(self, context, args):
current_os = platforms.OperatingSystem.Current()
if current_os is platforms.OperatingSystem.LINUX:
util.EnsureComponentIsInstalled(
spanner_util.SPANNER_EMULATOR_COMPONENT_ID,
spanner_util.SPANNER_EMULATOR_TITLE)
else:
_RequireDockerInstalled()

View File

@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""gcloud emulators spanner env_init command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import spanner_util
from googlecloudsdk.command_lib.emulators import util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class EnvInit(base.Command):
"""Print the commands required to export Spanner emulator's env variables."""
detailed_help = {
'EXAMPLES':
"""\
To print the env variables exports for a Spanner emulator, run:
$ {command}
""",
}
@staticmethod
def Args(parser):
parser.display_info.AddFormat('config[export]')
def Run(self, args):
data_dir = spanner_util.GetDataDir()
return util.ReadEnvYaml(data_dir)

View File

@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""gcloud emulators spanner notices command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import argparse
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import spanner_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.UniverseCompatible
class Notices(base.Command):
"""Print third-party notices for the local Cloud Spanner emulator.
"""
detailed_help = {
'EXAMPLES':
"""\
To print third-party notices for the local Cloud Spanner emulator, run:
$ {command}
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'--use-docker',
required=False,
action='store_true',
help='Use the Cloud Spanner emulator docker image even if the platform '
'has a native binary available in the gcloud CLI. Currently we only '
'provide a native binary for Linux. For other systems, you must '
'install Docker for your platform before starting the emulator.')
def Run(self, args):
# Construct a new args for spanner_util.Start. No need to parse arguments
# for this command.
start_args = argparse.Namespace()
# These attributes are needed by spanner_util._BuildStartArgs*
start_args.host_port = arg_parsers.HostPort('localhost', '9010')
start_args.rest_port = 9020
start_args.use_docker = args.use_docker
start_args.enable_fault_injection = False
# This is the main point of this command.
start_args.print_notices = True
spanner_util.Start(start_args)

View File

@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""gcloud emulators spanner start command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.emulators import spanner_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Start(base.Command):
"""Start a local Cloud Spanner emulator.
This command starts a local Cloud Spanner emulator.
"""
detailed_help = {
'EXAMPLES':
"""\
To start a local Cloud Spanner emulator, run:
$ {command}
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'--host-port',
required=False,
type=lambda arg: arg_parsers.HostPort.Parse(arg, ipv6_enabled=True),
help='The host:port to which the emulator should be bound. The default '
'value is localhost:9010. Note that this port serves gRPC requests. To '
'override the default port serving REST requests, use --rest-port. If '
'using Docker to run the emulator, the host must be specified as an '
'ipaddress.')
parser.add_argument(
'--rest-port',
required=False,
type=arg_parsers.BoundedInt(1, 65535),
help='The port at which REST requests are served. gcloud uses REST to '
'communicate with the emulator. The default value is 9020.')
parser.add_argument(
'--use-docker',
required=False,
type=arg_parsers.ArgBoolean(),
help='Use the Cloud Spanner emulator docker image even if the platform '
'has a native binary available in the gcloud CLI. Currently we only '
'provide a native binary for Linux. For other systems, you must '
'install Docker for your platform before starting the emulator.')
parser.add_argument(
'--enable-fault-injection',
required=False,
type=arg_parsers.ArgBoolean(),
help='If true, the emulator will randomly inject faults into '
'transactions. This facilitates application abort-retry testing.',
default=False)
def Run(self, args):
if not args.host_port:
args.host_port = arg_parsers.HostPort('localhost', '9010')
if not args.rest_port:
args.rest_port = 9020
spanner_util.Start(args)