github.com/cs3org/reva/v2@v2.27.7/pkg/storage/fs/s3ng/option.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package s3ng 20 21 import ( 22 "github.com/mitchellh/mapstructure" 23 "github.com/pkg/errors" 24 ) 25 26 // Option defines a single option function. 27 type Option func(o *Options) 28 29 // Options defines the available options for this package. 30 type Options struct { 31 32 // Endpoint of the s3 blobstore 33 S3Endpoint string `mapstructure:"s3.endpoint"` 34 35 // Region of the s3 blobstore 36 S3Region string `mapstructure:"s3.region"` 37 38 // Bucket of the s3 blobstore 39 S3Bucket string `mapstructure:"s3.bucket"` 40 41 // Access key for the s3 blobstore 42 S3AccessKey string `mapstructure:"s3.access_key"` 43 44 // Secret key for the s3 blobstore 45 S3SecretKey string `mapstructure:"s3.secret_key"` 46 47 // disable sending content sha256 48 DisableContentSha256 bool `mapstructure:"s3.disable_content_sha254"` 49 50 // disable multipart uploads 51 DisableMultipart bool `mapstructure:"s3.disable_multipart"` 52 53 // enable sending content md5, defaults to true if unset 54 SendContentMd5 bool `mapstructure:"s3.send_content_md5"` 55 56 // use concurrent stream parts 57 ConcurrentStreamParts bool `mapstructure:"s3.concurrent_stream_parts"` 58 59 // number of concurrent uploads 60 NumThreads uint `mapstructure:"s3.num_threads"` 61 62 // part size for concurrent uploads 63 PartSize uint64 `mapstructure:"s3.part_size"` 64 } 65 66 // S3ConfigComplete return true if all required s3 fields are set 67 func (o *Options) S3ConfigComplete() bool { 68 return o.S3Endpoint != "" && 69 o.S3Region != "" && 70 o.S3Bucket != "" && 71 o.S3AccessKey != "" && 72 o.S3SecretKey != "" 73 } 74 75 func parseConfig(m map[string]interface{}) (*Options, error) { 76 o := &Options{} 77 if err := mapstructure.Decode(m, o); err != nil { 78 err = errors.Wrap(err, "error decoding conf") 79 return nil, err 80 } 81 82 // if unset we set these defaults 83 if m["s3.send_content_md5"] == nil { 84 o.SendContentMd5 = true 85 } 86 if m["s3.concurrent_stream_parts"] == nil { 87 o.ConcurrentStreamParts = true 88 } 89 if m["s3.num_threads"] == nil { 90 o.NumThreads = 4 91 } 92 return o, nil 93 }