1# -*- coding: utf-8 -*- # 2# Copyright 2017 Google LLC. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15"""Flags and helpers for the compute security policies commands.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import unicode_literals 20 21from googlecloudsdk.command_lib.compute import completers as compute_completers 22from googlecloudsdk.command_lib.compute import flags as compute_flags 23 24 25class SecurityPoliciesCompleter(compute_completers.ListCommandCompleter): 26 27 def __init__(self, **kwargs): 28 super(SecurityPoliciesCompleter, self).__init__( 29 collection='compute.securityPolicies', 30 list_command='alpha compute security-policies list --uri', 31 **kwargs) 32 33 34def SecurityPolicyArgument(required=True, plural=False): 35 return compute_flags.ResourceArgument( 36 resource_name='security policy', 37 completer=SecurityPoliciesCompleter, 38 plural=plural, 39 custom_plural='security policies', 40 required=required, 41 global_collection='compute.securityPolicies') 42 43 44def SecurityPolicyArgumentForTargetResource(resource, required=False): 45 return compute_flags.ResourceArgument( 46 resource_name='security policy', 47 name='--security-policy', 48 completer=SecurityPoliciesCompleter, 49 plural=False, 50 required=required, 51 global_collection='compute.securityPolicies', 52 short_help=('The security policy that will be set for this {0}.' 53 .format(resource))) 54 55 56def EdgeSecurityPolicyArgumentForTargetResource(resource, required=False): 57 return compute_flags.ResourceArgument( 58 resource_name='security policy', 59 name='--edge-security-policy', 60 completer=SecurityPoliciesCompleter, 61 plural=False, 62 required=required, 63 global_collection='compute.securityPolicies', 64 short_help=('The edge security policy that will be set for this {0}.' 65 .format(resource))) 66 67 68def SecurityPolicyArgumentForRules(required=False): 69 return compute_flags.ResourceArgument( 70 resource_name='security policy', 71 name='--security-policy', 72 completer=SecurityPoliciesCompleter, 73 plural=False, 74 required=required, 75 global_collection='compute.securityPolicies', 76 short_help='The security policy that this rule belongs to.') 77