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