-
Notifications
You must be signed in to change notification settings - Fork 148
feat: add support for azure blob with connection string/sas token/account key #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f5147a
0677cf6
daec4e9
f824d27
52087cc
c9460d8
05a243e
870fc84
af40d2f
aeff466
fcaee37
de395e5
4a77637
19a6514
3426092
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package io | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "net/url" | ||
|
|
||
| "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" | ||
| "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container" | ||
| "gocloud.dev/blob" | ||
| "gocloud.dev/blob/azureblob" | ||
| ) | ||
|
|
||
| // Constants for Azure configuration options | ||
| const ( | ||
| AdlsSasTokenPrefix = "adls.sas-token." | ||
| AdlsConnectionStringPrefix = "adls.connection-string." | ||
| AdlsSharedKeyAccountName = "adls.auth.shared-key.account.name" | ||
| AdlsSharedKeyAccountKey = "adls.auth.shared-key.account.key" | ||
| AdlsEndpoint = "adls.endpoint" | ||
| AdlsProtocol = "adls.protocol" | ||
|
|
||
| // Not in use yet | ||
| // AdlsReadBlockSize = "adls.read.block-size-bytes" | ||
| // AdlsWriteBlockSize = "adls.write.block-size-bytes" | ||
| ) | ||
|
|
||
| // Construct a Azure bucket from a URL | ||
| func createAzureBucket(ctx context.Context, parsed *url.URL, props map[string]string) (*blob.Bucket, error) { | ||
| adlsSasTokens := propertiesWithPrefix(props, AdlsSasTokenPrefix) | ||
| adlsConnectionStrings := propertiesWithPrefix(props, AdlsConnectionStringPrefix) | ||
|
|
||
| // Construct the client | ||
| accountName := props[AdlsSharedKeyAccountName] | ||
| endpoint := props[AdlsEndpoint] | ||
| protocol := props[AdlsProtocol] | ||
|
Comment on lines
+53
to
+54
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are there defaults we should use for these?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default value will be blob.core.windows.net and https which are returned from the sdk. We could also set it to be the default value on the iceberg-go side. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is the case here. I'd like to make the user to set this value by themselves if necessary while our default for now could only support wasb actually. |
||
|
|
||
| var client *container.Client | ||
|
|
||
| if accountName == "" { | ||
| return nil, errors.New("account name is required for azure bucket") | ||
| } | ||
|
|
||
| if accountKey, ok := props[AdlsSharedKeyAccountKey]; ok { | ||
| svcURL, err := azureblob.NewServiceURL(&azureblob.ServiceURLOptions{ | ||
| AccountName: accountName, | ||
| Protocol: protocol, | ||
| StorageDomain: endpoint, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| containerURL, err := url.JoinPath(string(svcURL), parsed.Host) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| sharedKeyCred, err := azblob.NewSharedKeyCredential(accountName, accountKey) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed azblob.NewSharedKeyCredential: %w", err) | ||
| } | ||
|
|
||
| client, err = container.NewClientWithSharedKeyCredential(containerURL, sharedKeyCred, nil) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed container.NewClientWithSharedKeyCredential: %w", err) | ||
| } | ||
| } else if sasToken, ok := adlsSasTokens[accountName]; ok { | ||
| svcURL, err := azureblob.NewServiceURL(&azureblob.ServiceURLOptions{ | ||
| AccountName: accountName, | ||
| SASToken: sasToken, | ||
| Protocol: protocol, | ||
| StorageDomain: endpoint, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| containerURL, err := url.JoinPath(string(svcURL), parsed.Host) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| client, err = container.NewClientWithNoCredential(containerURL, nil) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed container.NewClientWithNoCredential: %w", err) | ||
| } | ||
| } else if connectionString, ok := adlsConnectionStrings[accountName]; ok { | ||
| var err error | ||
| client, err = container.NewClientFromConnectionString(connectionString, parsed.Host, nil) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed container.NewClientFromConnectionString: %w", err) | ||
| } | ||
| } | ||
|
|
||
| return azureblob.OpenBucket(ctx, client, nil) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
iceberg.Propertiesinstead ofmap[string]stringThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding reference to the current iceberg.Properties struct will cause import cycle, I think that is why we don't use it in gcs.go and s3.go. Should I just move it to the io package here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, didn't realize that. that's fair. we shouldn't move it so that's fine then