azblob: fix SAS URL with embedded container name

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2022-08-01 21:52:32 +02:00
parent e7866047aa
commit 97d5680d1e
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
2 changed files with 7 additions and 6 deletions

View file

@ -107,23 +107,24 @@ func NewAzBlobFs(connectionID, localTempDir, mountPath string, config AzBlobFsCo
if err != nil { if err != nil {
return fs, fmt.Errorf("invalid SAS URL: %w", err) return fs, fmt.Errorf("invalid SAS URL: %w", err)
} }
svc, err := azblob.NewServiceClientWithNoCredential(fs.config.SASURL.GetPayload(), clientOptions)
if err != nil {
return fs, fmt.Errorf("invalid credentials: %v", err)
}
if parts.ContainerName != "" { if parts.ContainerName != "" {
if fs.config.Container != "" && fs.config.Container != parts.ContainerName { if fs.config.Container != "" && fs.config.Container != parts.ContainerName {
return fs, fmt.Errorf("container name in SAS URL %#v and container provided %#v do not match", return fs, fmt.Errorf("container name in SAS URL %#v and container provided %#v do not match",
parts.ContainerName, fs.config.Container) parts.ContainerName, fs.config.Container)
} }
fs.config.Container = parts.ContainerName fs.config.Container = parts.ContainerName
fs.containerClient, err = svc.NewContainerClient("")
} else { } else {
if fs.config.Container == "" { if fs.config.Container == "" {
return fs, errors.New("container is required with this SAS URL") return fs, errors.New("container is required with this SAS URL")
} }
} fs.containerClient, err = svc.NewContainerClient(fs.config.Container)
svc, err := azblob.NewServiceClientWithNoCredential(fs.config.SASURL.GetPayload(), clientOptions)
if err != nil {
return fs, fmt.Errorf("invalid credentials: %v", err)
} }
fs.hasContainerAccess = false fs.hasContainerAccess = false
fs.containerClient, err = svc.NewContainerClient(fs.config.Container)
return fs, err return fs, err
} }

View file

@ -156,7 +156,7 @@ func (fs *CryptFs) Create(name string, flag int) (File, *PipeWriter, func(), err
if flag == 0 { if flag == 0 {
f, err = os.Create(name) f, err = os.Create(name)
} else { } else {
f, err = os.OpenFile(name, flag, os.ModePerm) f, err = os.OpenFile(name, flag, 0666)
} }
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, err