From dfb1f39b577c93a4a3023733032aa97ec06f72fb Mon Sep 17 00:00:00 2001 From: Justin Griffin Date: Tue, 5 Mar 2024 11:44:08 -0500 Subject: [PATCH] Support custom endpoint for Azure remote storage tier (#19188) This commits adds support for using the `--endpoint` arg when creating a tier of type `azure`. This is needed to connect to Azure's Gov Cloud instance. For example, ``` mc ilm tier add azure TARGET TIER_NAME \ --account-name ACCOUNT \ --account-key KEY \ --bucket CONTAINER \ --endpoint https://ACCOUNT.blob.core.usgovcloudapi.net --prefix PREFIX \ --storage-class STORAGE_CLASS ``` Prior to this, the endpoint was hardcoded to `https://ACCOUNT.blob.core.windows.net`. The docs were even explicit about this, stating that `--endpoint` is: "Required for `s3` or `minio` tier types. This option has no effect for any other value of `TIER_TYPE`." Now, if the endpoint arg is present it will be used. If not, it will fall back to the same default behavior of `ACCOUNT.blob.core.windows.net`. --- cmd/warm-backend-azure.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/warm-backend-azure.go b/cmd/warm-backend-azure.go index 941c4de70..256835670 100644 --- a/cmd/warm-backend-azure.go +++ b/cmd/warm-backend-azure.go @@ -178,9 +178,17 @@ func newWarmBackendAzure(conf madmin.TierAzure, _ string) (*warmBackendAzure, er return nil, err } p := azblob.NewPipeline(credential, azblob.PipelineOptions{}) - u, err := url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net", conf.AccountName)) - if err != nil { - return nil, err + var u *url.URL + if conf.Endpoint != "" { + u, err = url.Parse(conf.Endpoint) + if err != nil { + return nil, err + } + } else { + u, err = url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net", conf.AccountName)) + if err != nil { + return nil, err + } } serviceURL := azblob.NewServiceURL(*u, p) return &warmBackendAzure{