-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add azure_remote_url and corresponding test.
Signed-off-by: Chris Grass <[email protected]>
- Loading branch information
Chris Grass
committed
Jan 8, 2024
1 parent
e97adba
commit 4b45194
Showing
4 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package implementations | ||
|
||
import ( | ||
"context" | ||
"github.com/flyteorg/flyte/flyteadmin/pkg/data/interfaces" | ||
"github.com/flyteorg/flyte/flyteadmin/pkg/errors" | ||
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/flyteorg/flyte/flytestdlib/storage" | ||
"github.com/flyteorg/stow" | ||
"google.golang.org/grpc/codes" | ||
"time" | ||
) | ||
|
||
type AzureRemoteURL struct { | ||
remoteDataStoreClient storage.DataStore | ||
presignDuration time.Duration | ||
} | ||
|
||
func (n *AzureRemoteURL) Get(ctx context.Context, uri string) (admin.UrlBlob, error) { | ||
metadata, err := n.remoteDataStoreClient.Head(ctx, storage.DataReference(uri)) | ||
if err != nil { | ||
return admin.UrlBlob{}, errors.NewFlyteAdminErrorf(codes.Internal, | ||
"failed to get metadata for uri: %s with err: %v", uri, err) | ||
} | ||
|
||
signedUri, err := n.remoteDataStoreClient.CreateSignedURL(ctx, storage.DataReference(uri), storage.SignedURLProperties{ | ||
Scope: stow.ClientMethodGet, | ||
ExpiresIn: n.presignDuration, | ||
}) | ||
if err != nil { | ||
return admin.UrlBlob{}, errors.NewFlyteAdminErrorf(codes.Internal, | ||
"failed to get metadata for uri: %s with err: %v", uri, err) | ||
} | ||
|
||
return admin.UrlBlob{ | ||
Url: signedUri.URL.String(), | ||
Bytes: metadata.Size(), | ||
}, nil | ||
} | ||
|
||
func NewAzureRemoteURL(remoteDataStoreClient storage.DataStore, presignDuration time.Duration) interfaces.RemoteURLInterface { | ||
return &AzureRemoteURL{ | ||
remoteDataStoreClient: remoteDataStoreClient, | ||
presignDuration: presignDuration, | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
flyteadmin/pkg/data/implementations/azure_remote_url_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package implementations | ||
|
||
import ( | ||
"context" | ||
commonMocks "github.com/flyteorg/flyte/flyteadmin/pkg/common/mocks" | ||
"github.com/flyteorg/flyte/flytestdlib/storage" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
type mockMetadata struct{} | ||
|
||
func (m mockMetadata) Exists() bool { | ||
return true | ||
} | ||
|
||
func (m mockMetadata) Size() int64 { | ||
return 1 | ||
} | ||
|
||
func (m mockMetadata) Etag() string { | ||
return "etag" | ||
} | ||
|
||
func TestAzureGet(t *testing.T) { | ||
inputUri := "abfs//test/data" | ||
mockStorage := commonMocks.GetMockStorageClient() | ||
mockStorage.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = | ||
func(ctx context.Context, reference storage.DataReference) (storage.Metadata, error) { | ||
return mockMetadata{}, nil | ||
} | ||
remoteUrl := AzureRemoteURL{ | ||
remoteDataStoreClient: *mockStorage, presignDuration: 1, | ||
} | ||
|
||
result, _ := remoteUrl.Get(context.TODO(), inputUri) | ||
assert.Contains(t, inputUri, result.Url) | ||
} |