diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 21:10:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 21:10:57 +0300 |
commit | 0351d9ed83635ce3258e2d09ba92b46a7cdcfa61 (patch) | |
tree | dd3c671fd8f618b87b9beeb7cf3a5b2ffa325253 /workhorse | |
parent | c59393a068f9d0113cc10ca8798d333d6a0e3d53 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'workhorse')
-rw-r--r-- | workhorse/internal/config/config.go | 16 | ||||
-rw-r--r-- | workhorse/internal/config/url_openers.go | 51 | ||||
-rw-r--r-- | workhorse/internal/config/url_openers_test.go | 117 |
3 files changed, 5 insertions, 179 deletions
diff --git a/workhorse/internal/config/config.go b/workhorse/internal/config/config.go index a7ffe1700c8..7658b7288c9 100644 --- a/workhorse/internal/config/config.go +++ b/workhorse/internal/config/config.go @@ -159,7 +159,6 @@ func (c *Config) RegisterGoCloudURLOpeners() error { if err != nil { return err } - c.ObjectStorageConfig.URLMux.RegisterBucket(azureblob.Scheme, urlOpener) } @@ -168,14 +167,13 @@ func (c *Config) RegisterGoCloudURLOpeners() error { if err != nil { return err } - c.ObjectStorageConfig.URLMux.RegisterBucket(gcsblob.Scheme, urlOpener) } return nil } -func (creds *AzureCredentials) getURLOpener() (*azureURLOpener, error) { +func (creds *AzureCredentials) getURLOpener() (*azureblob.URLOpener, error) { accountName := azureblob.AccountName(creds.AccountName) accountKey := azureblob.AccountKey(creds.AccountKey) @@ -184,14 +182,10 @@ func (creds *AzureCredentials) getURLOpener() (*azureURLOpener, error) { return nil, fmt.Errorf("error creating Azure credentials: %w", err) } - pipeline := azureblob.NewPipeline(credential, azblob.PipelineOptions{}) - - return &azureURLOpener{ - &azureblob.URLOpener{ - AccountName: accountName, - Pipeline: pipeline, - Options: azureblob.Options{Credential: credential}, - }, + return &azureblob.URLOpener{ + AccountName: accountName, + Pipeline: azureblob.NewPipeline(credential, azblob.PipelineOptions{}), + Options: azureblob.Options{Credential: credential}, }, nil } diff --git a/workhorse/internal/config/url_openers.go b/workhorse/internal/config/url_openers.go deleted file mode 100644 index d3c96ee9eef..00000000000 --- a/workhorse/internal/config/url_openers.go +++ /dev/null @@ -1,51 +0,0 @@ -package config - -import ( - "context" - "fmt" - "net/url" - - "gocloud.dev/blob" - "gocloud.dev/blob/azureblob" -) - -// This code can be removed once https://github.com/google/go-cloud/pull/2851 is merged. - -// URLOpener opens Azure URLs like "azblob://mybucket". -// -// The URL host is used as the bucket name. -// -// The following query options are supported: -// - domain: The domain name used to access the Azure Blob storage (e.g. blob.core.windows.net) -type azureURLOpener struct { - *azureblob.URLOpener -} - -func (o *azureURLOpener) OpenBucketURL(ctx context.Context, u *url.URL) (*blob.Bucket, error) { - opts := new(azureblob.Options) - *opts = o.Options - - err := setOptionsFromURLParams(u.Query(), opts) - if err != nil { - return nil, err - } - return azureblob.OpenBucket(ctx, o.Pipeline, o.AccountName, u.Host, opts) -} - -func setOptionsFromURLParams(q url.Values, opts *azureblob.Options) error { - for param, values := range q { - if len(values) > 1 { - return fmt.Errorf("multiple values of %v not allowed", param) - } - - value := values[0] - switch param { - case "domain": - opts.StorageDomain = azureblob.StorageDomain(value) - default: - return fmt.Errorf("unknown query parameter %q", param) - } - } - - return nil -} diff --git a/workhorse/internal/config/url_openers_test.go b/workhorse/internal/config/url_openers_test.go deleted file mode 100644 index 6a851cacbb8..00000000000 --- a/workhorse/internal/config/url_openers_test.go +++ /dev/null @@ -1,117 +0,0 @@ -package config - -import ( - "context" - "net/url" - "testing" - - "github.com/stretchr/testify/require" - "gocloud.dev/blob/azureblob" -) - -func TestURLOpeners(t *testing.T) { - cfg, err := LoadConfig(azureConfig) - require.NoError(t, err) - - require.NotNil(t, cfg.ObjectStorageCredentials, "Expected object storage credentials") - - require.NoError(t, cfg.RegisterGoCloudURLOpeners()) - require.NotNil(t, cfg.ObjectStorageConfig.URLMux) - - tests := []struct { - url string - valid bool - }{ - - { - url: "azblob://container/object", - valid: true, - }, - { - url: "azblob://container/object?domain=core.windows.net", - valid: true, - }, - { - url: "azblob://container/object?domain=core.windows.net&domain=test", - valid: false, - }, - { - url: "azblob://container/object?param=value", - valid: false, - }, - { - url: "s3://bucket/object", - valid: false, - }, - } - - for _, test := range tests { - t.Run(test.url, func(t *testing.T) { - ctx := context.Background() - url, err := url.Parse(test.url) - require.NoError(t, err) - - bucket, err := cfg.ObjectStorageConfig.URLMux.OpenBucketURL(ctx, url) - if bucket != nil { - defer bucket.Close() - } - - if test.valid { - require.NotNil(t, bucket) - require.NoError(t, err) - } else { - require.Error(t, err) - } - }) - } -} - -func TestTestURLOpenersForParams(t *testing.T) { - tests := []struct { - name string - currOpts azureblob.Options - query url.Values - wantOpts azureblob.Options - wantErr bool - }{ - { - name: "InvalidParam", - query: url.Values{ - "foo": {"bar"}, - }, - wantErr: true, - }, - { - name: "StorageDomain", - query: url.Values{ - "domain": {"blob.core.usgovcloudapi.net"}, - }, - wantOpts: azureblob.Options{StorageDomain: "blob.core.usgovcloudapi.net"}, - }, - { - name: "duplicate StorageDomain", - query: url.Values{ - "domain": {"blob.core.usgovcloudapi.net", "blob.core.windows.net"}, - }, - wantErr: true, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - o := &azureURLOpener{ - URLOpener: &azureblob.URLOpener{ - Options: test.currOpts, - }, - } - err := setOptionsFromURLParams(test.query, &o.Options) - - if test.wantErr { - require.NotNil(t, err) - } else { - require.Nil(t, err) - require.Equal(t, test.wantOpts, o.Options) - } - }) - } -} |