Skip to content
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

Storage clients add new builder: NewWithEndpoint() to allow build client with a custom endpoint #78

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions storage/2020-08-04/blob/accounts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Example() error {
accountName := "storageaccount1"

// e.g. https://github.com/tombuildsstuff/giovanni/blob/76f5f686c99ecdcc3fa533a0330d0e1aacb1c327/example/azuread-auth/main.go#L54
client, err := buildClient()
client, err := buildClient(accountName)
if err != nil {
return fmt.Errorf("error building client: %s", err)
}
Expand All @@ -39,19 +39,19 @@ func Example() error {
},
}

_, err = client.SetServiceProperties(ctx, accountName, input)
_, err = client.SetServiceProperties(ctx, input)
if err != nil {
return fmt.Errorf("error setting properties: %s", err)
}

time.Sleep(2 * time.Second)

_, err = accountsClient.GetServiceProperties(ctx, accountName)
_, err = accountsClient.GetServiceProperties(ctx)
if err != nil {
return fmt.Errorf("error getting properties: %s", err)
}

return nil
}

```
```
21 changes: 15 additions & 6 deletions storage/2020-08-04/blob/accounts/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@ package accounts
import (
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
)

// Client is the base client for Blob Storage Blobs.
type Client struct {
autorest.Client
BaseURI string
endpoint string
}

