コード例 #1
0
    def apply(self):
        stub = firewall_policy_rule_pb2_grpc.ComputeBetaFirewallPolicyRuleServiceStub(
            channel.Channel())
        request = firewall_policy_rule_pb2.ApplyComputeBetaFirewallPolicyRuleRequest(
        )
        if Primitive.to_proto(self.description):
            request.resource.description = Primitive.to_proto(self.description)

        if Primitive.to_proto(self.priority):
            request.resource.priority = Primitive.to_proto(self.priority)

        if FirewallPolicyRuleMatch.to_proto(self.match):
            request.resource.match.CopyFrom(
                FirewallPolicyRuleMatch.to_proto(self.match))
        else:
            request.resource.ClearField("match")
        if Primitive.to_proto(self.action):
            request.resource.action = Primitive.to_proto(self.action)

        if FirewallPolicyRuleDirectionEnum.to_proto(self.direction):
            request.resource.direction = FirewallPolicyRuleDirectionEnum.to_proto(
                self.direction)

        if Primitive.to_proto(self.target_resources):
            request.resource.target_resources.extend(
                Primitive.to_proto(self.target_resources))
        if Primitive.to_proto(self.enable_logging):
            request.resource.enable_logging = Primitive.to_proto(
                self.enable_logging)

        if Primitive.to_proto(self.target_service_accounts):
            request.resource.target_service_accounts.extend(
                Primitive.to_proto(self.target_service_accounts))
        if Primitive.to_proto(self.disabled):
            request.resource.disabled = Primitive.to_proto(self.disabled)

        if Primitive.to_proto(self.firewall_policy):
            request.resource.firewall_policy = Primitive.to_proto(
                self.firewall_policy)

        request.service_account_file = self.service_account_file

        response = stub.ApplyComputeBetaFirewallPolicyRule(request)
        self.description = Primitive.from_proto(response.description)
        self.priority = Primitive.from_proto(response.priority)
        self.match = FirewallPolicyRuleMatch.from_proto(response.match)
        self.action = Primitive.from_proto(response.action)
        self.direction = FirewallPolicyRuleDirectionEnum.from_proto(
            response.direction)
        self.target_resources = Primitive.from_proto(response.target_resources)
        self.enable_logging = Primitive.from_proto(response.enable_logging)
        self.rule_tuple_count = Primitive.from_proto(response.rule_tuple_count)
        self.target_service_accounts = Primitive.from_proto(
            response.target_service_accounts)
        self.disabled = Primitive.from_proto(response.disabled)
        self.kind = Primitive.from_proto(response.kind)
        self.firewall_policy = Primitive.from_proto(response.firewall_policy)
コード例 #2
0
    def list(self, firewallPolicy, service_account_file=""):
        stub = firewall_policy_rule_pb2_grpc.ComputeBetaFirewallPolicyRuleServiceStub(
            channel.Channel())
        request = firewall_policy_rule_pb2.ListComputeBetaFirewallPolicyRuleRequest(
        )
        request.service_account_file = service_account_file
        request.FirewallPolicy = firewallPolicy

        return stub.ListComputeBetaFirewallPolicyRule(request).items