github.com/adrianjagielak/goofys@v0.24.1-0.20230810095418-94919a5d2254/api/common/conf_gcs.go (about) 1 package common 2 3 import ( 4 "context" 5 "golang.org/x/oauth2/google" 6 ) 7 8 type GCSConfig struct { 9 Credentials *google.Credentials 10 ChunkSize int // determine the size of chunks when uploading a file to GCS 11 } 12 13 const ( 14 defaultGCSChunkSize int = 64 * 1024 * 1024 15 ) 16 17 // NewGCSConfig returns a GCS Config. 18 func NewGCSConfig() *GCSConfig { 19 // Credentials will be checked when initializing GCS bucket to create an authenticated / unauthenticated client 20 // We allow nil credentials for unauthenticated client. 21 credentials, err := google.FindDefaultCredentials(context.Background()) 22 if err == nil { 23 // authenticated config 24 return &GCSConfig{ 25 ChunkSize: defaultGCSChunkSize, 26 Credentials: credentials, 27 } 28 } else { 29 log.Debugf("Initializing an unauthenticated config: %v", err) 30 // unauthenticated config 31 return &GCSConfig{ 32 ChunkSize: defaultGCSChunkSize, 33 } 34 } 35 }