* 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"
|
||||
b64 "encoding/base64"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
|
@ -98,17 +99,21 @@ func (r *StateStore) Init(metadata state.Metadata) error {
|
|||
}
|
||||
p := azblob.NewPipeline(credential, options)
|
||||
|
||||
var containerURL azblob.ContainerURL
|
||||
var URL *url.URL
|
||||
customEndpoint, ok := metadata.Properties[endpointKey]
|
||||
if ok && customEndpoint != "" {
|
||||
URL, parseErr := url.Parse(fmt.Sprintf("%s/%s/%s", customEndpoint, meta.accountName, meta.containerName))
|
||||
if parseErr != nil {
|
||||
return parseErr
|
||||
}
|
||||
containerURL = azblob.NewContainerURL(*URL, p)
|
||||
URL, err = url.Parse(fmt.Sprintf("%s/%s/%s", customEndpoint, meta.accountName, meta.containerName))
|
||||
} else {
|
||||
URL, _ := url.Parse(fmt.Sprintf("https://%s.blob.%s/%s", meta.accountName, env.StorageEndpointSuffix, meta.containerName))
|
||||
containerURL = azblob.NewContainerURL(*URL, p)
|
||||
URL, err = url.Parse(fmt.Sprintf("https://%s.blob.%s/%s", meta.accountName, env.StorageEndpointSuffix, meta.containerName))
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
containerURL := azblob.NewContainerURL(*URL, p)
|
||||
|
||||
_, err = net.LookupHost(URL.Hostname())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
|
|
@ -46,6 +46,16 @@ func TestInit(t *testing.T) {
|
|||
assert.NotNil(t, err)
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue