From 0eccaf2b60eacc48b1009ea78bd8ad706b05d790 Mon Sep 17 00:00:00 2001 From: Ryan Gonzalez Date: Wed, 18 May 2022 11:31:13 -0500 Subject: [PATCH] Change Azure endpoint syntax to require a full URL Before, a "partial" URL (either "localhost:port" or an endpoint URL *without* the account name as the subdomain) would be specified, and the full one would automatically be inferred. Although this is somewhat nice, it means that the endpoint string doesn't match the official Azure syntax: https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string This also raises issues for the creation of functional tests for Azure, as the code to determine the endpoint string needs to be duplicated there as well. Instead, it's just easiest to follow Azure's own standard, and then sidestep the need for any custom logic in the functional tests. Signed-off-by: Ryan Gonzalez --- .github/workflows/ci.yml | 2 +- azure/public.go | 26 ++------------------------ man/aptly.1.ronn.tmpl | 4 ++-- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74f256df..c45e9220 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: - name: Make env: RUN_LONG_TESTS: 'yes' - AZURE_STORAGE_ENDPOINT: "127.0.0.1:10000" + AZURE_STORAGE_ENDPOINT: "http://127.0.0.1:10000/devstoreaccount1" AZURE_STORAGE_ACCOUNT: "devstoreaccount1" AZURE_STORAGE_ACCESS_KEY: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" run: | diff --git a/azure/public.go b/azure/public.go index 4c2b81af..ae349410 100644 --- a/azure/public.go +++ b/azure/public.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "fmt" "io" - "net" "net/http" "net/url" "os" @@ -30,22 +29,6 @@ var ( _ aptly.PublishedStorage = (*PublishedStorage)(nil) ) -func isEmulatorEndpoint(endpoint string) bool { - if h, _, err := net.SplitHostPort(endpoint); err == nil { - endpoint = h - } - if endpoint == "localhost" { - return true - } - // For IPv6, there could be case where SplitHostPort fails for cannot finding port. - // In this case, eliminate the '[' and ']' in the URL. - // For details about IPv6 URL, please refer to https://tools.ietf.org/html/rfc2732 - if endpoint[0] == '[' && endpoint[len(endpoint)-1] == ']' { - endpoint = endpoint[1 : len(endpoint)-1] - } - return net.ParseIP(endpoint) != nil -} - // NewPublishedStorage creates published storage from Azure storage credentials func NewPublishedStorage(accountName, accountKey, container, prefix, endpoint string) (*PublishedStorage, error) { credential, err := azblob.NewSharedKeyCredential(accountName, accountKey) @@ -54,15 +37,10 @@ func NewPublishedStorage(accountName, accountKey, container, prefix, endpoint st } if endpoint == "" { - endpoint = "blob.core.windows.net" + endpoint = fmt.Sprintf("https://%s.blob.core.windows.net", accountName) } - var url *url.URL - if isEmulatorEndpoint(endpoint) { - url, err = url.Parse(fmt.Sprintf("http://%s/%s/%s", endpoint, accountName, container)) - } else { - url, err = url.Parse(fmt.Sprintf("https://%s.%s/%s", accountName, endpoint, container)) - } + url, err := url.Parse(fmt.Sprintf("%s/%s", endpoint, container)) if err != nil { return nil, err } diff --git a/man/aptly.1.ronn.tmpl b/man/aptly.1.ronn.tmpl index df49404a..2e4ee07b 100644 --- a/man/aptly.1.ronn.tmpl +++ b/man/aptly.1.ronn.tmpl @@ -96,8 +96,8 @@ Configuration file is stored in JSON format (default values shown below): "accountName": "", "accountKey": "", "container": "repo", - "prefix": "" - "endpoint": "blob.core.windows.net" + "prefix": "", + "endpoint": "" } } }