github.com/minio/madmin-go/v2@v2.2.1/tier-minio.go (about) 1 // 2 // Copyright (c) 2015-2022 MinIO, Inc. 3 // 4 // This file is part of MinIO Object Storage stack 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU Affero General Public License as 8 // published by the Free Software Foundation, either version 3 of the 9 // License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Affero General Public License for more details. 15 // 16 // You should have received a copy of the GNU Affero General Public License 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. 18 // 19 20 package madmin 21 22 //go:generate msgp -file $GOFILE 23 24 // TierMinIO represents the remote tier configuration for MinIO object storage backend. 25 type TierMinIO struct { 26 Endpoint string `json:",omitempty"` 27 AccessKey string `json:",omitempty"` 28 SecretKey string `json:",omitempty"` 29 Bucket string `json:",omitempty"` 30 Prefix string `json:",omitempty"` 31 Region string `json:",omitempty"` 32 } 33 34 // MinIOOptions supports NewTierMinIO to take variadic options 35 type MinIOOptions func(*TierMinIO) error 36 37 // MinIORegion helper to supply optional region to NewTierMinIO 38 func MinIORegion(region string) func(m *TierMinIO) error { 39 return func(m *TierMinIO) error { 40 m.Region = region 41 return nil 42 } 43 } 44 45 // MinIOPrefix helper to supply optional object prefix to NewTierMinIO 46 func MinIOPrefix(prefix string) func(m *TierMinIO) error { 47 return func(m *TierMinIO) error { 48 m.Prefix = prefix 49 return nil 50 } 51 } 52 53 func NewTierMinIO(name, endpoint, accessKey, secretKey, bucket string, options ...MinIOOptions) (*TierConfig, error) { 54 if name == "" { 55 return nil, ErrTierNameEmpty 56 } 57 m := &TierMinIO{ 58 AccessKey: accessKey, 59 SecretKey: secretKey, 60 Bucket: bucket, 61 Endpoint: endpoint, 62 } 63 64 for _, option := range options { 65 err := option(m) 66 if err != nil { 67 return nil, err 68 } 69 } 70 71 return &TierConfig{ 72 Version: TierConfigVer, 73 Type: MinIO, 74 Name: name, 75 MinIO: m, 76 }, nil 77 }