Пример #1
0
    def Run(self, args):
        client = zones_api.Client(version=self._API_VERSION)
        perimeter_ref = args.CONCEPTS.perimeter.Parse()
        result = repeated.CachedResult.FromFunc(client.Get, perimeter_ref)
        policies.ValidateAccessPolicyArg(perimeter_ref, args)

        return self.Patch(
            client=client,
            args=args,
            result=result,
            perimeter_ref=perimeter_ref,
            description=args.description,
            title=args.title,
            perimeter_type=perimeters.GetTypeEnumMapper(
                version=self._API_VERSION).GetEnumForChoice(args.type),
            resources=perimeters.ParseResources(args, result),
            restricted_services=perimeters.ParseRestrictedServices(
                args, result),
            levels=perimeters.ParseLevels(args, result,
                                          perimeter_ref.accessPoliciesId),
            vpc_allowed_services=perimeters.ParseVpcRestriction(
                args, result, self._API_VERSION),
            enable_vpc_accessible_services=args.enable_vpc_accessible_services,
            ingress_policies=perimeters.ParseUpdateDirectionalPoliciesArgs(
                args, self._release_track, 'ingress-policies'),
            egress_policies=perimeters.ParseUpdateDirectionalPoliciesArgs(
                args, self._release_track, 'egress-policies'))
Пример #2
0
    def Run(self, args):
        client = zones_api.Client(version=self._API_VERSION)
        messages = util.GetMessages(version=self._API_VERSION)
        perimeter_ref = args.CONCEPTS.perimeter.Parse()
        policies.ValidateAccessPolicyArg(perimeter_ref, args)
        original_perimeter = client.Get(perimeter_ref)
        base_config = _GetBaseConfig(original_perimeter)
        if _IsFieldSpecified('resources', args):
            updated_resources = _GetRepeatedFieldValue(
                args, 'resources', base_config.resources,
                original_perimeter.useExplicitDryRunSpec)
        else:
            updated_resources = base_config.resources
        if _IsFieldSpecified('restricted_services', args):
            updated_restricted_services = _GetRepeatedFieldValue(
                args, 'restricted_services', base_config.restrictedServices,
                original_perimeter.useExplicitDryRunSpec)
        else:
            updated_restricted_services = base_config.restrictedServices
        if _IsFieldSpecified('access_levels', args):
            updated_access_levels = _GetRepeatedFieldValue(
                args, 'access_levels', base_config.accessLevels,
                original_perimeter.useExplicitDryRunSpec)
        else:
            updated_access_levels = base_config.accessLevels
        base_vpc_config = base_config.vpcAccessibleServices
        if base_vpc_config is None:
            base_vpc_config = messages.VpcAccessibleServices()
        if _IsFieldSpecified('vpc_allowed_services', args):
            updated_vpc_services = _GetRepeatedFieldValue(
                args, 'vpc-allowed-services', base_vpc_config.allowedServices,
                original_perimeter.useExplicitDryRunSpec)
        elif base_config.vpcAccessibleServices is not None:
            updated_vpc_services = base_vpc_config.allowedServices
        else:
            updated_vpc_services = None
        if args.IsSpecified('enable_vpc_accessible_services'):
            updated_vpc_enabled = args.enable_vpc_accessible_services
        elif base_config.vpcAccessibleServices is not None:
            updated_vpc_enabled = base_vpc_config.enableRestriction
        else:
            updated_vpc_enabled = None
        # Vpc allowed services list should only be populated if enable restrictions
        # is set to true.
        if updated_vpc_enabled is None:
            updated_vpc_services = None
        elif not updated_vpc_enabled:
            updated_vpc_services = []

        return client.PatchDryRunConfig(
            perimeter_ref,
            resources=updated_resources,
            levels=updated_access_levels,
            restricted_services=updated_restricted_services,
            vpc_allowed_services=updated_vpc_services,
            enable_vpc_accessible_services=updated_vpc_enabled,
            ingress_policies=perimeters.ParseUpdateDirectionalPoliciesArgs(
                args, 'ingress-policies'),
            egress_policies=perimeters.ParseUpdateDirectionalPoliciesArgs(
                args, 'egress-policies'))
Пример #3
0
 def Run(self, args):
     client = zones_api.Client(version=self._API_VERSION)
     messages = util.GetMessages(version=self._API_VERSION)
     perimeter_ref = args.CONCEPTS.perimeter.Parse()
     policies.ValidateAccessPolicyArg(perimeter_ref, args)
     original_perimeter = client.Get(perimeter_ref)
     base_config = _GetBaseConfig(original_perimeter)
     if _IsFieldSpecified('resources', args):
         updated_resources = repeated.ParsePrimitiveArgs(
             args, 'resources', lambda: base_config.resources or [])
     else:
         updated_resources = base_config.resources
     if _IsFieldSpecified('restricted_services', args):
         updated_restricted_services = repeated.ParsePrimitiveArgs(
             args, 'restricted-services',
             lambda: base_config.restrictedServices or [])
     else:
         updated_restricted_services = base_config.restrictedServices
     if _IsFieldSpecified('access_levels', args):
         updated_access_levels = repeated.ParsePrimitiveArgs(
             args, 'access-levels', lambda: base_config.accessLevels or [])
     else:
         updated_access_levels = base_config.accessLevels
     base_vpc_config = base_config.vpcAccessibleServices
     if base_vpc_config is None:
         base_vpc_config = messages.VpcAccessibleServices()
     if _IsFieldSpecified('vpc_allowed_services', args):
         updated_vpc_services = repeated.ParsePrimitiveArgs(
             args, 'vpc-allowed-services',
             lambda: base_vpc_config.allowedServices or [])
     elif base_config.vpcAccessibleServices is not None:
         updated_vpc_services = base_vpc_config.allowedServices
     else:
         updated_vpc_services = None
     if args.IsSpecified('enable_vpc_accessible_services'):
         updated_vpc_enabled = args.enable_vpc_accessible_services
     elif base_config.vpcAccessibleServices is not None:
         updated_vpc_enabled = base_vpc_config.enableRestriction
     else:
         updated_vpc_enabled = None
     return client.PatchDryRunConfig(
         perimeter_ref,
         resources=updated_resources,
         levels=updated_access_levels,
         restricted_services=updated_restricted_services,
         vpc_allowed_services=updated_vpc_services,
         enable_vpc_accessible_services=updated_vpc_enabled,
         ingress_policies=perimeters.ParseUpdateDirectionalPoliciesArgs(
             args, self._API_VERSION, 'ingress-policies'),
         egress_policies=perimeters.ParseUpdateDirectionalPoliciesArgs(
             args, self._API_VERSION, 'egress-policies'))