* state azure blobstorage: fail for invalid account name Signed-off-by: Tim Burkert <burkert.tim@gmail.com> * state azure blobstorage: Remove duplicated code and add error check for common entpoint Signed-off-by: Tim Burkert <burkert.tim@gmail.com> Co-authored-by: Looong Dai <long.dai@intel.com> Co-authored-by: Yaron Schneider <schneider.yaron@live.com>
This commit is contained in:
parent
3af57ca5b7
commit
44199ca4dc
|
@ -40,6 +40,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
b64 "encoding/base64"
|
b64 "encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -98,17 +99,21 @@ func (r *StateStore) Init(metadata state.Metadata) error {
|
||||||
}
|
}
|
||||||
p := azblob.NewPipeline(credential, options)
|
p := azblob.NewPipeline(credential, options)
|
||||||
|
|
||||||
var containerURL azblob.ContainerURL
|
var URL *url.URL
|
||||||
customEndpoint, ok := metadata.Properties[endpointKey]
|
customEndpoint, ok := metadata.Properties[endpointKey]
|
||||||
if ok && customEndpoint != "" {
|
if ok && customEndpoint != "" {
|
||||||
URL, parseErr := url.Parse(fmt.Sprintf("%s/%s/%s", customEndpoint, meta.accountName, meta.containerName))
|
URL, err = url.Parse(fmt.Sprintf("%s/%s/%s", customEndpoint, meta.accountName, meta.containerName))
|
||||||
if parseErr != nil {
|
|
||||||
return parseErr
|
|
||||||
}
|
|
||||||
containerURL = azblob.NewContainerURL(*URL, p)
|
|
||||||
} else {
|
} else {
|
||||||
URL, _ := url.Parse(fmt.Sprintf("https://%s.blob.%s/%s", meta.accountName, env.StorageEndpointSuffix, meta.containerName))
|
URL, err = url.Parse(fmt.Sprintf("https://%s.blob.%s/%s", meta.accountName, env.StorageEndpointSuffix, meta.containerName))
|
||||||
containerURL = azblob.NewContainerURL(*URL, p)
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
containerURL := azblob.NewContainerURL(*URL, p)
|
||||||
|
|
||||||
|
_, err = net.LookupHost(URL.Hostname())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
@ -46,6 +46,16 @@ func TestInit(t *testing.T) {
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
assert.Equal(t, err, fmt.Errorf("missing or empty accountName field from metadata"))
|
assert.Equal(t, err, fmt.Errorf("missing or empty accountName field from metadata"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Init with invalid account name", func(t *testing.T) {
|
||||||
|
m.Properties = map[string]string{
|
||||||
|
"accountName": "invalid-account",
|
||||||
|
"accountKey": "e+Dnvl8EOxYxV94nurVaRQ==",
|
||||||
|
"containerName": "dapr",
|
||||||
|
}
|
||||||
|
err := s.Init(m)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBlobStorageMetaData(t *testing.T) {
|
func TestGetBlobStorageMetaData(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue