Beispiel #1
0
    def CreateBackendBucket(self, args):
        """Creates and returns the backend bucket."""
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        backend_buckets_ref = self.BACKEND_BUCKET_ARG.ResolveAsResource(
            args, holder.resources)

        enable_cdn = args.enable_cdn or False

        backend_bucket = client.messages.BackendBucket(
            description=args.description,
            name=backend_buckets_ref.Name(),
            bucketName=args.gcs_bucket_name,
            enableCdn=enable_cdn)

        backend_buckets_utils.ApplyCdnPolicyArgs(
            client,
            args,
            backend_bucket,
            support_flexible_cache_step_one=self.
            _support_flexible_cache_step_one)

        if self._support_flexible_cache_step_one:
            if args.custom_response_header is not None:
                backend_bucket.customResponseHeaders = args.custom_response_header
            if (backend_bucket.cdnPolicy is not None
                    and backend_bucket.cdnPolicy.cacheMode
                    and args.enable_cdn is not False):  # pylint: disable=g-bool-id-comparison
                backend_bucket.enableCdn = True

        return backend_bucket
Beispiel #2
0
    def Modify(self, args, existing):
        """Modifies and returns the updated backend bucket."""
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client
        replacement = encoding.CopyProtoMessage(existing)
        cleared_fields = []

        if args.IsSpecified('description'):
            replacement.description = args.description

        if args.gcs_bucket_name:
            replacement.bucketName = args.gcs_bucket_name

        if args.enable_cdn is not None:
            replacement.enableCdn = args.enable_cdn

        backend_buckets_utils.ApplyCdnPolicyArgs(
            client,
            args,
            replacement,
            is_update=True,
            cleared_fields=cleared_fields,
            support_flexible_cache_step_one=self.
            _support_flexible_cache_step_one,
            support_flexible_cache_step_two=self.
            _support_flexible_cache_step_two,
            support_negative_cache=self._support_negative_cache)

        if self._support_flexible_cache_step_one:
            if args.custom_response_header is not None:
                replacement.customResponseHeaders = args.custom_response_header
            if args.no_custom_response_headers:
                replacement.customResponseHeaders = []
            if not replacement.customResponseHeaders:
                cleared_fields.append('customResponseHeaders')
            if (replacement.cdnPolicy is not None
                    and replacement.cdnPolicy.cacheMode
                    and args.enable_cdn is not False):  # pylint: disable=g-bool-id-comparison
                replacement.enableCdn = True

        if not replacement.description:
            cleared_fields.append('description')
        return replacement, cleared_fields