github.com/minio/madmin-go/v2@v2.2.1/tier-s3.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 // TierS3 represents the remote tier configuration for AWS S3 compatible backend. 25 type TierS3 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 StorageClass string `json:",omitempty"` 33 AWSRole bool `json:",omitempty"` 34 } 35 36 // S3Options supports NewTierS3 to take variadic options 37 type S3Options func(*TierS3) error 38 39 // S3Region helper to supply optional region to NewTierS3 40 func S3Region(region string) func(s3 *TierS3) error { 41 return func(s3 *TierS3) error { 42 s3.Region = region 43 return nil 44 } 45 } 46 47 // S3Prefix helper to supply optional object prefix to NewTierS3 48 func S3Prefix(prefix string) func(s3 *TierS3) error { 49 return func(s3 *TierS3) error { 50 s3.Prefix = prefix 51 return nil 52 } 53 } 54 55 // S3Endpoint helper to supply optional endpoint to NewTierS3 56 func S3Endpoint(endpoint string) func(s3 *TierS3) error { 57 return func(s3 *TierS3) error { 58 s3.Endpoint = endpoint 59 return nil 60 } 61 } 62 63 // S3StorageClass helper to supply optional storage class to NewTierS3 64 func S3StorageClass(storageClass string) func(s3 *TierS3) error { 65 return func(s3 *TierS3) error { 66 s3.StorageClass = storageClass 67 return nil 68 } 69 } 70 71 // S3AWSRole helper to use optional AWS Role to NewTierS3 72 func S3AWSRole() func(s3 *TierS3) error { 73 return func(s3 *TierS3) error { 74 s3.AWSRole = true 75 return nil 76 } 77 } 78 79 // NewTierS3 returns a TierConfig of S3 type. Returns error if the given 80 // parameters are invalid like name is empty etc. 81 func NewTierS3(name, accessKey, secretKey, bucket string, options ...S3Options) (*TierConfig, error) { 82 if name == "" { 83 return nil, ErrTierNameEmpty 84 } 85 sc := &TierS3{ 86 AccessKey: accessKey, 87 SecretKey: secretKey, 88 Bucket: bucket, 89 // Defaults 90 Endpoint: "https://s3.amazonaws.com", 91 Region: "", 92 StorageClass: "", 93 } 94 95 for _, option := range options { 96 err := option(sc) 97 if err != nil { 98 return nil, err 99 } 100 } 101 102 return &TierConfig{ 103 Version: TierConfigVer, 104 Type: S3, 105 Name: name, 106 S3: sc, 107 }, nil 108 }