github.com/minio/madmin-go@v1.7.5/tier-azure.go (about) 1 // 2 // MinIO Object Storage (c) 2021 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 // TierAzure represents the remote tier configuration for Azure Blob Storage. 22 type TierAzure struct { 23 Endpoint string `json:",omitempty"` 24 AccountName string `json:",omitempty"` 25 AccountKey string `json:",omitempty"` 26 Bucket string `json:",omitempty"` 27 Prefix string `json:",omitempty"` 28 Region string `json:",omitempty"` 29 StorageClass string `json:",omitempty"` 30 } 31 32 // AzureOptions supports NewTierAzure to take variadic options 33 type AzureOptions func(*TierAzure) error 34 35 // AzurePrefix helper to supply optional object prefix to NewTierAzure 36 func AzurePrefix(prefix string) func(az *TierAzure) error { 37 return func(az *TierAzure) error { 38 az.Prefix = prefix 39 return nil 40 } 41 } 42 43 // AzureEndpoint helper to supply optional endpoint to NewTierAzure 44 func AzureEndpoint(endpoint string) func(az *TierAzure) error { 45 return func(az *TierAzure) error { 46 az.Endpoint = endpoint 47 return nil 48 } 49 } 50 51 // AzureRegion helper to supply optional region to NewTierAzure 52 func AzureRegion(region string) func(az *TierAzure) error { 53 return func(az *TierAzure) error { 54 az.Region = region 55 return nil 56 } 57 } 58 59 // AzureStorageClass helper to supply optional storage class to NewTierAzure 60 func AzureStorageClass(sc string) func(az *TierAzure) error { 61 return func(az *TierAzure) error { 62 az.StorageClass = sc 63 return nil 64 } 65 } 66 67 // NewTierAzure returns a TierConfig of Azure type. Returns error if the given 68 // parameters are invalid like name is empty etc. 69 func NewTierAzure(name, accountName, accountKey, bucket string, options ...AzureOptions) (*TierConfig, error) { 70 if name == "" { 71 return nil, ErrTierNameEmpty 72 } 73 74 az := &TierAzure{ 75 AccountName: accountName, 76 AccountKey: accountKey, 77 Bucket: bucket, 78 // Defaults 79 Endpoint: "http://blob.core.windows.net", 80 Prefix: "", 81 Region: "", 82 StorageClass: "", 83 } 84 85 for _, option := range options { 86 err := option(az) 87 if err != nil { 88 return nil, err 89 } 90 } 91 92 return &TierConfig{ 93 Version: TierConfigVer, 94 Type: Azure, 95 Name: name, 96 Azure: az, 97 }, nil 98 }