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,40 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 app firewall-rules group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class FirewallRules(base.Group):
"""View and manage your App Engine firewall rules.
This set of commands can be used to view and manage your app's firewall rules.
"""
category = base.APP_ENGINE_CATEGORY
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To list your App Engine firewall rules, run:
$ {command} list""",
}

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Surface for creating a firewall rule."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.app.api import appengine_firewall_api_client as api_client
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.app import firewall_rules_util
from googlecloudsdk.command_lib.app import flags
from googlecloudsdk.core import log
class Create(base.CreateCommand):
"""Creates a firewall rule."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To create a new App Engine firewall rule, run:
$ {command} 1234
--source-range='2001:db8::/32'
--action=deny
--description='block traffic from the example range.'
""",
}
@staticmethod
def Args(parser):
flags.FIREWALL_PRIORITY_FLAG.AddToParser(parser)
flags.AddFirewallRulesFlags(parser, required=True)
def Run(self, args):
client = api_client.GetApiClientForTrack(self.ReleaseTrack())
priority = firewall_rules_util.ParsePriority(args.priority)
if priority == firewall_rules_util.DEFAULT_RULE_PRIORITY:
raise exceptions.InvalidArgumentException(
'priority', 'The `default` can not be created, only updated.')
action = firewall_rules_util.ParseAction(client.messages, args.action)
rule = client.Create(priority, args.source_range, action, args.description)
log.CreatedResource(args.priority)
return rule

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Surface for deleting a firewall rule."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.app.api import appengine_firewall_api_client as api_client
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.app import firewall_rules_util
from googlecloudsdk.command_lib.app import flags
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
class Delete(base.DeleteCommand):
"""Deletes a specified firewall rule."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To delete an App Engine firewall rule, run:
$ {command} 1234
""",
}
@staticmethod
def Args(parser):
flags.FIREWALL_PRIORITY_FLAG.AddToParser(parser)
def Run(self, args):
priority = firewall_rules_util.ParsePriority(args.priority)
if priority == firewall_rules_util.DEFAULT_RULE_PRIORITY:
raise exceptions.InvalidArgumentException(
'priority', 'The `default` can not be deleted, only updated.')
console_io.PromptContinue(
prompt_string='You are about to delete rule [{0}].'.format(priority),
cancel_on_no=True)
client = api_client.GetApiClientForTrack(self.ReleaseTrack())
resource = firewall_rules_util.ParseFirewallRule(client, priority)
client.Delete(resource)
log.DeletedResource(priority)

View File

@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Surface for retrieving a single firewall rule."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.app.api import appengine_firewall_api_client as api_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.app import firewall_rules_util
from googlecloudsdk.command_lib.app import flags
class Describe(base.DescribeCommand):
"""Prints the fields of a specified firewall rule."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To describe an App Engine firewall rule, run:
$ {command} 1234
""",
}
@staticmethod
def Args(parser):
flags.FIREWALL_PRIORITY_FLAG.AddToParser(parser)
def Run(self, args):
client = api_client.GetApiClientForTrack(self.ReleaseTrack())
resource = firewall_rules_util.ParseFirewallRule(client, args.priority)
return client.Get(resource)

View File

@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Surface for listing all firewall rules."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.app.api import appengine_firewall_api_client as api_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.app import firewall_rules_util
class List(base.ListCommand):
"""Lists the firewall rules."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To list all App Engine firewall rules, run:
$ {command}
""",
}
@staticmethod
def Args(parser):
parser.display_info.AddFormat(firewall_rules_util.LIST_FORMAT)
def Run(self, args):
client = api_client.GetApiClientForTrack(self.ReleaseTrack())
return client.List()

View File

@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Surface to test an ip address against firewall rules."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.app.api import appengine_firewall_api_client as api_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.app import firewall_rules_util
from googlecloudsdk.core import log
class TestIp(base.Command):
"""Display firewall rules that match a given IP."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To test an IP address against the firewall rule set, run:
$ {command} 127.1.2.3
""",
}
@staticmethod
def Args(parser):
parser.display_info.AddFormat(firewall_rules_util.LIST_FORMAT)
parser.add_argument(
'ip', help='An IPv4 or IPv6 address to test against the firewall.')
def Run(self, args):
client = api_client.GetApiClientForTrack(self.ReleaseTrack())
response = client.List(args.ip)
rules = list(response)
if rules:
log.status.Print('The action `{0}` will apply to the IP address.\n'.
format(rules[0].action))
log.status.Print('Matching Rules')
else:
log.status.Print('No rules match the IP address.')
return rules

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Surface for updating a firewall rule."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.app import util as util
from googlecloudsdk.api_lib.app.api import appengine_firewall_api_client as api_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.app import firewall_rules_util
from googlecloudsdk.command_lib.app import flags
from googlecloudsdk.core import log
class Update(base.UpdateCommand):
"""Updates a firewall rule."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To update an App Engine firewall rule, run:
$ {command} 1234
--source-range='2001:db8::/32'
--action=allow
--description='This is an example rule.'
""",
}
@staticmethod
def Args(parser):
flags.FIREWALL_PRIORITY_FLAG.AddToParser(parser)
flags.AddFirewallRulesFlags(parser, required=False)
def Run(self, args):
client = api_client.GetApiClientForTrack(self.ReleaseTrack())
priority = firewall_rules_util.ParsePriority(args.priority)
resource = firewall_rules_util.ParseFirewallRule(client, priority)
action = firewall_rules_util.ParseAction(client.messages, args.action)
try:
rule = client.Update(resource, priority, args.source_range, action,
args.description)
except util.NoFieldsSpecifiedError:
firewall_rules_util.RaiseMinArgument()
log.UpdatedResource(priority)
return rule