// New creates an instance of the Client client.
func New() Client {
return NewWithEnvironment(azure.PublicCloud)
func New(accountName string) Client {
return NewWithEnvironment(accountName, azure.PublicCloud)
}

// NewWithBaseURI creates an instance of the Client client.
func NewWithEnvironment(environment azure.Environment) Client {
func NewWithEnvironment(accountName string, environment azure.Environment) Client {
return Client{
Client: autorest.NewClientWithUserAgent(UserAgent()),
BaseURI: environment.StorageEndpointSuffix,
Client: autorest.NewClientWithUserAgent(UserAgent()),
endpoint: endpoints.BuildBlobEndpoint(environment.StorageEndpointSuffix, accountName),
}
}

// NewWithEndpoint creates an instance of the Client client with the endpoint specified.
func NewWithEndpoint(endpoint string) Client {
return Client{
Client: autorest.NewClientWithUserAgent(UserAgent()),
endpoint: endpoint,
}
}
14 changes: 4 additions & 10 deletions storage/2020-08-04/blob/accounts/get_service_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/validation"
"github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
)

type GetServicePropertiesResult struct {
Expand All @@ -18,7 +16,7 @@ type GetServicePropertiesResult struct {
}

// GetServicePropertiesPreparer prepares the GetServiceProperties request.
func (client Client) GetServicePropertiesPreparer(ctx context.Context, accountName string) (*http.Request, error) {
func (client Client) GetServicePropertiesPreparer(ctx context.Context) (*http.Request, error) {
queryParameters := map[string]interface{}{
"restype": "service",
"comp": "properties",
Expand All @@ -30,7 +28,7 @@ func (client Client) GetServicePropertiesPreparer(ctx context.Context, accountNa

preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)),
autorest.WithBaseURL(client.endpoint),
autorest.WithHeaders(headers),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
Expand All @@ -56,12 +54,8 @@ func (client Client) GetServicePropertiesResponder(resp *http.Response) (result
return
}

func (client Client) GetServiceProperties(ctx context.Context, accountName string) (result GetServicePropertiesResult, err error) {
if accountName == "" {
return result, validation.NewError("accounts.Client", "GetServiceProperties", "`accountName` cannot be an empty string.")
}

req, err := client.GetServicePropertiesPreparer(ctx, accountName)
func (client Client) GetServiceProperties(ctx context.Context) (result GetServicePropertiesResult, err error) {
req, err := client.GetServicePropertiesPreparer(ctx)
if err != nil {
err = autorest.NewErrorWithError(err, "accounts.Client", "GetServiceProperties", nil, "Failure preparing request")
return
Expand Down
14 changes: 4 additions & 10 deletions storage/2020-08-04/blob/accounts/set_service_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/validation"
"github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
)

// SetServicePropertiesSender sends the SetServiceProperties request. The method will close the
Expand All @@ -18,7 +16,7 @@ func (client Client) SetServicePropertiesSender(req *http.Request) (*http.Respon
}

// SetServicePropertiesPreparer prepares the SetServiceProperties request.
func (client Client) SetServicePropertiesPreparer(ctx context.Context, accountName string, input StorageServiceProperties) (*http.Request, error) {
func (client Client) SetServicePropertiesPreparer(ctx context.Context, input StorageServiceProperties) (*http.Request, error) {
queryParameters := map[string]interface{}{
"restype": "service",
"comp": "properties",
Expand All @@ -30,7 +28,7 @@ func (client Client) SetServicePropertiesPreparer(ctx context.Context, accountNa

preparer := autorest.CreatePreparer(
autorest.AsPut(),
autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)),
autorest.WithBaseURL(client.endpoint),
autorest.WithHeaders(headers),
autorest.WithXML(input),
autorest.WithQueryParameters(queryParameters))
Expand All @@ -49,12 +47,8 @@ func (client Client) SetServicePropertiesResponder(resp *http.Response) (result
return
}

func (client Client) SetServiceProperties(ctx context.Context, accountName string, input StorageServiceProperties) (result SetServicePropertiesResult, err error) {
if accountName == "" {
return result, validation.NewError("accounts.Client", "SetServiceProperties", "`accountName` cannot be an empty string.")
}

req, err := client.SetServicePropertiesPreparer(ctx, accountName, input)
func (client Client) SetServiceProperties(ctx context.Context, input StorageServiceProperties) (result SetServicePropertiesResult, err error) {
req, err := client.SetServicePropertiesPreparer(ctx, input)
if err != nil {
err = autorest.NewErrorWithError(err, "accounts.Client", "SetServiceProperties", nil, "Failure preparing request")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func TestContainerLifecycle(t *testing.T) {
}
defer client.DestroyTestResources(ctx, resourceGroup, accountName)

accountsClient := NewWithEnvironment(client.AutoRestEnvironment)
accountsClient := NewWithEnvironment(accountName, client.AutoRestEnvironment)
accountsClient.Client = client.PrepareWithStorageResourceManagerAuth(accountsClient.Client)

input := StorageServiceProperties{}
_, err = accountsClient.SetServiceProperties(ctx, accountName, input)
_, err = accountsClient.SetServiceProperties(ctx, input)
if err != nil {
t.Fatal(fmt.Errorf("error setting properties: %s", err))
}
Expand All @@ -59,15 +59,15 @@ func TestContainerLifecycle(t *testing.T) {
},
}

_, err = accountsClient.SetServiceProperties(ctx, accountName, input)
_, err = accountsClient.SetServiceProperties(ctx, input)
if err != nil {
t.Fatal(fmt.Errorf("error setting properties: %s", err))
}

t.Log("[DEBUG] Waiting 2 seconds..")
time.Sleep(2 * time.Second)

result, err := accountsClient.GetServiceProperties(ctx, accountName)
result, err := accountsClient.GetServiceProperties(ctx)
if err != nil {
t.Fatal(fmt.Errorf("error getting properties: %s", err))
}
Expand Down
6 changes: 3 additions & 3 deletions storage/2020-08-04/blob/blobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ func Example() error {
fileName := "example-large-file.iso"

storageAuth := autorest.NewSharedKeyLiteAuthorizer(accountName, storageAccountKey)
blobClient := blobs.New()
blobClient := blobs.New(accountName)
blobClient.Client.Authorizer = storageAuth

ctx := context.TODO()
copyInput := blobs.CopyInput{
CopySource: "http://releases.ubuntu.com/14.04/ubuntu-14.04.6-desktop-amd64.iso",
}
refreshInterval := 5 * time.Second
if err := blobClient.CopyAndWait(ctx, accountName, containerName, fileName, copyInput, refreshInterval); err != nil {
if err := blobClient.CopyAndWait(ctx, containerName, fileName, copyInput, refreshInterval); err != nil {
return fmt.Errorf("Error copying: %s", err)
}

return nil
}

```
```
66 changes: 33 additions & 33 deletions storage/2020-08-04/blob/blobs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ import (
)

type StorageBlob interface {
AppendBlock(ctx context.Context, accountName, containerName, blobName string, input AppendBlockInput) (result AppendBlockResult, err error)
Copy(ctx context.Context, accountName, containerName, blobName string, input CopyInput) (result CopyResult, err error)
AbortCopy(ctx context.Context, accountName, containerName, blobName string, input AbortCopyInput) (result autorest.Response, err error)
CopyAndWait(ctx context.Context, accountName, containerName, blobName string, input CopyInput, pollingInterval time.Duration) error
Delete(ctx context.Context, accountName, containerName, blobName string, input DeleteInput) (result autorest.Response, err error)
DeleteSnapshot(ctx context.Context, accountName, containerName, blobName string, input DeleteSnapshotInput) (result autorest.Response, err error)
DeleteSnapshots(ctx context.Context, accountName, containerName, blobName string, input DeleteSnapshotsInput) (result autorest.Response, err error)
Get(ctx context.Context, accountName, containerName, blobName string, input GetInput) (result GetResult, err error)
GetBlockList(ctx context.Context, accountName, containerName, blobName string, input GetBlockListInput) (result GetBlockListResult, err error)
GetPageRanges(ctx context.Context, accountName, containerName, blobName string, input GetPageRangesInput) (result GetPageRangesResult, err error)
IncrementalCopyBlob(ctx context.Context, accountName, containerName, blobName string, input IncrementalCopyBlobInput) (result autorest.Response, err error)
AcquireLease(ctx context.Context, accountName, containerName, blobName string, input AcquireLeaseInput) (result AcquireLeaseResult, err error)
BreakLease(ctx context.Context, accountName, containerName, blobName string, input BreakLeaseInput) (result autorest.Response, err error)
ChangeLease(ctx context.Context, accountName, containerName, blobName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error)
ReleaseLease(ctx context.Context, accountName, containerName, blobName, leaseID string) (result autorest.Response, err error)
RenewLease(ctx context.Context, accountName, containerName, blobName, leaseID string) (result autorest.Response, err error)
SetMetaData(ctx context.Context, accountName, containerName, blobName string, input SetMetaDataInput) (result autorest.Response, err error)
GetProperties(ctx context.Context, accountName, containerName, blobName string, input GetPropertiesInput) (result GetPropertiesResult, err error)
SetProperties(ctx context.Context, accountName, containerName, blobName string, input SetPropertiesInput) (result SetPropertiesResult, err error)
PutAppendBlob(ctx context.Context, accountName, containerName, blobName string, input PutAppendBlobInput) (result autorest.Response, err error)
PutBlock(ctx context.Context, accountName, containerName, blobName string, input PutBlockInput) (result PutBlockResult, err error)
PutBlockBlob(ctx context.Context, accountName, containerName, blobName string, input PutBlockBlobInput) (result autorest.Response, err error)
PutBlockBlobFromFile(ctx context.Context, accountName, containerName, blobName string, file *os.File, input PutBlockBlobInput) error
PutBlockList(ctx context.Context, accountName, containerName, blobName string, input PutBlockListInput) (result PutBlockListResult, err error)
PutBlockFromURL(ctx context.Context, accountName, containerName, blobName string, input PutBlockFromURLInput) (result PutBlockFromURLResult, err error)
PutPageBlob(ctx context.Context, accountName, containerName, blobName string, input PutPageBlobInput) (result autorest.Response, err error)
PutPageClear(ctx context.Context, accountName, containerName, blobName string, input PutPageClearInput) (result autorest.Response, err error)
PutPageUpdate(ctx context.Context, accountName, containerName, blobName string, input PutPageUpdateInput) (result PutPageUpdateResult, err error)
GetResourceID(accountName, containerName, blobName string) string
SetTier(ctx context.Context, accountName, containerName, blobName string, tier AccessTier) (result autorest.Response, err error)
Snapshot(ctx context.Context, accountName, containerName, blobName string, input SnapshotInput) (result SnapshotResult, err error)
GetSnapshotProperties(ctx context.Context, accountName, containerName, blobName string, input GetSnapshotPropertiesInput) (result GetPropertiesResult, err error)
Undelete(ctx context.Context, accountName, containerName, blobName string) (result autorest.Response, err error)
AppendBlock(ctx context.Context, containerName, blobName string, input AppendBlockInput) (result AppendBlockResult, err error)
Copy(ctx context.Context, containerName, blobName string, input CopyInput) (result CopyResult, err error)
AbortCopy(ctx context.Context, containerName, blobName string, input AbortCopyInput) (result autorest.Response, err error)
CopyAndWait(ctx context.Context, containerName, blobName string, input CopyInput, pollingInterval time.Duration) error
Delete(ctx context.Context, containerName, blobName string, input DeleteInput) (result autorest.Response, err error)
DeleteSnapshot(ctx context.Context, containerName, blobName string, input DeleteSnapshotInput) (result autorest.Response, err error)
DeleteSnapshots(ctx context.Context, containerName, blobName string, input DeleteSnapshotsInput) (result autorest.Response, err error)
Get(ctx context.Context, containerName, blobName string, input GetInput) (result GetResult, err error)
GetBlockList(ctx context.Context, containerName, blobName string, input GetBlockListInput) (result GetBlockListResult, err error)
GetPageRanges(ctx context.Context, containerName, blobName string, input GetPageRangesInput) (result GetPageRangesResult, err error)
IncrementalCopyBlob(ctx context.Context, containerName, blobName string, input IncrementalCopyBlobInput) (result autorest.Response, err error)
AcquireLease(ctx context.Context, containerName, blobName string, input AcquireLeaseInput) (result AcquireLeaseResult, err error)
BreakLease(ctx context.Context, containerName, blobName string, input BreakLeaseInput) (result autorest.Response, err error)
ChangeLease(ctx context.Context, containerName, blobName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error)
ReleaseLease(ctx context.Context, containerName, blobName, leaseID string) (result autorest.Response, err error)
RenewLease(ctx context.Context, containerName, blobName, leaseID string) (result autorest.Response, err error)
SetMetaData(ctx context.Context, containerName, blobName string, input SetMetaDataInput) (result autorest.Response, err error)
GetProperties(ctx context.Context, containerName, blobName string, input GetPropertiesInput) (result GetPropertiesResult, err error)
SetProperties(ctx context.Context, containerName, blobName string, input SetPropertiesInput) (result SetPropertiesResult, err error)
PutAppendBlob(ctx context.Context, containerName, blobName string, input PutAppendBlobInput) (result autorest.Response, err error)
PutBlock(ctx context.Context, containerName, blobName string, input PutBlockInput) (result PutBlockResult, err error)
PutBlockBlob(ctx context.Context, containerName, blobName string, input PutBlockBlobInput) (result autorest.Response, err error)
PutBlockBlobFromFile(ctx context.Context, containerName, blobName string, file *os.File, input PutBlockBlobInput) error
PutBlockList(ctx context.Context, containerName, blobName string, input PutBlockListInput) (result PutBlockListResult, err error)
PutBlockFromURL(ctx context.Context, containerName, blobName string, input PutBlockFromURLInput) (result PutBlockFromURLResult, err error)
PutPageBlob(ctx context.Context, containerName, blobName string, input PutPageBlobInput) (result autorest.Response, err error)
PutPageClear(ctx context.Context, containerName, blobName string, input PutPageClearInput) (result autorest.Response, err error)
PutPageUpdate(ctx context.Context, containerName, blobName string, input PutPageUpdateInput) (result PutPageUpdateResult, err error)
GetResourceID(containerName, blobName string) string
SetTier(ctx context.Context, containerName, blobName string, tier AccessTier) (result autorest.Response, err error)
Snapshot(ctx context.Context, containerName, blobName string, input SnapshotInput) (result SnapshotResult, err error)
GetSnapshotProperties(ctx context.Context, containerName, blobName string, input GetSnapshotPropertiesInput) (result GetPropertiesResult, err error)
Undelete(ctx context.Context, containerName, blobName string) (result autorest.Response, err error)
}
12 changes: 4 additions & 8 deletions storage/2020-08-04/blob/blobs/append_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/validation"
"github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
)

type AppendBlockInput struct {
Expand Down Expand Up @@ -56,10 +55,7 @@ type AppendBlockResult struct {
}

// AppendBlock commits a new block of data to the end of an existing append blob.
func (client Client) AppendBlock(ctx context.Context, accountName, containerName, blobName string, input AppendBlockInput) (result AppendBlockResult, err error) {
if accountName == "" {
return result, validation.NewError("blobs.Client", "AppendBlock", "`accountName` cannot be an empty string.")
}
func (client Client) AppendBlock(ctx context.Context, containerName, blobName string, input AppendBlockInput) (result AppendBlockResult, err error) {
if containerName == "" {
return result, validation.NewError("blobs.Client", "AppendBlock", "`containerName` cannot be an empty string.")
}
Expand All @@ -73,7 +69,7 @@ func (client Client) AppendBlock(ctx context.Context, accountName, containerName
return result, validation.NewError("files.Client", "PutByteRange", "`input.Content` must be at most 4MB.")
}

req, err := client.AppendBlockPreparer(ctx, accountName, containerName, blobName, input)
req, err := client.AppendBlockPreparer(ctx, containerName, blobName, input)
if err != nil {
err = autorest.NewErrorWithError(err, "blobs.Client", "AppendBlock", nil, "Failure preparing request")
return
Expand All @@ -96,7 +92,7 @@ func (client Client) AppendBlock(ctx context.Context, accountName, containerName
}

// AppendBlockPreparer prepares the AppendBlock request.
func (client Client) AppendBlockPreparer(ctx context.Context, accountName, containerName, blobName string, input AppendBlockInput) (*http.Request, error) {
func (client Client) AppendBlockPreparer(ctx context.Context, containerName, blobName string, input AppendBlockInput) (*http.Request, error) {
pathParameters := map[string]interface{}{
"containerName": autorest.Encode("path", containerName),
"blobName": autorest.Encode("path", blobName),
Expand Down Expand Up @@ -128,7 +124,7 @@ func (client Client) AppendBlockPreparer(ctx context.Context, accountName, conta

decorators := []autorest.PrepareDecorator{
autorest.AsPut(),
autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)),
autorest.WithBaseURL(client.endpoint),
autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters),
autorest.WithQueryParameters(queryParameters),
autorest.WithHeaders(headers),
Expand Down
Loading