github.com/minio/madmin-go@v1.7.5/tier-minio.go (about) 1 // 2 // MinIO Object Storage (c) 2022 MinIO, Inc. 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 madmin 18 19 //go:generate msgp -file $GOFILE 20 21 // TierMinIO represents the remote tier configuration for MinIO object storage backend. 22 type TierMinIO struct { 23 Endpoint string `json:",omitempty"` 24 AccessKey string `json:",omitempty"` 25 SecretKey string `json:",omitempty"` 26 Bucket string `json:",omitempty"` 27 Prefix string `json:",omitempty"` 28 Region string `json:",omitempty"` 29 } 30 31 // MinIOOptions supports NewTierMinIO to take variadic options 32 type MinIOOptions func(*TierMinIO) error 33 34 // MinIORegion helper to supply optional region to NewTierMinIO 35 func MinIORegion(region string) func(m *TierMinIO) error { 36 return func(m *TierMinIO) error { 37 m.Region = region 38 return nil 39 } 40 } 41 42 // MinIOPrefix helper to supply optional object prefix to NewTierMinIO 43 func MinIOPrefix(prefix string) func(m *TierMinIO) error { 44 return func(m *TierMinIO) error { 45 m.Prefix = prefix 46 return nil 47 } 48 } 49 50 func NewTierMinIO(name, endpoint, accessKey, secretKey, bucket string, options ...MinIOOptions) (*TierConfig, error) { 51 if name == "" { 52 return nil, ErrTierNameEmpty 53 } 54 m := &TierMinIO{ 55 AccessKey: accessKey, 56 SecretKey: secretKey, 57 Bucket: bucket, 58 Endpoint: endpoint, 59 } 60 61 for _, option := range options { 62 err := option(m) 63 if err != nil { 64 return nil, err 65 } 66 } 67 68 return &TierConfig{ 69 Version: TierConfigVer, 70 Type: MinIO, 71 Name: name, 72 MinIO: m, 73 }, nil 74 }