sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/io/option.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 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 17 package io 18 19 import ( 20 "cloud.google.com/go/storage" 21 "github.com/aws/aws-sdk-go/service/s3/s3manager" 22 "gocloud.dev/blob" 23 "google.golang.org/api/googleapi" 24 ) 25 26 // WriterOptions are options for the opener Writer method 27 type WriterOptions struct { 28 BufferSize *int64 29 ContentEncoding *string 30 ContentType *string 31 Metadata map[string]string 32 PreconditionDoesNotExist *bool 33 CacheControl *string 34 } 35 36 func (wo WriterOptions) Apply(opts *WriterOptions) { 37 if wo.BufferSize != nil { 38 opts.BufferSize = wo.BufferSize 39 } 40 if wo.ContentEncoding != nil { 41 opts.ContentEncoding = wo.ContentEncoding 42 } 43 if wo.ContentType != nil { 44 opts.ContentType = wo.ContentType 45 } 46 if wo.Metadata != nil { 47 opts.Metadata = wo.Metadata 48 } 49 if wo.PreconditionDoesNotExist != nil { 50 opts.PreconditionDoesNotExist = wo.PreconditionDoesNotExist 51 } 52 if wo.CacheControl != nil { 53 opts.CacheControl = wo.CacheControl 54 } 55 } 56 57 // Apply applies the WriterOptions to storage.Writer and blob.WriterOptions 58 // Both arguments are allowed to be nil. 59 func (wo WriterOptions) apply(writer *storage.Writer, o *blob.WriterOptions) { 60 if writer != nil { 61 if wo.BufferSize != nil { 62 if *wo.BufferSize < googleapi.DefaultUploadChunkSize { 63 writer.ChunkSize = int(*wo.BufferSize) 64 } 65 } 66 if wo.ContentEncoding != nil { 67 writer.ObjectAttrs.ContentEncoding = *wo.ContentEncoding 68 } 69 if wo.ContentType != nil { 70 writer.ObjectAttrs.ContentType = *wo.ContentType 71 } 72 if wo.Metadata != nil { 73 writer.ObjectAttrs.Metadata = wo.Metadata 74 } 75 if wo.CacheControl != nil { 76 writer.ObjectAttrs.CacheControl = *wo.CacheControl 77 } 78 } 79 80 if o == nil { 81 return 82 } 83 84 if wo.BufferSize != nil { 85 // aws sdk throws an error if the BufferSize is smaller 86 // than the MinUploadPartSize 87 if *wo.BufferSize < s3manager.MinUploadPartSize { 88 o.BufferSize = int(s3manager.MinUploadPartSize) 89 } else { 90 o.BufferSize = int(*wo.BufferSize) 91 } 92 } 93 if wo.ContentEncoding != nil { 94 o.ContentEncoding = *wo.ContentEncoding 95 } 96 if wo.ContentType != nil { 97 o.ContentType = *wo.ContentType 98 } 99 if wo.Metadata != nil { 100 o.Metadata = wo.Metadata 101 } 102 if wo.CacheControl != nil { 103 o.CacheControl = *wo.CacheControl 104 } 105 } 106 107 // SignedURLOptions are options for the opener SignedURL method 108 type SignedURLOptions struct { 109 // UseGSCookieAuth defines if we should use cookie auth for GCS, see: 110 // https://cloud.google.com/storage/docs/access-control/cookie-based-authentication 111 UseGSCookieAuth bool 112 }