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 16"""Command for describing security policies rules.""" 17 18from __future__ import absolute_import 19from __future__ import division 20from __future__ import unicode_literals 21 22from googlecloudsdk.api_lib.compute import base_classes 23from googlecloudsdk.api_lib.compute.security_policies import client 24from googlecloudsdk.calliope import base 25from googlecloudsdk.command_lib.compute.security_policies import flags as security_policy_flags 26from googlecloudsdk.command_lib.compute.security_policies.rules import flags 27from googlecloudsdk.core import properties 28 29 30class Describe(base.DescribeCommand): 31 """Describe a Compute Engine security policy rule. 32 33 *{command}* displays all data associated with a security policy rule. 34 """ 35 36 SECURITY_POLICY_ARG = None 37 38 @classmethod 39 def Args(cls, parser): 40 flags.AddPriority(parser, 'describe') 41 cls.SECURITY_POLICY_ARG = ( 42 security_policy_flags.SecurityPolicyArgumentForRules()) 43 cls.SECURITY_POLICY_ARG.AddArgument(parser) 44 45 def Run(self, args): 46 holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) 47 ref = holder.resources.Parse( 48 args.name, 49 collection='compute.securityPolicyRules', 50 params={ 51 'project': properties.VALUES.core.project.GetOrFail, 52 'securityPolicy': args.security_policy 53 }) 54 security_policy_rule = client.SecurityPolicyRule( 55 ref, compute_client=holder.client) 56 57 return security_policy_rule.Describe() 58