diff --git a/storage/2020-08-04/blob/accounts/README.md b/storage/2020-08-04/blob/accounts/README.md index 5fa24a7..0a49bd5 100644 --- a/storage/2020-08-04/blob/accounts/README.md +++ b/storage/2020-08-04/blob/accounts/README.md @@ -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) } @@ -39,14 +39,14 @@ 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) } @@ -54,4 +54,4 @@ func Example() error { return nil } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/blob/accounts/client.go b/storage/2020-08-04/blob/accounts/client.go index 0162ebb..b0312c4 100644 --- a/storage/2020-08-04/blob/accounts/client.go +++ b/storage/2020-08-04/blob/accounts/client.go @@ -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, } } diff --git a/storage/2020-08-04/blob/accounts/get_service_properties.go b/storage/2020-08-04/blob/accounts/get_service_properties.go index e622fff..0a270a3 100644 --- a/storage/2020-08-04/blob/accounts/get_service_properties.go +++ b/storage/2020-08-04/blob/accounts/get_service_properties.go @@ -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 { @@ -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", @@ -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)) @@ -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 diff --git a/storage/2020-08-04/blob/accounts/set_service_properties.go b/storage/2020-08-04/blob/accounts/set_service_properties.go index 17b7bcc..effab44 100644 --- a/storage/2020-08-04/blob/accounts/set_service_properties.go +++ b/storage/2020-08-04/blob/accounts/set_service_properties.go @@ -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 @@ -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", @@ -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)) @@ -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 diff --git a/storage/2020-08-04/blob/accounts/set_service_properties_test.go b/storage/2020-08-04/blob/accounts/set_service_properties_test.go index 8ae2c44..43b3064 100644 --- a/storage/2020-08-04/blob/accounts/set_service_properties_test.go +++ b/storage/2020-08-04/blob/accounts/set_service_properties_test.go @@ -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)) } @@ -59,7 +59,7 @@ 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)) } @@ -67,7 +67,7 @@ func TestContainerLifecycle(t *testing.T) { 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)) } diff --git a/storage/2020-08-04/blob/blobs/README.md b/storage/2020-08-04/blob/blobs/README.md index 19218cf..164a86c 100644 --- a/storage/2020-08-04/blob/blobs/README.md +++ b/storage/2020-08-04/blob/blobs/README.md @@ -28,7 +28,7 @@ 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() @@ -36,11 +36,11 @@ func Example() error { 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 } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/blob/blobs/api.go b/storage/2020-08-04/blob/blobs/api.go index 7e4f649..ddcc79c 100644 --- a/storage/2020-08-04/blob/blobs/api.go +++ b/storage/2020-08-04/blob/blobs/api.go @@ -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) } diff --git a/storage/2020-08-04/blob/blobs/append_block.go b/storage/2020-08-04/blob/blobs/append_block.go index b7705c2..50812b2 100644 --- a/storage/2020-08-04/blob/blobs/append_block.go +++ b/storage/2020-08-04/blob/blobs/append_block.go @@ -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 { @@ -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.") } @@ -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 @@ -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), @@ -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), diff --git a/storage/2020-08-04/blob/blobs/blob_append_test.go b/storage/2020-08-04/blob/blobs/blob_append_test.go index da7feb2..92b7cc1 100644 --- a/storage/2020-08-04/blob/blobs/blob_append_test.go +++ b/storage/2020-08-04/blob/blobs/blob_append_test.go @@ -32,29 +32,29 @@ func TestAppendBlobLifecycle(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - containersClient := containers.NewWithEnvironment(client.AutoRestEnvironment) + containersClient := containers.NewWithEnvironment(accountName, client.AutoRestEnvironment) containersClient.Client = client.PrepareWithStorageResourceManagerAuth(containersClient.Client) - _, err = containersClient.Create(ctx, accountName, containerName, containers.CreateInput{}) + _, err = containersClient.Create(ctx, containerName, containers.CreateInput{}) if err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } - defer containersClient.Delete(ctx, accountName, containerName) + defer containersClient.Delete(ctx, containerName) storageAuth, err := autorest.NewSharedKeyAuthorizer(accountName, testData.StorageAccountKey, autorest.SharedKeyLite) if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - blobClient := NewWithEnvironment(client.AutoRestEnvironment) + blobClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) blobClient.Client = client.PrepareWithAuthorizer(blobClient.Client, storageAuth) t.Logf("[DEBUG] Putting Append Blob..") - if _, err := blobClient.PutAppendBlob(ctx, accountName, containerName, fileName, PutAppendBlobInput{}); err != nil { + if _, err := blobClient.PutAppendBlob(ctx, containerName, fileName, PutAppendBlobInput{}); err != nil { t.Fatalf("Error putting append blob: %s", err) } t.Logf("[DEBUG] Retrieving Properties..") - props, err := blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + props, err := blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error retrieving properties: %s", err) } @@ -73,12 +73,12 @@ func TestAppendBlobLifecycle(t *testing.T) { 10, }, } - if _, err := blobClient.AppendBlock(ctx, accountName, containerName, fileName, appendInput); err != nil { + if _, err := blobClient.AppendBlock(ctx, containerName, fileName, appendInput); err != nil { t.Fatalf("Error appending first block: %s", err) } t.Logf("[DEBUG] Re-Retrieving Properties..") - props, err = blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + props, err = blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error retrieving properties: %s", err) } @@ -97,12 +97,12 @@ func TestAppendBlobLifecycle(t *testing.T) { 77, }, } - if _, err := blobClient.AppendBlock(ctx, accountName, containerName, fileName, appendInput); err != nil { + if _, err := blobClient.AppendBlock(ctx, containerName, fileName, appendInput); err != nil { t.Fatalf("Error appending Second block: %s", err) } t.Logf("[DEBUG] Re-Retrieving Properties..") - props, err = blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + props, err = blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error retrieving properties: %s", err) } @@ -111,7 +111,7 @@ func TestAppendBlobLifecycle(t *testing.T) { } t.Logf("[DEBUG] Acquiring Lease..") - leaseDetails, err := blobClient.AcquireLease(ctx, accountName, containerName, fileName, AcquireLeaseInput{ + leaseDetails, err := blobClient.AcquireLease(ctx, containerName, fileName, AcquireLeaseInput{ LeaseDuration: -1, }) if err != nil { @@ -131,12 +131,12 @@ func TestAppendBlobLifecycle(t *testing.T) { }, LeaseID: &leaseDetails.LeaseID, } - if _, err := blobClient.AppendBlock(ctx, accountName, containerName, fileName, appendInput); err != nil { + if _, err := blobClient.AppendBlock(ctx, containerName, fileName, appendInput); err != nil { t.Fatalf("Error appending Third block: %s", err) } t.Logf("[DEBUG] Re-Retrieving Properties..") - props, err = blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{ + props, err = blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{ LeaseID: &leaseDetails.LeaseID, }) if err != nil { @@ -150,12 +150,12 @@ func TestAppendBlobLifecycle(t *testing.T) { breakLeaseInput := BreakLeaseInput{ LeaseID: leaseDetails.LeaseID, } - if _, err := blobClient.BreakLease(ctx, accountName, containerName, fileName, breakLeaseInput); err != nil { + if _, err := blobClient.BreakLease(ctx, containerName, fileName, breakLeaseInput); err != nil { t.Fatalf("Error breaking lease: %s", err) } t.Logf("[DEBUG] Deleting Lease..") - if _, err := blobClient.Delete(ctx, accountName, containerName, fileName, DeleteInput{}); err != nil { + if _, err := blobClient.Delete(ctx, containerName, fileName, DeleteInput{}); err != nil { t.Fatalf("Error deleting: %s", err) } } diff --git a/storage/2020-08-04/blob/blobs/blob_page_test.go b/storage/2020-08-04/blob/blobs/blob_page_test.go index 22b552a..510143d 100644 --- a/storage/2020-08-04/blob/blobs/blob_page_test.go +++ b/storage/2020-08-04/blob/blobs/blob_page_test.go @@ -32,32 +32,32 @@ func TestPageBlobLifecycle(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - containersClient := containers.NewWithEnvironment(client.AutoRestEnvironment) + containersClient := containers.NewWithEnvironment(accountName, client.AutoRestEnvironment) containersClient.Client = client.PrepareWithStorageResourceManagerAuth(containersClient.Client) - _, err = containersClient.Create(ctx, accountName, containerName, containers.CreateInput{}) + _, err = containersClient.Create(ctx, containerName, containers.CreateInput{}) if err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } - defer containersClient.Delete(ctx, accountName, containerName) + defer containersClient.Delete(ctx, containerName) storageAuth, err := autorest.NewSharedKeyAuthorizer(accountName, testData.StorageAccountKey, autorest.SharedKeyLite) if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - blobClient := NewWithEnvironment(client.AutoRestEnvironment) + blobClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) blobClient.Client = client.PrepareWithAuthorizer(blobClient.Client, storageAuth) t.Logf("[DEBUG] Putting Page Blob..") fileSize := int64(10240000) - if _, err := blobClient.PutPageBlob(ctx, accountName, containerName, fileName, PutPageBlobInput{ + if _, err := blobClient.PutPageBlob(ctx, containerName, fileName, PutPageBlobInput{ BlobContentLengthBytes: fileSize, }); err != nil { t.Fatalf("Error putting page blob: %s", err) } t.Logf("[DEBUG] Retrieving Properties..") - props, err := blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + props, err := blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error retrieving properties: %s", err) } @@ -83,13 +83,13 @@ func TestPageBlobLifecycle(t *testing.T) { EndByte: endByte, Content: byteArray, } - if _, err := blobClient.PutPageUpdate(ctx, accountName, containerName, fileName, putPageInput); err != nil { + if _, err := blobClient.PutPageUpdate(ctx, containerName, fileName, putPageInput); err != nil { t.Fatalf("Error putting page: %s", err) } } t.Logf("[DEBUG] Deleting..") - if _, err := blobClient.Delete(ctx, accountName, containerName, fileName, DeleteInput{}); err != nil { + if _, err := blobClient.Delete(ctx, containerName, fileName, DeleteInput{}); err != nil { t.Fatalf("Error deleting: %s", err) } } diff --git a/storage/2020-08-04/blob/blobs/client.go b/storage/2020-08-04/blob/blobs/client.go index db20391..0398bec 100644 --- a/storage/2020-08-04/blob/blobs/client.go +++ b/storage/2020-08-04/blob/blobs/client.go @@ -3,23 +3,32 @@ package blobs 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, } } diff --git a/storage/2020-08-04/blob/blobs/copy.go b/storage/2020-08-04/blob/blobs/copy.go index febaab5..fdc142a 100644 --- a/storage/2020-08-04/blob/blobs/copy.go +++ b/storage/2020-08-04/blob/blobs/copy.go @@ -8,7 +8,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -114,10 +113,7 @@ type CopyResult struct { } // Copy copies a blob to a destination within the storage account asynchronously. -func (client Client) Copy(ctx context.Context, accountName, containerName, blobName string, input CopyInput) (result CopyResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "Copy", "`accountName` cannot be an empty string.") - } +func (client Client) Copy(ctx context.Context, containerName, blobName string, input CopyInput) (result CopyResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "Copy", "`containerName` cannot be an empty string.") } @@ -131,7 +127,7 @@ func (client Client) Copy(ctx context.Context, accountName, containerName, blobN return result, validation.NewError("blobs.Client", "Copy", "`input.CopySource` cannot be an empty string.") } - req, err := client.CopyPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.CopyPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "Copy", nil, "Failure preparing request") return @@ -154,7 +150,7 @@ func (client Client) Copy(ctx context.Context, accountName, containerName, blobN } // CopyPreparer prepares the Copy request. -func (client Client) CopyPreparer(ctx context.Context, accountName, containerName, blobName string, input CopyInput) (*http.Request, error) { +func (client Client) CopyPreparer(ctx context.Context, containerName, blobName string, input CopyInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -205,7 +201,7 @@ func (client Client) CopyPreparer(ctx context.Context, accountName, containerNam preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/blob/blobs/copy_abort.go b/storage/2020-08-04/blob/blobs/copy_abort.go index a992ff1..e055c82 100644 --- a/storage/2020-08-04/blob/blobs/copy_abort.go +++ b/storage/2020-08-04/blob/blobs/copy_abort.go @@ -8,7 +8,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 AbortCopyInput struct { @@ -21,10 +20,7 @@ type AbortCopyInput struct { } // AbortCopy aborts a pending Copy Blob operation, and leaves a destination blob with zero length and full metadata. -func (client Client) AbortCopy(ctx context.Context, accountName, containerName, blobName string, input AbortCopyInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "AbortCopy", "`accountName` cannot be an empty string.") - } +func (client Client) AbortCopy(ctx context.Context, containerName, blobName string, input AbortCopyInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "AbortCopy", "`containerName` cannot be an empty string.") } @@ -38,7 +34,7 @@ func (client Client) AbortCopy(ctx context.Context, accountName, containerName, return result, validation.NewError("blobs.Client", "AbortCopy", "`input.CopyID` cannot be an empty string.") } - req, err := client.AbortCopyPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.AbortCopyPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "AbortCopy", nil, "Failure preparing request") return @@ -61,7 +57,7 @@ func (client Client) AbortCopy(ctx context.Context, accountName, containerName, } // AbortCopyPreparer prepares the AbortCopy request. -func (client Client) AbortCopyPreparer(ctx context.Context, accountName, containerName, blobName string, input AbortCopyInput) (*http.Request, error) { +func (client Client) AbortCopyPreparer(ctx context.Context, containerName, blobName string, input AbortCopyInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -83,7 +79,7 @@ func (client Client) AbortCopyPreparer(ctx context.Context, accountName, contain preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/blobs/copy_and_wait.go b/storage/2020-08-04/blob/blobs/copy_and_wait.go index a1e7fa4..55c2e79 100644 --- a/storage/2020-08-04/blob/blobs/copy_and_wait.go +++ b/storage/2020-08-04/blob/blobs/copy_and_wait.go @@ -7,8 +7,8 @@ import ( ) // CopyAndWait copies a blob to a destination within the storage account and waits for it to finish copying. -func (client Client) CopyAndWait(ctx context.Context, accountName, containerName, blobName string, input CopyInput, pollingInterval time.Duration) error { - if _, err := client.Copy(ctx, accountName, containerName, blobName, input); err != nil { +func (client Client) CopyAndWait(ctx context.Context, containerName, blobName string, input CopyInput, pollingInterval time.Duration) error { + if _, err := client.Copy(ctx, containerName, blobName, input); err != nil { return fmt.Errorf("Error copying: %s", err) } @@ -16,7 +16,7 @@ func (client Client) CopyAndWait(ctx context.Context, accountName, containerName getInput := GetPropertiesInput{ LeaseID: input.LeaseID, } - getResult, err := client.GetProperties(ctx, accountName, containerName, blobName, getInput) + getResult, err := client.GetProperties(ctx, containerName, blobName, getInput) if err != nil { return fmt.Errorf("") } diff --git a/storage/2020-08-04/blob/blobs/copy_test.go b/storage/2020-08-04/blob/blobs/copy_test.go index effd599..9b8e40a 100644 --- a/storage/2020-08-04/blob/blobs/copy_test.go +++ b/storage/2020-08-04/blob/blobs/copy_test.go @@ -9,7 +9,6 @@ import ( "github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage" "github.com/Azure/go-autorest/autorest" "github.com/tombuildsstuff/giovanni/storage/2020-08-04/blob/containers" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" "github.com/tombuildsstuff/giovanni/storage/internal/testhelpers" ) @@ -34,20 +33,20 @@ func TestCopyFromExistingFile(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - containersClient := containers.NewWithEnvironment(client.AutoRestEnvironment) + containersClient := containers.NewWithEnvironment(accountName, client.AutoRestEnvironment) containersClient.Client = client.PrepareWithStorageResourceManagerAuth(containersClient.Client) - _, err = containersClient.Create(ctx, accountName, containerName, containers.CreateInput{}) + _, err = containersClient.Create(ctx, containerName, containers.CreateInput{}) if err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } - defer containersClient.Delete(ctx, accountName, containerName) + defer containersClient.Delete(ctx, containerName) storageAuth, err := autorest.NewSharedKeyAuthorizer(accountName, testData.StorageAccountKey, autorest.SharedKeyLite) if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - blobClient := NewWithEnvironment(client.AutoRestEnvironment) + blobClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) blobClient.Client = client.PrepareWithAuthorizer(blobClient.Client, storageAuth) t.Logf("[DEBUG] Copying file to Blob Storage..") @@ -56,26 +55,26 @@ func TestCopyFromExistingFile(t *testing.T) { } 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 { t.Fatalf("Error copying: %s", err) } t.Logf("[DEBUG] Duplicating that file..") copiedInput := CopyInput{ - CopySource: fmt.Sprintf("%s/%s/%s", endpoints.GetBlobEndpoint(blobClient.BaseURI, accountName), containerName, fileName), + CopySource: fmt.Sprintf("%s/%s/%s", blobClient.endpoint, containerName, fileName), } - if err := blobClient.CopyAndWait(ctx, accountName, containerName, copiedFileName, copiedInput, refreshInterval); err != nil { + if err := blobClient.CopyAndWait(ctx, containerName, copiedFileName, copiedInput, refreshInterval); err != nil { t.Fatalf("Error duplicating file: %s", err) } t.Logf("[DEBUG] Retrieving Properties for the Original File..") - props, err := blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + props, err := blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error getting properties for the original file: %s", err) } t.Logf("[DEBUG] Retrieving Properties for the Copied File..") - copiedProps, err := blobClient.GetProperties(ctx, accountName, containerName, copiedFileName, GetPropertiesInput{}) + copiedProps, err := blobClient.GetProperties(ctx, containerName, copiedFileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error getting properties for the copied file: %s", err) } @@ -85,12 +84,12 @@ func TestCopyFromExistingFile(t *testing.T) { } t.Logf("[DEBUG] Deleting copied file..") - if _, err := blobClient.Delete(ctx, accountName, containerName, copiedFileName, DeleteInput{}); err != nil { + if _, err := blobClient.Delete(ctx, containerName, copiedFileName, DeleteInput{}); err != nil { t.Fatalf("Error deleting file: %s", err) } t.Logf("[DEBUG] Deleting original file..") - if _, err := blobClient.Delete(ctx, accountName, containerName, fileName, DeleteInput{}); err != nil { + if _, err := blobClient.Delete(ctx, containerName, fileName, DeleteInput{}); err != nil { t.Fatalf("Error deleting file: %s", err) } } @@ -115,20 +114,20 @@ func TestCopyFromURL(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - containersClient := containers.NewWithEnvironment(client.AutoRestEnvironment) + containersClient := containers.NewWithEnvironment(accountName, client.AutoRestEnvironment) containersClient.Client = client.PrepareWithStorageResourceManagerAuth(containersClient.Client) - _, err = containersClient.Create(ctx, accountName, containerName, containers.CreateInput{}) + _, err = containersClient.Create(ctx, containerName, containers.CreateInput{}) if err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } - defer containersClient.Delete(ctx, accountName, containerName) + defer containersClient.Delete(ctx, containerName) storageAuth, err := autorest.NewSharedKeyAuthorizer(accountName, testData.StorageAccountKey, autorest.SharedKeyLite) if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - blobClient := NewWithEnvironment(client.AutoRestEnvironment) + blobClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) blobClient.Client = client.PrepareWithAuthorizer(blobClient.Client, storageAuth) t.Logf("[DEBUG] Copying file to Blob Storage..") @@ -137,12 +136,12 @@ func TestCopyFromURL(t *testing.T) { } 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 { t.Fatalf("Error copying: %s", err) } t.Logf("[DEBUG] Retrieving Properties..") - props, err := blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + props, err := blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error getting properties: %s", err) } @@ -152,7 +151,7 @@ func TestCopyFromURL(t *testing.T) { } t.Logf("[DEBUG] Deleting file..") - if _, err := blobClient.Delete(ctx, accountName, containerName, fileName, DeleteInput{}); err != nil { + if _, err := blobClient.Delete(ctx, containerName, fileName, DeleteInput{}); err != nil { t.Fatalf("Error deleting file: %s", err) } } diff --git a/storage/2020-08-04/blob/blobs/delete.go b/storage/2020-08-04/blob/blobs/delete.go index c1c642d..92cca9c 100644 --- a/storage/2020-08-04/blob/blobs/delete.go +++ b/storage/2020-08-04/blob/blobs/delete.go @@ -8,7 +8,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 DeleteInput struct { @@ -22,10 +21,7 @@ type DeleteInput struct { } // Delete marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. -func (client Client) Delete(ctx context.Context, accountName, containerName, blobName string, input DeleteInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, containerName, blobName string, input DeleteInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "Delete", "`containerName` cannot be an empty string.") } @@ -36,7 +32,7 @@ func (client Client) Delete(ctx context.Context, accountName, containerName, blo return result, validation.NewError("blobs.Client", "Delete", "`blobName` cannot be an empty string.") } - req, err := client.DeletePreparer(ctx, accountName, containerName, blobName, input) + req, err := client.DeletePreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "Delete", nil, "Failure preparing request") return @@ -59,7 +55,7 @@ func (client Client) Delete(ctx context.Context, accountName, containerName, blo } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName, containerName, blobName string, input DeleteInput) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, containerName, blobName string, input DeleteInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -79,7 +75,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName, containerN preparer := autorest.CreatePreparer( autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/blob/blobs/delete_snapshot.go b/storage/2020-08-04/blob/blobs/delete_snapshot.go index 18c3d4c..f38aecd 100644 --- a/storage/2020-08-04/blob/blobs/delete_snapshot.go +++ b/storage/2020-08-04/blob/blobs/delete_snapshot.go @@ -8,7 +8,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 DeleteSnapshotInput struct { @@ -21,10 +20,7 @@ type DeleteSnapshotInput struct { } // DeleteSnapshot marks a single Snapshot of a Blob for Deletion based on it's DateTime, which will be deleted during the next Garbage Collection cycle. -func (client Client) DeleteSnapshot(ctx context.Context, accountName, containerName, blobName string, input DeleteSnapshotInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "DeleteSnapshot", "`accountName` cannot be an empty string.") - } +func (client Client) DeleteSnapshot(ctx context.Context, containerName, blobName string, input DeleteSnapshotInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "DeleteSnapshot", "`containerName` cannot be an empty string.") } @@ -38,7 +34,7 @@ func (client Client) DeleteSnapshot(ctx context.Context, accountName, containerN return result, validation.NewError("blobs.Client", "DeleteSnapshot", "`input.SnapshotDateTime` cannot be an empty string.") } - req, err := client.DeleteSnapshotPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.DeleteSnapshotPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "DeleteSnapshot", nil, "Failure preparing request") return @@ -61,7 +57,7 @@ func (client Client) DeleteSnapshot(ctx context.Context, accountName, containerN } // DeleteSnapshotPreparer prepares the DeleteSnapshot request. -func (client Client) DeleteSnapshotPreparer(ctx context.Context, accountName, containerName, blobName string, input DeleteSnapshotInput) (*http.Request, error) { +func (client Client) DeleteSnapshotPreparer(ctx context.Context, containerName, blobName string, input DeleteSnapshotInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -81,7 +77,7 @@ func (client Client) DeleteSnapshotPreparer(ctx context.Context, accountName, co preparer := autorest.CreatePreparer( autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/blobs/delete_snapshots.go b/storage/2020-08-04/blob/blobs/delete_snapshots.go index e7e2b66..c2fb4cd 100644 --- a/storage/2020-08-04/blob/blobs/delete_snapshots.go +++ b/storage/2020-08-04/blob/blobs/delete_snapshots.go @@ -8,7 +8,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 DeleteSnapshotsInput struct { @@ -18,10 +17,7 @@ type DeleteSnapshotsInput struct { } // DeleteSnapshots marks all Snapshots of a Blob for Deletion, which will be deleted during the next Garbage Collection Cycle. -func (client Client) DeleteSnapshots(ctx context.Context, accountName, containerName, blobName string, input DeleteSnapshotsInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "DeleteSnapshots", "`accountName` cannot be an empty string.") - } +func (client Client) DeleteSnapshots(ctx context.Context, containerName, blobName string, input DeleteSnapshotsInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "DeleteSnapshots", "`containerName` cannot be an empty string.") } @@ -32,7 +28,7 @@ func (client Client) DeleteSnapshots(ctx context.Context, accountName, container return result, validation.NewError("blobs.Client", "DeleteSnapshots", "`blobName` cannot be an empty string.") } - req, err := client.DeleteSnapshotsPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.DeleteSnapshotsPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "DeleteSnapshots", nil, "Failure preparing request") return @@ -55,7 +51,7 @@ func (client Client) DeleteSnapshots(ctx context.Context, accountName, container } // DeleteSnapshotsPreparer prepares the DeleteSnapshots request. -func (client Client) DeleteSnapshotsPreparer(ctx context.Context, accountName, containerName, blobName string, input DeleteSnapshotsInput) (*http.Request, error) { +func (client Client) DeleteSnapshotsPreparer(ctx context.Context, containerName, blobName string, input DeleteSnapshotsInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -73,7 +69,7 @@ func (client Client) DeleteSnapshotsPreparer(ctx context.Context, accountName, c preparer := autorest.CreatePreparer( autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/blob/blobs/get.go b/storage/2020-08-04/blob/blobs/get.go index 7e0d6ee..a2dfc01 100644 --- a/storage/2020-08-04/blob/blobs/get.go +++ b/storage/2020-08-04/blob/blobs/get.go @@ -9,7 +9,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 GetInput struct { @@ -25,10 +24,7 @@ type GetResult struct { } // Get reads or downloads a blob from the system, including its metadata and properties. -func (client Client) Get(ctx context.Context, accountName, containerName, blobName string, input GetInput) (result GetResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "Get", "`accountName` cannot be an empty string.") - } +func (client Client) Get(ctx context.Context, containerName, blobName string, input GetInput) (result GetResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "Get", "`containerName` cannot be an empty string.") } @@ -45,7 +41,7 @@ func (client Client) Get(ctx context.Context, accountName, containerName, blobNa return result, validation.NewError("blobs.Client", "Get", "`input.StartByte` and `input.EndByte` must both be specified, or both be nil.") } - req, err := client.GetPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.GetPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "Get", nil, "Failure preparing request") return @@ -68,7 +64,7 @@ func (client Client) Get(ctx context.Context, accountName, containerName, blobNa } // GetPreparer prepares the Get request. -func (client Client) GetPreparer(ctx context.Context, accountName, containerName, blobName string, input GetInput) (*http.Request, error) { +func (client Client) GetPreparer(ctx context.Context, containerName, blobName string, input GetInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -84,7 +80,7 @@ func (client Client) GetPreparer(ctx context.Context, accountName, containerName preparer := autorest.CreatePreparer( autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/blob/blobs/get_block_list.go b/storage/2020-08-04/blob/blobs/get_block_list.go index 9f8120c..d36e90a 100644 --- a/storage/2020-08-04/blob/blobs/get_block_list.go +++ b/storage/2020-08-04/blob/blobs/get_block_list.go @@ -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 GetBlockListInput struct { @@ -38,10 +37,7 @@ type GetBlockListResult struct { } // GetBlockList retrieves the list of blocks that have been uploaded as part of a block blob. -func (client Client) GetBlockList(ctx context.Context, accountName, containerName, blobName string, input GetBlockListInput) (result GetBlockListResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "GetBlockList", "`accountName` cannot be an empty string.") - } +func (client Client) GetBlockList(ctx context.Context, containerName, blobName string, input GetBlockListInput) (result GetBlockListResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "GetBlockList", "`containerName` cannot be an empty string.") } @@ -52,7 +48,7 @@ func (client Client) GetBlockList(ctx context.Context, accountName, containerNam return result, validation.NewError("blobs.Client", "GetBlockList", "`blobName` cannot be an empty string.") } - req, err := client.GetBlockListPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.GetBlockListPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "GetBlockList", nil, "Failure preparing request") return @@ -75,7 +71,7 @@ func (client Client) GetBlockList(ctx context.Context, accountName, containerNam } // GetBlockListPreparer prepares the GetBlockList request. -func (client Client) GetBlockListPreparer(ctx context.Context, accountName, containerName, blobName string, input GetBlockListInput) (*http.Request, error) { +func (client Client) GetBlockListPreparer(ctx context.Context, containerName, blobName string, input GetBlockListInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -96,7 +92,7 @@ func (client Client) GetBlockListPreparer(ctx context.Context, accountName, cont preparer := autorest.CreatePreparer( autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/get_page_ranges.go b/storage/2020-08-04/blob/blobs/get_page_ranges.go index 37abf63..a2e399c 100644 --- a/storage/2020-08-04/blob/blobs/get_page_ranges.go +++ b/storage/2020-08-04/blob/blobs/get_page_ranges.go @@ -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 GetPageRangesInput struct { @@ -44,10 +43,7 @@ type PageRange struct { } // GetPageRanges returns the list of valid page ranges for a page blob or snapshot of a page blob. -func (client Client) GetPageRanges(ctx context.Context, accountName, containerName, blobName string, input GetPageRangesInput) (result GetPageRangesResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "GetPageRanges", "`accountName` cannot be an empty string.") - } +func (client Client) GetPageRanges(ctx context.Context, containerName, blobName string, input GetPageRangesInput) (result GetPageRangesResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "GetPageRanges", "`containerName` cannot be an empty string.") } @@ -61,7 +57,7 @@ func (client Client) GetPageRanges(ctx context.Context, accountName, containerNa return result, validation.NewError("blobs.Client", "GetPageRanges", "`input.StartByte` and `input.EndByte` must both be specified, or both be nil.") } - req, err := client.GetPageRangesPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.GetPageRangesPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "GetPageRanges", nil, "Failure preparing request") return @@ -84,7 +80,7 @@ func (client Client) GetPageRanges(ctx context.Context, accountName, containerNa } // GetPageRangesPreparer prepares the GetPageRanges request. -func (client Client) GetPageRangesPreparer(ctx context.Context, accountName, containerName, blobName string, input GetPageRangesInput) (*http.Request, error) { +func (client Client) GetPageRangesPreparer(ctx context.Context, containerName, blobName string, input GetPageRangesInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -108,7 +104,7 @@ func (client Client) GetPageRangesPreparer(ctx context.Context, accountName, con preparer := autorest.CreatePreparer( autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/incremental_copy_blob.go b/storage/2020-08-04/blob/blobs/incremental_copy_blob.go index 7fb7e6b..3632d30 100644 --- a/storage/2020-08-04/blob/blobs/incremental_copy_blob.go +++ b/storage/2020-08-04/blob/blobs/incremental_copy_blob.go @@ -8,7 +8,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 IncrementalCopyBlobInput struct { @@ -23,10 +22,7 @@ type IncrementalCopyBlobInput struct { // The snapshot is copied such that only the differential changes between the previously copied // snapshot are transferred to the destination. // The copied snapshots are complete copies of the original snapshot and can be read or copied from as usual. -func (client Client) IncrementalCopyBlob(ctx context.Context, accountName, containerName, blobName string, input IncrementalCopyBlobInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "IncrementalCopyBlob", "`accountName` cannot be an empty string.") - } +func (client Client) IncrementalCopyBlob(ctx context.Context, containerName, blobName string, input IncrementalCopyBlobInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "IncrementalCopyBlob", "`containerName` cannot be an empty string.") } @@ -40,7 +36,7 @@ func (client Client) IncrementalCopyBlob(ctx context.Context, accountName, conta return result, validation.NewError("blobs.Client", "IncrementalCopyBlob", "`input.CopySource` cannot be an empty string.") } - req, err := client.IncrementalCopyBlobPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.IncrementalCopyBlobPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "IncrementalCopyBlob", nil, "Failure preparing request") return @@ -63,7 +59,7 @@ func (client Client) IncrementalCopyBlob(ctx context.Context, accountName, conta } // IncrementalCopyBlobPreparer prepares the IncrementalCopyBlob request. -func (client Client) IncrementalCopyBlobPreparer(ctx context.Context, accountName, containerName, blobName string, input IncrementalCopyBlobInput) (*http.Request, error) { +func (client Client) IncrementalCopyBlobPreparer(ctx context.Context, containerName, blobName string, input IncrementalCopyBlobInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -93,7 +89,7 @@ func (client Client) IncrementalCopyBlobPreparer(ctx context.Context, accountNam preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/blobs/lease_acquire.go b/storage/2020-08-04/blob/blobs/lease_acquire.go index c4b49d7..8382955 100644 --- a/storage/2020-08-04/blob/blobs/lease_acquire.go +++ b/storage/2020-08-04/blob/blobs/lease_acquire.go @@ -8,7 +8,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 AcquireLeaseInput struct { @@ -30,10 +29,7 @@ type AcquireLeaseResult struct { } // AcquireLease establishes and manages a lock on a blob for write and delete operations. -func (client Client) AcquireLease(ctx context.Context, accountName, containerName, blobName string, input AcquireLeaseInput) (result AcquireLeaseResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "AcquireLease", "`accountName` cannot be an empty string.") - } +func (client Client) AcquireLease(ctx context.Context, containerName, blobName string, input AcquireLeaseInput) (result AcquireLeaseResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "AcquireLease", "`containerName` cannot be an empty string.") } @@ -54,7 +50,7 @@ func (client Client) AcquireLease(ctx context.Context, accountName, containerNam return result, validation.NewError("blobs.Client", "AcquireLease", "`input.LeaseDuration` must be -1 (infinite), or between 15 and 60 seconds.") } - req, err := client.AcquireLeasePreparer(ctx, accountName, containerName, blobName, input) + req, err := client.AcquireLeasePreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "AcquireLease", nil, "Failure preparing request") return @@ -77,7 +73,7 @@ func (client Client) AcquireLease(ctx context.Context, accountName, containerNam } // AcquireLeasePreparer prepares the AcquireLease request. -func (client Client) AcquireLeasePreparer(ctx context.Context, accountName, containerName, blobName string, input AcquireLeaseInput) (*http.Request, error) { +func (client Client) AcquireLeasePreparer(ctx context.Context, containerName, blobName string, input AcquireLeaseInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -103,7 +99,7 @@ func (client Client) AcquireLeasePreparer(ctx context.Context, accountName, cont preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/lease_break.go b/storage/2020-08-04/blob/blobs/lease_break.go index d564204..0113080 100644 --- a/storage/2020-08-04/blob/blobs/lease_break.go +++ b/storage/2020-08-04/blob/blobs/lease_break.go @@ -8,7 +8,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 BreakLeaseInput struct { @@ -34,10 +33,7 @@ type BreakLeaseResponse struct { } // BreakLease breaks an existing lock on a blob using the LeaseID. -func (client Client) BreakLease(ctx context.Context, accountName, containerName, blobName string, input BreakLeaseInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "BreakLease", "`accountName` cannot be an empty string.") - } +func (client Client) BreakLease(ctx context.Context, containerName, blobName string, input BreakLeaseInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "BreakLease", "`containerName` cannot be an empty string.") } @@ -51,7 +47,7 @@ func (client Client) BreakLease(ctx context.Context, accountName, containerName, return result, validation.NewError("blobs.Client", "BreakLease", "`input.LeaseID` cannot be an empty string.") } - req, err := client.BreakLeasePreparer(ctx, accountName, containerName, blobName, input) + req, err := client.BreakLeasePreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "BreakLease", nil, "Failure preparing request") return @@ -74,7 +70,7 @@ func (client Client) BreakLease(ctx context.Context, accountName, containerName, } // BreakLeasePreparer prepares the BreakLease request. -func (client Client) BreakLeasePreparer(ctx context.Context, accountName, containerName, blobName string, input BreakLeaseInput) (*http.Request, error) { +func (client Client) BreakLeasePreparer(ctx context.Context, containerName, blobName string, input BreakLeaseInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -96,7 +92,7 @@ func (client Client) BreakLeasePreparer(ctx context.Context, accountName, contai preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/lease_change.go b/storage/2020-08-04/blob/blobs/lease_change.go index c57f9db..c58bfff 100644 --- a/storage/2020-08-04/blob/blobs/lease_change.go +++ b/storage/2020-08-04/blob/blobs/lease_change.go @@ -8,7 +8,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 ChangeLeaseInput struct { @@ -23,10 +22,7 @@ type ChangeLeaseResponse struct { } // ChangeLease changes an existing lock on a blob for another lock. -func (client Client) ChangeLease(ctx context.Context, accountName, containerName, blobName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "ChangeLease", "`accountName` cannot be an empty string.") - } +func (client Client) ChangeLease(ctx context.Context, containerName, blobName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "ChangeLease", "`containerName` cannot be an empty string.") } @@ -43,7 +39,7 @@ func (client Client) ChangeLease(ctx context.Context, accountName, containerName return result, validation.NewError("blobs.Client", "ChangeLease", "`input.ProposedLeaseID` cannot be an empty string.") } - req, err := client.ChangeLeasePreparer(ctx, accountName, containerName, blobName, input) + req, err := client.ChangeLeasePreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "ChangeLease", nil, "Failure preparing request") return @@ -66,7 +62,7 @@ func (client Client) ChangeLease(ctx context.Context, accountName, containerName } // ChangeLeasePreparer prepares the ChangeLease request. -func (client Client) ChangeLeasePreparer(ctx context.Context, accountName, containerName, blobName string, input ChangeLeaseInput) (*http.Request, error) { +func (client Client) ChangeLeasePreparer(ctx context.Context, containerName, blobName string, input ChangeLeaseInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -85,7 +81,7 @@ func (client Client) ChangeLeasePreparer(ctx context.Context, accountName, conta preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/lease_release.go b/storage/2020-08-04/blob/blobs/lease_release.go index 0226cdf..fe5f973 100644 --- a/storage/2020-08-04/blob/blobs/lease_release.go +++ b/storage/2020-08-04/blob/blobs/lease_release.go @@ -8,14 +8,10 @@ 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" ) // ReleaseLease releases a lock based on the Lease ID. -func (client Client) ReleaseLease(ctx context.Context, accountName, containerName, blobName, leaseID string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "ReleaseLease", "`accountName` cannot be an empty string.") - } +func (client Client) ReleaseLease(ctx context.Context, containerName, blobName, leaseID string) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "ReleaseLease", "`containerName` cannot be an empty string.") } @@ -29,7 +25,7 @@ func (client Client) ReleaseLease(ctx context.Context, accountName, containerNam return result, validation.NewError("blobs.Client", "ReleaseLease", "`leaseID` cannot be an empty string.") } - req, err := client.ReleaseLeasePreparer(ctx, accountName, containerName, blobName, leaseID) + req, err := client.ReleaseLeasePreparer(ctx, containerName, blobName, leaseID) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "ReleaseLease", nil, "Failure preparing request") return @@ -52,7 +48,7 @@ func (client Client) ReleaseLease(ctx context.Context, accountName, containerNam } // ReleaseLeasePreparer prepares the ReleaseLease request. -func (client Client) ReleaseLeasePreparer(ctx context.Context, accountName, containerName, blobName, leaseID string) (*http.Request, error) { +func (client Client) ReleaseLeasePreparer(ctx context.Context, containerName, blobName, leaseID string) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -70,7 +66,7 @@ func (client Client) ReleaseLeasePreparer(ctx context.Context, accountName, cont preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/lease_renew.go b/storage/2020-08-04/blob/blobs/lease_renew.go index 69c495b..408da36 100644 --- a/storage/2020-08-04/blob/blobs/lease_renew.go +++ b/storage/2020-08-04/blob/blobs/lease_renew.go @@ -8,13 +8,9 @@ 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" ) -func (client Client) RenewLease(ctx context.Context, accountName, containerName, blobName, leaseID string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "RenewLease", "`accountName` cannot be an empty string.") - } +func (client Client) RenewLease(ctx context.Context, containerName, blobName, leaseID string) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "RenewLease", "`containerName` cannot be an empty string.") } @@ -28,7 +24,7 @@ func (client Client) RenewLease(ctx context.Context, accountName, containerName, return result, validation.NewError("blobs.Client", "RenewLease", "`leaseID` cannot be an empty string.") } - req, err := client.RenewLeasePreparer(ctx, accountName, containerName, blobName, leaseID) + req, err := client.RenewLeasePreparer(ctx, containerName, blobName, leaseID) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "RenewLease", nil, "Failure preparing request") return @@ -51,7 +47,7 @@ func (client Client) RenewLease(ctx context.Context, accountName, containerName, } // RenewLeasePreparer prepares the RenewLease request. -func (client Client) RenewLeasePreparer(ctx context.Context, accountName, containerName, blobName, leaseID string) (*http.Request, error) { +func (client Client) RenewLeasePreparer(ctx context.Context, containerName, blobName, leaseID string) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -69,7 +65,7 @@ func (client Client) RenewLeasePreparer(ctx context.Context, accountName, contai preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/lease_test.go b/storage/2020-08-04/blob/blobs/lease_test.go index f6b58a4..b1dd7d7 100644 --- a/storage/2020-08-04/blob/blobs/lease_test.go +++ b/storage/2020-08-04/blob/blobs/lease_test.go @@ -32,20 +32,20 @@ func TestLeaseLifecycle(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - containersClient := containers.NewWithEnvironment(client.AutoRestEnvironment) + containersClient := containers.NewWithEnvironment(accountName, client.AutoRestEnvironment) containersClient.Client = client.PrepareWithStorageResourceManagerAuth(containersClient.Client) - _, err = containersClient.Create(ctx, accountName, containerName, containers.CreateInput{}) + _, err = containersClient.Create(ctx, containerName, containers.CreateInput{}) if err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } - defer containersClient.Delete(ctx, accountName, containerName) + defer containersClient.Delete(ctx, containerName) storageAuth, err := autorest.NewSharedKeyAuthorizer(accountName, testData.StorageAccountKey, autorest.SharedKeyLite) if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - blobClient := NewWithEnvironment(client.AutoRestEnvironment) + blobClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) blobClient.Client = client.PrepareWithAuthorizer(blobClient.Client, storageAuth) t.Logf("[DEBUG] Copying file to Blob Storage..") @@ -54,17 +54,17 @@ func TestLeaseLifecycle(t *testing.T) { } 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 { t.Fatalf("Error copying: %s", err) } - defer blobClient.Delete(ctx, accountName, containerName, fileName, DeleteInput{}) + defer blobClient.Delete(ctx, containerName, fileName, DeleteInput{}) // Test begins here t.Logf("[DEBUG] Acquiring Lease..") leaseInput := AcquireLeaseInput{ LeaseDuration: -1, } - leaseInfo, err := blobClient.AcquireLease(ctx, accountName, containerName, fileName, leaseInput) + leaseInfo, err := blobClient.AcquireLease(ctx, containerName, fileName, leaseInput) if err != nil { t.Fatalf("Error acquiring lease: %s", err) } @@ -75,14 +75,14 @@ func TestLeaseLifecycle(t *testing.T) { ExistingLeaseID: leaseInfo.LeaseID, ProposedLeaseID: "31f5bb01-cdd9-4166-bcdc-95186076bde0", } - changeLeaseResult, err := blobClient.ChangeLease(ctx, accountName, containerName, fileName, changeLeaseInput) + changeLeaseResult, err := blobClient.ChangeLease(ctx, containerName, fileName, changeLeaseInput) if err != nil { t.Fatalf("Error changing lease: %s", err) } t.Logf("[DEBUG] New Lease ID: %q", changeLeaseResult.LeaseID) t.Logf("[DEBUG] Releasing Lease..") - if _, err := blobClient.ReleaseLease(ctx, accountName, containerName, fileName, changeLeaseResult.LeaseID); err != nil { + if _, err := blobClient.ReleaseLease(ctx, containerName, fileName, changeLeaseResult.LeaseID); err != nil { t.Fatalf("Error releasing lease: %s", err) } @@ -90,14 +90,14 @@ func TestLeaseLifecycle(t *testing.T) { leaseInput = AcquireLeaseInput{ LeaseDuration: 30, } - leaseInfo, err = blobClient.AcquireLease(ctx, accountName, containerName, fileName, leaseInput) + leaseInfo, err = blobClient.AcquireLease(ctx, containerName, fileName, leaseInput) if err != nil { t.Fatalf("Error acquiring lease: %s", err) } t.Logf("[DEBUG] Lease ID: %q", leaseInfo.LeaseID) t.Logf("[DEBUG] Renewing lease..") - if _, err := blobClient.RenewLease(ctx, accountName, containerName, fileName, leaseInfo.LeaseID); err != nil { + if _, err := blobClient.RenewLease(ctx, containerName, fileName, leaseInfo.LeaseID); err != nil { t.Fatalf("Error renewing lease: %s", err) } @@ -105,7 +105,7 @@ func TestLeaseLifecycle(t *testing.T) { breakLeaseInput := BreakLeaseInput{ LeaseID: leaseInfo.LeaseID, } - if _, err := blobClient.BreakLease(ctx, accountName, containerName, fileName, breakLeaseInput); err != nil { + if _, err := blobClient.BreakLease(ctx, containerName, fileName, breakLeaseInput); err != nil { t.Fatalf("Error breaking lease: %s", err) } } diff --git a/storage/2020-08-04/blob/blobs/lifecycle_test.go b/storage/2020-08-04/blob/blobs/lifecycle_test.go index 2697dd9..19913a9 100644 --- a/storage/2020-08-04/blob/blobs/lifecycle_test.go +++ b/storage/2020-08-04/blob/blobs/lifecycle_test.go @@ -38,16 +38,16 @@ func TestLifecycle(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - containersClient := containers.NewWithEnvironment(client.AutoRestEnvironment) + containersClient := containers.NewWithEnvironment(accountName, client.AutoRestEnvironment) containersClient.Client = client.PrepareWithAuthorizer(containersClient.Client, storageAuth) - _, err = containersClient.Create(ctx, accountName, containerName, containers.CreateInput{}) + _, err = containersClient.Create(ctx, containerName, containers.CreateInput{}) if err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } - defer containersClient.Delete(ctx, accountName, containerName) + defer containersClient.Delete(ctx, containerName) - blobClient := NewWithEnvironment(client.AutoRestEnvironment) + blobClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) blobClient.Client = client.PrepareWithAuthorizer(blobClient.Client, storageAuth) t.Logf("[DEBUG] Copying file to Blob Storage..") @@ -56,12 +56,12 @@ func TestLifecycle(t *testing.T) { } 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 { t.Fatalf("Error copying: %s", err) } t.Logf("[DEBUG] Retrieving Blob Properties..") - details, err := blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + details, err := blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error retrieving properties: %s", err) } @@ -79,7 +79,7 @@ func TestLifecycle(t *testing.T) { t.Logf("[DEBUG] Checking it's returned in the List API..") listInput := containers.ListBlobsInput{} - listResult, err := containersClient.ListBlobs(ctx, accountName, containerName, listInput) + listResult, err := containersClient.ListBlobs(ctx, containerName, listInput) if err != nil { t.Fatalf("Error listing blobs: %s", err) } @@ -94,12 +94,12 @@ func TestLifecycle(t *testing.T) { "hello": "there", }, } - if _, err := blobClient.SetMetaData(ctx, accountName, containerName, fileName, metaDataInput); err != nil { + if _, err := blobClient.SetMetaData(ctx, containerName, fileName, metaDataInput); err != nil { t.Fatalf("Error setting MetaData: %s", err) } t.Logf("[DEBUG] Re-retrieving Blob Properties..") - details, err = blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + details, err = blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error re-retrieving properties: %s", err) } @@ -122,7 +122,7 @@ func TestLifecycle(t *testing.T) { getBlockListInput := GetBlockListInput{ BlockListType: All, } - blockList, err := blobClient.GetBlockList(ctx, accountName, containerName, fileName, getBlockListInput) + blockList, err := blobClient.GetBlockList(ctx, containerName, fileName, getBlockListInput) if err != nil { t.Fatalf("Error retrieving Block List: %s", err) } @@ -143,12 +143,12 @@ func TestLifecycle(t *testing.T) { } for _, tier := range tiers { t.Logf("[DEBUG] Updating the Access Tier to %q..", string(tier)) - if _, err := blobClient.SetTier(ctx, accountName, containerName, fileName, tier); err != nil { + if _, err := blobClient.SetTier(ctx, containerName, fileName, tier); err != nil { t.Fatalf("Error setting the Access Tier: %s", err) } t.Logf("[DEBUG] Re-retrieving Blob Properties..") - details, err = blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + details, err = blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error re-retrieving properties: %s", err) } @@ -159,7 +159,7 @@ func TestLifecycle(t *testing.T) { } t.Logf("[DEBUG] Deleting Blob") - if _, err := blobClient.Delete(ctx, accountName, containerName, fileName, DeleteInput{}); err != nil { + if _, err := blobClient.Delete(ctx, containerName, fileName, DeleteInput{}); err != nil { t.Fatalf("Error deleting Blob: %s", err) } } diff --git a/storage/2020-08-04/blob/blobs/metadata_set.go b/storage/2020-08-04/blob/blobs/metadata_set.go index ec69152..138b1ef 100644 --- a/storage/2020-08-04/blob/blobs/metadata_set.go +++ b/storage/2020-08-04/blob/blobs/metadata_set.go @@ -9,7 +9,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -23,10 +22,7 @@ type SetMetaDataInput struct { } // SetMetaData marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. -func (client Client) SetMetaData(ctx context.Context, accountName, containerName, blobName string, input SetMetaDataInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "GetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) SetMetaData(ctx context.Context, containerName, blobName string, input SetMetaDataInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "GetProperties", "`containerName` cannot be an empty string.") } @@ -40,7 +36,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, containerName return result, validation.NewError("blobs.Client", "GetProperties", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) } - req, err := client.SetMetaDataPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.SetMetaDataPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "SetMetaData", nil, "Failure preparing request") return @@ -63,7 +59,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, containerName } // SetMetaDataPreparer prepares the SetMetaData request. -func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, containerName, blobName string, input SetMetaDataInput) (*http.Request, error) { +func (client Client) SetMetaDataPreparer(ctx context.Context, containerName, blobName string, input SetMetaDataInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -85,7 +81,7 @@ func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, conta preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/properties_get.go b/storage/2020-08-04/blob/blobs/properties_get.go index 5640687..ae71a44 100644 --- a/storage/2020-08-04/blob/blobs/properties_get.go +++ b/storage/2020-08-04/blob/blobs/properties_get.go @@ -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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -163,10 +162,7 @@ type GetPropertiesResult struct { } // GetProperties returns all user-defined metadata, standard HTTP properties, and system properties for the blob -func (client Client) GetProperties(ctx context.Context, accountName, containerName, blobName string, input GetPropertiesInput) (result GetPropertiesResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "GetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) GetProperties(ctx context.Context, containerName, blobName string, input GetPropertiesInput) (result GetPropertiesResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "GetProperties", "`containerName` cannot be an empty string.") } @@ -177,7 +173,7 @@ func (client Client) GetProperties(ctx context.Context, accountName, containerNa return result, validation.NewError("blobs.Client", "GetProperties", "`blobName` cannot be an empty string.") } - req, err := client.GetPropertiesPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.GetPropertiesPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "GetProperties", nil, "Failure preparing request") return @@ -200,7 +196,7 @@ func (client Client) GetProperties(ctx context.Context, accountName, containerNa } // GetPropertiesPreparer prepares the GetProperties request. -func (client Client) GetPropertiesPreparer(ctx context.Context, accountName, containerName, blobName string, input GetPropertiesInput) (*http.Request, error) { +func (client Client) GetPropertiesPreparer(ctx context.Context, containerName, blobName string, input GetPropertiesInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -216,7 +212,7 @@ func (client Client) GetPropertiesPreparer(ctx context.Context, accountName, con preparer := autorest.CreatePreparer( autorest.AsHead(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/blob/blobs/properties_set.go b/storage/2020-08-04/blob/blobs/properties_set.go index a8c0ed8..15255ff 100644 --- a/storage/2020-08-04/blob/blobs/properties_set.go +++ b/storage/2020-08-04/blob/blobs/properties_set.go @@ -8,7 +8,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 SetPropertiesInput struct { @@ -32,10 +31,7 @@ type SetPropertiesResult struct { } // SetProperties sets system properties on the blob. -func (client Client) SetProperties(ctx context.Context, accountName, containerName, blobName string, input SetPropertiesInput) (result SetPropertiesResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "SetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) SetProperties(ctx context.Context, containerName, blobName string, input SetPropertiesInput) (result SetPropertiesResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "SetProperties", "`containerName` cannot be an empty string.") } @@ -46,7 +42,7 @@ func (client Client) SetProperties(ctx context.Context, accountName, containerNa return result, validation.NewError("blobs.Client", "SetProperties", "`blobName` cannot be an empty string.") } - req, err := client.SetPropertiesPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.SetPropertiesPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "SetProperties", nil, "Failure preparing request") return @@ -77,7 +73,7 @@ var ( ) // SetPropertiesPreparer prepares the SetProperties request. -func (client Client) SetPropertiesPreparer(ctx context.Context, accountName, containerName, blobName string, input SetPropertiesInput) (*http.Request, error) { +func (client Client) SetPropertiesPreparer(ctx context.Context, containerName, blobName string, input SetPropertiesInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -124,7 +120,7 @@ func (client Client) SetPropertiesPreparer(ctx context.Context, accountName, con preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/put_append_blob.go b/storage/2020-08-04/blob/blobs/put_append_blob.go index ef2c502..90e71ff 100644 --- a/storage/2020-08-04/blob/blobs/put_append_blob.go +++ b/storage/2020-08-04/blob/blobs/put_append_blob.go @@ -9,7 +9,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -26,10 +25,7 @@ type PutAppendBlobInput struct { // PutAppendBlob is a wrapper around the Put API call (with a stricter input object) // which creates a new append blob, or updates the content of an existing blob. -func (client Client) PutAppendBlob(ctx context.Context, accountName, containerName, blobName string, input PutAppendBlobInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "PutAppendBlob", "`accountName` cannot be an empty string.") - } +func (client Client) PutAppendBlob(ctx context.Context, containerName, blobName string, input PutAppendBlobInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "PutAppendBlob", "`containerName` cannot be an empty string.") } @@ -43,7 +39,7 @@ func (client Client) PutAppendBlob(ctx context.Context, accountName, containerNa return result, validation.NewError("blobs.Client", "PutAppendBlob", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) } - req, err := client.PutAppendBlobPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.PutAppendBlobPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "PutAppendBlob", nil, "Failure preparing request") return @@ -66,7 +62,7 @@ func (client Client) PutAppendBlob(ctx context.Context, accountName, containerNa } // PutAppendBlobPreparer prepares the PutAppendBlob request. -func (client Client) PutAppendBlobPreparer(ctx context.Context, accountName, containerName, blobName string, input PutAppendBlobInput) (*http.Request, error) { +func (client Client) PutAppendBlobPreparer(ctx context.Context, containerName, blobName string, input PutAppendBlobInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -107,7 +103,7 @@ func (client Client) PutAppendBlobPreparer(ctx context.Context, accountName, con preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/blob/blobs/put_block.go b/storage/2020-08-04/blob/blobs/put_block.go index 6d41bda..ab9faee 100644 --- a/storage/2020-08-04/blob/blobs/put_block.go +++ b/storage/2020-08-04/blob/blobs/put_block.go @@ -8,7 +8,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 PutBlockInput struct { @@ -25,10 +24,7 @@ type PutBlockResult struct { } // PutBlock creates a new block to be committed as part of a blob. -func (client Client) PutBlock(ctx context.Context, accountName, containerName, blobName string, input PutBlockInput) (result PutBlockResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "PutBlock", "`accountName` cannot be an empty string.") - } +func (client Client) PutBlock(ctx context.Context, containerName, blobName string, input PutBlockInput) (result PutBlockResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "PutBlock", "`containerName` cannot be an empty string.") } @@ -45,7 +41,7 @@ func (client Client) PutBlock(ctx context.Context, accountName, containerName, b return result, validation.NewError("blobs.Client", "PutBlock", "`input.Content` cannot be empty.") } - req, err := client.PutBlockPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.PutBlockPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "PutBlock", nil, "Failure preparing request") return @@ -68,7 +64,7 @@ func (client Client) PutBlock(ctx context.Context, accountName, containerName, b } // PutBlockPreparer prepares the PutBlock request. -func (client Client) PutBlockPreparer(ctx context.Context, accountName, containerName, blobName string, input PutBlockInput) (*http.Request, error) { +func (client Client) PutBlockPreparer(ctx context.Context, containerName, blobName string, input PutBlockInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -93,7 +89,7 @@ func (client Client) PutBlockPreparer(ctx context.Context, accountName, containe preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers), diff --git a/storage/2020-08-04/blob/blobs/put_block_blob.go b/storage/2020-08-04/blob/blobs/put_block_blob.go index f5c1a97..7f6f315 100644 --- a/storage/2020-08-04/blob/blobs/put_block_blob.go +++ b/storage/2020-08-04/blob/blobs/put_block_blob.go @@ -9,7 +9,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -27,10 +26,7 @@ type PutBlockBlobInput struct { // PutBlockBlob is a wrapper around the Put API call (with a stricter input object) // which creates a new block append blob, or updates the content of an existing block blob. -func (client Client) PutBlockBlob(ctx context.Context, accountName, containerName, blobName string, input PutBlockBlobInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "PutBlockBlob", "`accountName` cannot be an empty string.") - } +func (client Client) PutBlockBlob(ctx context.Context, containerName, blobName string, input PutBlockBlobInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "PutBlockBlob", "`containerName` cannot be an empty string.") } @@ -47,7 +43,7 @@ func (client Client) PutBlockBlob(ctx context.Context, accountName, containerNam return result, validation.NewError("blobs.Client", "PutBlockBlob", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) } - req, err := client.PutBlockBlobPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.PutBlockBlobPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "PutBlockBlob", nil, "Failure preparing request") return @@ -70,7 +66,7 @@ func (client Client) PutBlockBlob(ctx context.Context, accountName, containerNam } // PutBlockBlobPreparer prepares the PutBlockBlob request. -func (client Client) PutBlockBlobPreparer(ctx context.Context, accountName, containerName, blobName string, input PutBlockBlobInput) (*http.Request, error) { +func (client Client) PutBlockBlobPreparer(ctx context.Context, containerName, blobName string, input PutBlockBlobInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -110,7 +106,7 @@ func (client Client) PutBlockBlobPreparer(ctx context.Context, accountName, cont decorators := []autorest.PrepareDecorator{ autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), } diff --git a/storage/2020-08-04/blob/blobs/put_block_blob_file.go b/storage/2020-08-04/blob/blobs/put_block_blob_file.go index b749949..b03b5bc 100644 --- a/storage/2020-08-04/blob/blobs/put_block_blob_file.go +++ b/storage/2020-08-04/blob/blobs/put_block_blob_file.go @@ -8,7 +8,7 @@ import ( ) // PutBlockBlobFromFile is a helper method which takes a file, and automatically chunks it up, rather than having to do this yourself -func (client Client) PutBlockBlobFromFile(ctx context.Context, accountName, containerName, blobName string, file *os.File, input PutBlockBlobInput) error { +func (client Client) PutBlockBlobFromFile(ctx context.Context, containerName, blobName string, file *os.File, input PutBlockBlobInput) error { fileInfo, err := file.Stat() if err != nil { return fmt.Errorf("Error loading file info: %s", err) @@ -26,7 +26,7 @@ func (client Client) PutBlockBlobFromFile(ctx context.Context, accountName, cont input.Content = &bytes - if _, err = client.PutBlockBlob(ctx, accountName, containerName, blobName, input); err != nil { + if _, err = client.PutBlockBlob(ctx, containerName, blobName, input); err != nil { return fmt.Errorf("Error putting bytes: %s", err) } diff --git a/storage/2020-08-04/blob/blobs/put_block_list.go b/storage/2020-08-04/blob/blobs/put_block_list.go index f805247..d4deb68 100644 --- a/storage/2020-08-04/blob/blobs/put_block_list.go +++ b/storage/2020-08-04/blob/blobs/put_block_list.go @@ -8,7 +8,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -45,10 +44,7 @@ type PutBlockListResult struct { // PutBlockList writes a blob by specifying the list of block IDs that make up the blob. // In order to be written as part of a blob, a block must have been successfully written // to the server in a prior Put Block operation. -func (client Client) PutBlockList(ctx context.Context, accountName, containerName, blobName string, input PutBlockListInput) (result PutBlockListResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "PutBlockList", "`accountName` cannot be an empty string.") - } +func (client Client) PutBlockList(ctx context.Context, containerName, blobName string, input PutBlockListInput) (result PutBlockListResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "PutBlockList", "`containerName` cannot be an empty string.") } @@ -59,7 +55,7 @@ func (client Client) PutBlockList(ctx context.Context, accountName, containerNam return result, validation.NewError("blobs.Client", "PutBlockList", "`blobName` cannot be an empty string.") } - req, err := client.PutBlockListPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.PutBlockListPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "PutBlockList", nil, "Failure preparing request") return @@ -82,7 +78,7 @@ func (client Client) PutBlockList(ctx context.Context, accountName, containerNam } // PutBlockListPreparer prepares the PutBlockList request. -func (client Client) PutBlockListPreparer(ctx context.Context, accountName, containerName, blobName string, input PutBlockListInput) (*http.Request, error) { +func (client Client) PutBlockListPreparer(ctx context.Context, containerName, blobName string, input PutBlockListInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -122,7 +118,7 @@ func (client Client) PutBlockListPreparer(ctx context.Context, accountName, cont preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers), diff --git a/storage/2020-08-04/blob/blobs/put_block_url.go b/storage/2020-08-04/blob/blobs/put_block_url.go index 95ad974..7f04da8 100644 --- a/storage/2020-08-04/blob/blobs/put_block_url.go +++ b/storage/2020-08-04/blob/blobs/put_block_url.go @@ -8,7 +8,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 PutBlockFromURLInput struct { @@ -26,10 +25,7 @@ type PutBlockFromURLResult struct { } // PutBlockFromURL creates a new block to be committed as part of a blob where the contents are read from a URL -func (client Client) PutBlockFromURL(ctx context.Context, accountName, containerName, blobName string, input PutBlockFromURLInput) (result PutBlockFromURLResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "PutBlockFromURL", "`accountName` cannot be an empty string.") - } +func (client Client) PutBlockFromURL(ctx context.Context, containerName, blobName string, input PutBlockFromURLInput) (result PutBlockFromURLResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "PutBlockFromURL", "`containerName` cannot be an empty string.") } @@ -46,7 +42,7 @@ func (client Client) PutBlockFromURL(ctx context.Context, accountName, container return result, validation.NewError("blobs.Client", "PutBlockFromURL", "`input.CopySource` cannot be an empty string.") } - req, err := client.PutBlockFromURLPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.PutBlockFromURLPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "PutBlockFromURL", nil, "Failure preparing request") return @@ -69,7 +65,7 @@ func (client Client) PutBlockFromURL(ctx context.Context, accountName, container } // PutBlockFromURLPreparer prepares the PutBlockFromURL request. -func (client Client) PutBlockFromURLPreparer(ctx context.Context, accountName, containerName, blobName string, input PutBlockFromURLInput) (*http.Request, error) { +func (client Client) PutBlockFromURLPreparer(ctx context.Context, containerName, blobName string, input PutBlockFromURLInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -97,7 +93,7 @@ func (client Client) PutBlockFromURLPreparer(ctx context.Context, accountName, c preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/blobs/put_page_blob.go b/storage/2020-08-04/blob/blobs/put_page_blob.go index 4cfba95..75fc076 100644 --- a/storage/2020-08-04/blob/blobs/put_page_blob.go +++ b/storage/2020-08-04/blob/blobs/put_page_blob.go @@ -8,7 +8,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -29,10 +28,7 @@ type PutPageBlobInput struct { // PutPageBlob is a wrapper around the Put API call (with a stricter input object) // which creates a new block blob, or updates the content of an existing page blob. -func (client Client) PutPageBlob(ctx context.Context, accountName, containerName, blobName string, input PutPageBlobInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "PutPageBlob", "`accountName` cannot be an empty string.") - } +func (client Client) PutPageBlob(ctx context.Context, containerName, blobName string, input PutPageBlobInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "PutPageBlob", "`containerName` cannot be an empty string.") } @@ -46,7 +42,7 @@ func (client Client) PutPageBlob(ctx context.Context, accountName, containerName return result, validation.NewError("blobs.Client", "PutPageBlob", "`input.BlobContentLengthBytes` must be aligned to a 512-byte boundary.") } - req, err := client.PutPageBlobPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.PutPageBlobPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "PutPageBlob", nil, "Failure preparing request") return @@ -69,7 +65,7 @@ func (client Client) PutPageBlob(ctx context.Context, accountName, containerName } // PutPageBlobPreparer prepares the PutPageBlob request. -func (client Client) PutPageBlobPreparer(ctx context.Context, accountName, containerName, blobName string, input PutPageBlobInput) (*http.Request, error) { +func (client Client) PutPageBlobPreparer(ctx context.Context, containerName, blobName string, input PutPageBlobInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -121,7 +117,7 @@ func (client Client) PutPageBlobPreparer(ctx context.Context, accountName, conta preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/blob/blobs/put_page_clear.go b/storage/2020-08-04/blob/blobs/put_page_clear.go index 59feaa5..b24f9ab 100644 --- a/storage/2020-08-04/blob/blobs/put_page_clear.go +++ b/storage/2020-08-04/blob/blobs/put_page_clear.go @@ -9,7 +9,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 PutPageClearInput struct { @@ -20,10 +19,7 @@ type PutPageClearInput struct { } // PutPageClear clears a range of pages within a page blob. -func (client Client) PutPageClear(ctx context.Context, accountName, containerName, blobName string, input PutPageClearInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "PutPageClear", "`accountName` cannot be an empty string.") - } +func (client Client) PutPageClear(ctx context.Context, containerName, blobName string, input PutPageClearInput) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "PutPageClear", "`containerName` cannot be an empty string.") } @@ -40,7 +36,7 @@ func (client Client) PutPageClear(ctx context.Context, accountName, containerNam return result, validation.NewError("blobs.Client", "PutPageClear", "`input.EndByte` must be greater than 0.") } - req, err := client.PutPageClearPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.PutPageClearPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "PutPageClear", nil, "Failure preparing request") return @@ -63,7 +59,7 @@ func (client Client) PutPageClear(ctx context.Context, accountName, containerNam } // PutPageClearPreparer prepares the PutPageClear request. -func (client Client) PutPageClearPreparer(ctx context.Context, accountName, containerName, blobName string, input PutPageClearInput) (*http.Request, error) { +func (client Client) PutPageClearPreparer(ctx context.Context, containerName, blobName string, input PutPageClearInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -85,7 +81,7 @@ func (client Client) PutPageClearPreparer(ctx context.Context, accountName, cont preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/blobs/put_page_update.go b/storage/2020-08-04/blob/blobs/put_page_update.go index 3799381..a2161ab 100644 --- a/storage/2020-08-04/blob/blobs/put_page_update.go +++ b/storage/2020-08-04/blob/blobs/put_page_update.go @@ -9,7 +9,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 PutPageUpdateInput struct { @@ -36,10 +35,7 @@ type PutPageUpdateResult struct { } // PutPageUpdate writes a range of pages to a page blob. -func (client Client) PutPageUpdate(ctx context.Context, accountName, containerName, blobName string, input PutPageUpdateInput) (result PutPageUpdateResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "PutPageUpdate", "`accountName` cannot be an empty string.") - } +func (client Client) PutPageUpdate(ctx context.Context, containerName, blobName string, input PutPageUpdateInput) (result PutPageUpdateResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "PutPageUpdate", "`containerName` cannot be an empty string.") } @@ -62,7 +58,7 @@ func (client Client) PutPageUpdate(ctx context.Context, accountName, containerNa return result, validation.NewError("blobs.Client", "PutPageUpdate", fmt.Sprintf("Content Size was defined as %d but got %d.", expectedSize, actualSize)) } - req, err := client.PutPageUpdatePreparer(ctx, accountName, containerName, blobName, input) + req, err := client.PutPageUpdatePreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "PutPageUpdate", nil, "Failure preparing request") return @@ -85,7 +81,7 @@ func (client Client) PutPageUpdate(ctx context.Context, accountName, containerNa } // PutPageUpdatePreparer prepares the PutPageUpdate request. -func (client Client) PutPageUpdatePreparer(ctx context.Context, accountName, containerName, blobName string, input PutPageUpdateInput) (*http.Request, error) { +func (client Client) PutPageUpdatePreparer(ctx context.Context, containerName, blobName string, input PutPageUpdateInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -129,7 +125,7 @@ func (client Client) PutPageUpdatePreparer(ctx context.Context, accountName, con preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers), diff --git a/storage/2020-08-04/blob/blobs/resource_id.go b/storage/2020-08-04/blob/blobs/resource_id.go index 4057cf2..5981718 100644 --- a/storage/2020-08-04/blob/blobs/resource_id.go +++ b/storage/2020-08-04/blob/blobs/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given Blob // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, containerName, blobName string) string { - domain := endpoints.GetBlobEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s/%s", domain, containerName, blobName) +func (client Client) GetResourceID(containerName, blobName string) string { + return fmt.Sprintf("%s/%s/%s", client.endpoint, containerName, blobName) } type ResourceID struct { diff --git a/storage/2020-08-04/blob/blobs/resource_id_test.go b/storage/2020-08-04/blob/blobs/resource_id_test.go index 02732c2..67c5f6f 100644 --- a/storage/2020-08-04/blob/blobs/resource_id_test.go +++ b/storage/2020-08-04/blob/blobs/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "container1", "blob1.vhd") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("container1", "blob1.vhd") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } diff --git a/storage/2020-08-04/blob/blobs/set_tier.go b/storage/2020-08-04/blob/blobs/set_tier.go index dd0f0b8..e2dca4b 100644 --- a/storage/2020-08-04/blob/blobs/set_tier.go +++ b/storage/2020-08-04/blob/blobs/set_tier.go @@ -8,14 +8,10 @@ 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" ) // SetTier sets the tier on a blob. -func (client Client) SetTier(ctx context.Context, accountName, containerName, blobName string, tier AccessTier) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "SetTier", "`accountName` cannot be an empty string.") - } +func (client Client) SetTier(ctx context.Context, containerName, blobName string, tier AccessTier) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "SetTier", "`containerName` cannot be an empty string.") } @@ -26,7 +22,7 @@ func (client Client) SetTier(ctx context.Context, accountName, containerName, bl return result, validation.NewError("blobs.Client", "SetTier", "`blobName` cannot be an empty string.") } - req, err := client.SetTierPreparer(ctx, accountName, containerName, blobName, tier) + req, err := client.SetTierPreparer(ctx, containerName, blobName, tier) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "SetTier", nil, "Failure preparing request") return @@ -49,7 +45,7 @@ func (client Client) SetTier(ctx context.Context, accountName, containerName, bl } // SetTierPreparer prepares the SetTier request. -func (client Client) SetTierPreparer(ctx context.Context, accountName, containerName, blobName string, tier AccessTier) (*http.Request, error) { +func (client Client) SetTierPreparer(ctx context.Context, containerName, blobName string, tier AccessTier) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -66,7 +62,7 @@ func (client Client) SetTierPreparer(ctx context.Context, accountName, container preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/blobs/snapshot.go b/storage/2020-08-04/blob/blobs/snapshot.go index 180070b..c60f5b4 100644 --- a/storage/2020-08-04/blob/blobs/snapshot.go +++ b/storage/2020-08-04/blob/blobs/snapshot.go @@ -9,7 +9,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -55,10 +54,7 @@ type SnapshotResult struct { } // Snapshot captures a Snapshot of a given Blob -func (client Client) Snapshot(ctx context.Context, accountName, containerName, blobName string, input SnapshotInput) (result SnapshotResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "Snapshot", "`accountName` cannot be an empty string.") - } +func (client Client) Snapshot(ctx context.Context, containerName, blobName string, input SnapshotInput) (result SnapshotResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "Snapshot", "`containerName` cannot be an empty string.") } @@ -72,7 +68,7 @@ func (client Client) Snapshot(ctx context.Context, accountName, containerName, b return result, validation.NewError("blobs.Client", "Snapshot", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) } - req, err := client.SnapshotPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.SnapshotPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "Snapshot", nil, "Failure preparing request") return @@ -95,7 +91,7 @@ func (client Client) Snapshot(ctx context.Context, accountName, containerName, b } // SnapshotPreparer prepares the Snapshot request. -func (client Client) SnapshotPreparer(ctx context.Context, accountName, containerName, blobName string, input SnapshotInput) (*http.Request, error) { +func (client Client) SnapshotPreparer(ctx context.Context, containerName, blobName string, input SnapshotInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -130,7 +126,7 @@ func (client Client) SnapshotPreparer(ctx context.Context, accountName, containe preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/blobs/snapshot_get_properties.go b/storage/2020-08-04/blob/blobs/snapshot_get_properties.go index fe1be63..49f4044 100644 --- a/storage/2020-08-04/blob/blobs/snapshot_get_properties.go +++ b/storage/2020-08-04/blob/blobs/snapshot_get_properties.go @@ -7,7 +7,6 @@ import ( "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" ) type GetSnapshotPropertiesInput struct { @@ -21,10 +20,7 @@ type GetSnapshotPropertiesInput struct { // GetSnapshotProperties returns all user-defined metadata, standard HTTP properties, and system properties for // the specified snapshot of a blob -func (client Client) GetSnapshotProperties(ctx context.Context, accountName, containerName, blobName string, input GetSnapshotPropertiesInput) (result GetPropertiesResult, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "GetSnapshotProperties", "`accountName` cannot be an empty string.") - } +func (client Client) GetSnapshotProperties(ctx context.Context, containerName, blobName string, input GetSnapshotPropertiesInput) (result GetPropertiesResult, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "GetSnapshotProperties", "`containerName` cannot be an empty string.") } @@ -38,7 +34,7 @@ func (client Client) GetSnapshotProperties(ctx context.Context, accountName, con return result, validation.NewError("blobs.Client", "GetSnapshotProperties", "`input.SnapshotID` cannot be an empty string.") } - req, err := client.GetSnapshotPropertiesPreparer(ctx, accountName, containerName, blobName, input) + req, err := client.GetSnapshotPropertiesPreparer(ctx, containerName, blobName, input) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "GetSnapshotProperties", nil, "Failure preparing request") return @@ -62,7 +58,7 @@ func (client Client) GetSnapshotProperties(ctx context.Context, accountName, con } // GetSnapshotPreparer prepares the GetSnapshot request. -func (client Client) GetSnapshotPropertiesPreparer(ctx context.Context, accountName, containerName, blobName string, input GetSnapshotPropertiesInput) (*http.Request, error) { +func (client Client) GetSnapshotPropertiesPreparer(ctx context.Context, containerName, blobName string, input GetSnapshotPropertiesInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -82,7 +78,7 @@ func (client Client) GetSnapshotPropertiesPreparer(ctx context.Context, accountN preparer := autorest.CreatePreparer( autorest.AsHead(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/blob/blobs/snapshot_test.go b/storage/2020-08-04/blob/blobs/snapshot_test.go index f55ef08..4649637 100644 --- a/storage/2020-08-04/blob/blobs/snapshot_test.go +++ b/storage/2020-08-04/blob/blobs/snapshot_test.go @@ -33,20 +33,20 @@ func TestSnapshotLifecycle(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - containersClient := containers.NewWithEnvironment(client.AutoRestEnvironment) + containersClient := containers.NewWithEnvironment(accountName, client.AutoRestEnvironment) containersClient.Client = client.PrepareWithStorageResourceManagerAuth(containersClient.Client) - _, err = containersClient.Create(ctx, accountName, containerName, containers.CreateInput{}) + _, err = containersClient.Create(ctx, containerName, containers.CreateInput{}) if err != nil { t.Fatalf("Error creating: %s", err) } - defer containersClient.Delete(ctx, accountName, containerName) + defer containersClient.Delete(ctx, containerName) storageAuth, err := autorest.NewSharedKeyAuthorizer(accountName, testData.StorageAccountKey, autorest.SharedKeyLite) if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - blobClient := NewWithEnvironment(client.AutoRestEnvironment) + blobClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) blobClient.Client = client.PrepareWithAuthorizer(blobClient.Client, storageAuth) t.Logf("[DEBUG] Copying file to Blob Storage..") @@ -55,12 +55,12 @@ func TestSnapshotLifecycle(t *testing.T) { } 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 { t.Fatalf("Error copying: %s", err) } t.Logf("[DEBUG] First Snapshot..") - firstSnapshot, err := blobClient.Snapshot(ctx, accountName, containerName, fileName, SnapshotInput{}) + firstSnapshot, err := blobClient.Snapshot(ctx, containerName, fileName, SnapshotInput{}) if err != nil { t.Fatalf("Error taking first snapshot: %s", err) } @@ -70,7 +70,7 @@ func TestSnapshotLifecycle(t *testing.T) { time.Sleep(2 * time.Second) t.Logf("[DEBUG] Second Snapshot..") - secondSnapshot, err := blobClient.Snapshot(ctx, accountName, containerName, fileName, SnapshotInput{ + secondSnapshot, err := blobClient.Snapshot(ctx, containerName, fileName, SnapshotInput{ MetaData: map[string]string{ "hello": "world", }, @@ -81,7 +81,7 @@ func TestSnapshotLifecycle(t *testing.T) { t.Logf("[DEBUG] Second Snapshot ID: %q", secondSnapshot.SnapshotDateTime) t.Logf("[DEBUG] Leasing the Blob..") - leaseDetails, err := blobClient.AcquireLease(ctx, accountName, containerName, fileName, AcquireLeaseInput{ + leaseDetails, err := blobClient.AcquireLease(ctx, containerName, fileName, AcquireLeaseInput{ // infinite LeaseDuration: -1, }) @@ -91,7 +91,7 @@ func TestSnapshotLifecycle(t *testing.T) { t.Logf("[DEBUG] Lease ID: %q", leaseDetails.LeaseID) t.Logf("[DEBUG] Third Snapshot..") - thirdSnapshot, err := blobClient.Snapshot(ctx, accountName, containerName, fileName, SnapshotInput{ + thirdSnapshot, err := blobClient.Snapshot(ctx, containerName, fileName, SnapshotInput{ LeaseID: &leaseDetails.LeaseID, }) if err != nil { @@ -100,20 +100,20 @@ func TestSnapshotLifecycle(t *testing.T) { t.Logf("[DEBUG] Third Snapshot ID: %q", thirdSnapshot.SnapshotDateTime) t.Logf("[DEBUG] Releasing Lease..") - if _, err := blobClient.ReleaseLease(ctx, accountName, containerName, fileName, leaseDetails.LeaseID); err != nil { + if _, err := blobClient.ReleaseLease(ctx, containerName, fileName, leaseDetails.LeaseID); err != nil { t.Fatalf("Error releasing Lease: %s", err) } // get the properties from the blob, which should include the LastModifiedDate t.Logf("[DEBUG] Retrieving Properties for Blob") - props, err := blobClient.GetProperties(ctx, accountName, containerName, fileName, GetPropertiesInput{}) + props, err := blobClient.GetProperties(ctx, containerName, fileName, GetPropertiesInput{}) if err != nil { t.Fatalf("Error getting properties: %s", err) } // confirm that the If-Modified-None returns an error t.Logf("[DEBUG] Third Snapshot..") - fourthSnapshot, err := blobClient.Snapshot(ctx, accountName, containerName, fileName, SnapshotInput{ + fourthSnapshot, err := blobClient.Snapshot(ctx, containerName, fileName, SnapshotInput{ LeaseID: &leaseDetails.LeaseID, IfModifiedSince: &props.LastModified, }) @@ -128,7 +128,7 @@ func TestSnapshotLifecycle(t *testing.T) { getSecondSnapshotInput := GetSnapshotPropertiesInput{ SnapshotID: secondSnapshot.SnapshotDateTime, } - if _, err := blobClient.GetSnapshotProperties(ctx, accountName, containerName, fileName, getSecondSnapshotInput); err != nil { + if _, err := blobClient.GetSnapshotProperties(ctx, containerName, fileName, getSecondSnapshotInput); err != nil { t.Fatalf("Error retrieving properties for the second snapshot: %s", err) } @@ -136,12 +136,12 @@ func TestSnapshotLifecycle(t *testing.T) { deleteSnapshotInput := DeleteSnapshotInput{ SnapshotDateTime: secondSnapshot.SnapshotDateTime, } - if _, err := blobClient.DeleteSnapshot(ctx, accountName, containerName, fileName, deleteSnapshotInput); err != nil { + if _, err := blobClient.DeleteSnapshot(ctx, containerName, fileName, deleteSnapshotInput); err != nil { t.Fatalf("Error deleting snapshot: %s", err) } t.Logf("[DEBUG] Re-Retrieving the Second Snapshot Properties..") - secondSnapshotProps, err := blobClient.GetSnapshotProperties(ctx, accountName, containerName, fileName, getSecondSnapshotInput) + secondSnapshotProps, err := blobClient.GetSnapshotProperties(ctx, containerName, fileName, getSecondSnapshotInput) if err == nil { t.Fatalf("Expected an error retrieving the snapshot but got none") } @@ -150,7 +150,7 @@ func TestSnapshotLifecycle(t *testing.T) { } t.Logf("[DEBUG] Deleting all the snapshots..") - if _, err := blobClient.DeleteSnapshots(ctx, accountName, containerName, fileName, DeleteSnapshotsInput{}); err != nil { + if _, err := blobClient.DeleteSnapshots(ctx, containerName, fileName, DeleteSnapshotsInput{}); err != nil { t.Fatalf("Error deleting snapshots: %s", err) } @@ -158,7 +158,7 @@ func TestSnapshotLifecycle(t *testing.T) { deleteInput := DeleteInput{ DeleteSnapshots: false, } - if _, err := blobClient.Delete(ctx, accountName, containerName, fileName, deleteInput); err != nil { + if _, err := blobClient.Delete(ctx, containerName, fileName, deleteInput); err != nil { t.Fatalf("Error deleting Blob: %s", err) } } diff --git a/storage/2020-08-04/blob/blobs/undelete.go b/storage/2020-08-04/blob/blobs/undelete.go index 9be2f81..49e321f 100644 --- a/storage/2020-08-04/blob/blobs/undelete.go +++ b/storage/2020-08-04/blob/blobs/undelete.go @@ -8,14 +8,10 @@ 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" ) // Undelete restores the contents and metadata of soft deleted blob and any associated soft deleted snapshots. -func (client Client) Undelete(ctx context.Context, accountName, containerName, blobName string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("blobs.Client", "Undelete", "`accountName` cannot be an empty string.") - } +func (client Client) Undelete(ctx context.Context, containerName, blobName string) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("blobs.Client", "Undelete", "`containerName` cannot be an empty string.") } @@ -26,7 +22,7 @@ func (client Client) Undelete(ctx context.Context, accountName, containerName, b return result, validation.NewError("blobs.Client", "Undelete", "`blobName` cannot be an empty string.") } - req, err := client.UndeletePreparer(ctx, accountName, containerName, blobName) + req, err := client.UndeletePreparer(ctx, containerName, blobName) if err != nil { err = autorest.NewErrorWithError(err, "blobs.Client", "Undelete", nil, "Failure preparing request") return @@ -49,7 +45,7 @@ func (client Client) Undelete(ctx context.Context, accountName, containerName, b } // UndeletePreparer prepares the Undelete request. -func (client Client) UndeletePreparer(ctx context.Context, accountName, containerName, blobName string) (*http.Request, error) { +func (client Client) UndeletePreparer(ctx context.Context, containerName, blobName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), "blobName": autorest.Encode("path", blobName), @@ -65,7 +61,7 @@ func (client Client) UndeletePreparer(ctx context.Context, accountName, containe preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/README.md b/storage/2020-08-04/blob/containers/README.md index 9d37548..bfcb3ae 100644 --- a/storage/2020-08-04/blob/containers/README.md +++ b/storage/2020-08-04/blob/containers/README.md @@ -36,10 +36,10 @@ func Example() error { createInput := containers.CreateInput{ AccessLevel: containers.Private, } - if _, err := containersClient.Create(ctx, accountName, containerName, createInput); err != nil { + if _, err := containersClient.Create(ctx, containerName, createInput); err != nil { return fmt.Errorf("Error creating Container: %s", err) } return nil } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/blob/containers/api.go b/storage/2020-08-04/blob/containers/api.go index 622f2b0..d56da20 100644 --- a/storage/2020-08-04/blob/containers/api.go +++ b/storage/2020-08-04/blob/containers/api.go @@ -7,19 +7,19 @@ import ( ) type StorageContainer interface { - Create(ctx context.Context, accountName, containerName string, input CreateInput) (result CreateResponse, err error) - Delete(ctx context.Context, accountName, containerName string) (result autorest.Response, err error) - GetProperties(ctx context.Context, accountName, containerName string) (ContainerProperties, error) - GetPropertiesWithLeaseID(ctx context.Context, accountName, containerName, leaseID string) (result ContainerProperties, err error) - AcquireLease(ctx context.Context, accountName, containerName string, input AcquireLeaseInput) (result AcquireLeaseResponse, err error) - BreakLease(ctx context.Context, accountName, containerName string, input BreakLeaseInput) (result BreakLeaseResponse, err error) - ChangeLease(ctx context.Context, accountName, containerName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) - ReleaseLease(ctx context.Context, accountName, containerName, leaseID string) (result autorest.Response, err error) - RenewLease(ctx context.Context, accountName, containerName, leaseID string) (result autorest.Response, err error) - ListBlobs(ctx context.Context, accountName, containerName string, input ListBlobsInput) (result ListBlobsResult, err error) + Create(ctx context.Context, containerName string, input CreateInput) (result CreateResponse, err error) + Delete(ctx context.Context, containerName string) (result autorest.Response, err error) + GetProperties(ctx context.Context, containerName string) (ContainerProperties, error) + GetPropertiesWithLeaseID(ctx context.Context, containerName, leaseID string) (result ContainerProperties, err error) + AcquireLease(ctx context.Context, containerName string, input AcquireLeaseInput) (result AcquireLeaseResponse, err error) + BreakLease(ctx context.Context, containerName string, input BreakLeaseInput) (result BreakLeaseResponse, err error) + ChangeLease(ctx context.Context, containerName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) + ReleaseLease(ctx context.Context, containerName, leaseID string) (result autorest.Response, err error) + RenewLease(ctx context.Context, containerName, leaseID string) (result autorest.Response, err error) + ListBlobs(ctx context.Context, containerName string, input ListBlobsInput) (result ListBlobsResult, err error) GetResourceManagerResourceID(subscriptionID, resourceGroup, accountName, containerName string) string - SetAccessControl(ctx context.Context, accountName, containerName string, level AccessLevel) (autorest.Response, error) - SetAccessControlWithLeaseID(ctx context.Context, accountName, containerName, leaseID string, level AccessLevel) (result autorest.Response, err error) - SetMetaData(ctx context.Context, accountName, containerName string, metaData map[string]string) (autorest.Response, error) - SetMetaDataWithLeaseID(ctx context.Context, accountName, containerName, leaseID string, metaData map[string]string) (result autorest.Response, err error) + SetAccessControl(ctx context.Context, containerName string, level AccessLevel) (autorest.Response, error) + SetAccessControlWithLeaseID(ctx context.Context, containerName, leaseID string, level AccessLevel) (result autorest.Response, err error) + SetMetaData(ctx context.Context, containerName string, metaData map[string]string) (autorest.Response, error) + SetMetaDataWithLeaseID(ctx context.Context, containerName, leaseID string, metaData map[string]string) (result autorest.Response, err error) } diff --git a/storage/2020-08-04/blob/containers/client.go b/storage/2020-08-04/blob/containers/client.go index 7bf4947..382ecf8 100644 --- a/storage/2020-08-04/blob/containers/client.go +++ b/storage/2020-08-04/blob/containers/client.go @@ -3,24 +3,33 @@ package containers 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 Containers. +// 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, } } diff --git a/storage/2020-08-04/blob/containers/create.go b/storage/2020-08-04/blob/containers/create.go index 84c2887..f429ea6 100644 --- a/storage/2020-08-04/blob/containers/create.go +++ b/storage/2020-08-04/blob/containers/create.go @@ -8,7 +8,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -27,10 +26,7 @@ type CreateResponse struct { // Create creates a new container under the specified account. // If the container with the same name already exists, the operation fails. -func (client Client) Create(ctx context.Context, accountName, containerName string, input CreateInput) (result CreateResponse, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "Create", "`accountName` cannot be an empty string.") - } +func (client Client) Create(ctx context.Context, containerName string, input CreateInput) (result CreateResponse, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "Create", "`containerName` cannot be an empty string.") } @@ -38,7 +34,7 @@ func (client Client) Create(ctx context.Context, accountName, containerName stri return result, validation.NewError("containers.Client", "Create", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) } - req, err := client.CreatePreparer(ctx, accountName, containerName, input) + req, err := client.CreatePreparer(ctx, containerName, input) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "Create", nil, "Failure preparing request") return @@ -61,7 +57,7 @@ func (client Client) Create(ctx context.Context, accountName, containerName stri } // CreatePreparer prepares the Create request. -func (client Client) CreatePreparer(ctx context.Context, accountName string, containerName string, input CreateInput) (*http.Request, error) { +func (client Client) CreatePreparer(ctx context.Context, containerName string, input CreateInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -80,7 +76,7 @@ func (client Client) CreatePreparer(ctx context.Context, accountName string, con preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/delete.go b/storage/2020-08-04/blob/containers/delete.go index 3095829..d0c0177 100644 --- a/storage/2020-08-04/blob/containers/delete.go +++ b/storage/2020-08-04/blob/containers/delete.go @@ -7,20 +7,16 @@ 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" ) // Delete marks the specified container for deletion. // The container and any blobs contained within it are later deleted during garbage collection. -func (client Client) Delete(ctx context.Context, accountName, containerName string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, containerName string) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "Delete", "`containerName` cannot be an empty string.") } - req, err := client.DeletePreparer(ctx, accountName, containerName) + req, err := client.DeletePreparer(ctx, containerName) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "Delete", nil, "Failure preparing request") return @@ -42,7 +38,7 @@ func (client Client) Delete(ctx context.Context, accountName, containerName stri } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName string, containerName string) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, containerName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -58,7 +54,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName string, con preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/get_properties.go b/storage/2020-08-04/blob/containers/get_properties.go index 1e308da..4e9ffd3 100644 --- a/storage/2020-08-04/blob/containers/get_properties.go +++ b/storage/2020-08-04/blob/containers/get_properties.go @@ -8,27 +8,23 @@ 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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) // GetProperties returns the properties for this Container without a Lease -func (client Client) GetProperties(ctx context.Context, accountName, containerName string) (ContainerProperties, error) { +func (client Client) GetProperties(ctx context.Context, containerName string) (ContainerProperties, error) { // If specified, Get Container Properties only succeeds if the container’s lease is active and matches this ID. // If there is no active lease or the ID does not match, 412 (Precondition Failed) is returned. - return client.GetPropertiesWithLeaseID(ctx, accountName, containerName, "") + return client.GetPropertiesWithLeaseID(ctx, containerName, "") } // GetPropertiesWithLeaseID returns the properties for this Container using the specified LeaseID -func (client Client) GetPropertiesWithLeaseID(ctx context.Context, accountName, containerName, leaseID string) (result ContainerProperties, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "GetPropertiesWithLeaseID", "`accountName` cannot be an empty string.") - } +func (client Client) GetPropertiesWithLeaseID(ctx context.Context, containerName, leaseID string) (result ContainerProperties, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "GetPropertiesWithLeaseID", "`containerName` cannot be an empty string.") } - req, err := client.GetPropertiesWithLeaseIDPreparer(ctx, accountName, containerName, leaseID) + req, err := client.GetPropertiesWithLeaseIDPreparer(ctx, containerName, leaseID) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "GetProperties", nil, "Failure preparing request") return @@ -51,7 +47,7 @@ func (client Client) GetPropertiesWithLeaseID(ctx context.Context, accountName, } // GetPropertiesWithLeaseIDPreparer prepares the GetPropertiesWithLeaseID request. -func (client Client) GetPropertiesWithLeaseIDPreparer(ctx context.Context, accountName, containerName, leaseID string) (*http.Request, error) { +func (client Client) GetPropertiesWithLeaseIDPreparer(ctx context.Context, containerName, leaseID string) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -73,7 +69,7 @@ func (client Client) GetPropertiesWithLeaseIDPreparer(ctx context.Context, accou preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/lease_acquire.go b/storage/2020-08-04/blob/containers/lease_acquire.go index 061c863..a4fe2e4 100644 --- a/storage/2020-08-04/blob/containers/lease_acquire.go +++ b/storage/2020-08-04/blob/containers/lease_acquire.go @@ -7,7 +7,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 AcquireLeaseInput struct { @@ -25,10 +24,7 @@ type AcquireLeaseResponse struct { } // AcquireLease establishes and manages a lock on a container for delete operations. -func (client Client) AcquireLease(ctx context.Context, accountName, containerName string, input AcquireLeaseInput) (result AcquireLeaseResponse, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "AcquireLease", "`accountName` cannot be an empty string.") - } +func (client Client) AcquireLease(ctx context.Context, containerName string, input AcquireLeaseInput) (result AcquireLeaseResponse, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "AcquireLease", "`containerName` cannot be an empty string.") } @@ -37,7 +33,7 @@ func (client Client) AcquireLease(ctx context.Context, accountName, containerNam return result, validation.NewError("containers.Client", "AcquireLease", "`input.LeaseDuration` must be -1 (infinite), or between 15 and 60 seconds.") } - req, err := client.AcquireLeasePreparer(ctx, accountName, containerName, input) + req, err := client.AcquireLeasePreparer(ctx, containerName, input) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "AcquireLease", nil, "Failure preparing request") return @@ -60,7 +56,7 @@ func (client Client) AcquireLease(ctx context.Context, accountName, containerNam } // AcquireLeasePreparer prepares the AcquireLease request. -func (client Client) AcquireLeasePreparer(ctx context.Context, accountName string, containerName string, input AcquireLeaseInput) (*http.Request, error) { +func (client Client) AcquireLeasePreparer(ctx context.Context, containerName string, input AcquireLeaseInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -83,7 +79,7 @@ func (client Client) AcquireLeasePreparer(ctx context.Context, accountName strin preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/lease_break.go b/storage/2020-08-04/blob/containers/lease_break.go index 08acfb7..09c304c 100644 --- a/storage/2020-08-04/blob/containers/lease_break.go +++ b/storage/2020-08-04/blob/containers/lease_break.go @@ -8,7 +8,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 BreakLeaseInput struct { @@ -34,10 +33,7 @@ type BreakLeaseResponse struct { } // BreakLease breaks a lock based on it's Lease ID -func (client Client) BreakLease(ctx context.Context, accountName, containerName string, input BreakLeaseInput) (result BreakLeaseResponse, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "BreakLease", "`accountName` cannot be an empty string.") - } +func (client Client) BreakLease(ctx context.Context, containerName string, input BreakLeaseInput) (result BreakLeaseResponse, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "BreakLease", "`containerName` cannot be an empty string.") } @@ -45,7 +41,7 @@ func (client Client) BreakLease(ctx context.Context, accountName, containerName return result, validation.NewError("containers.Client", "BreakLease", "`input.LeaseID` cannot be an empty string.") } - req, err := client.BreakLeasePreparer(ctx, accountName, containerName, input) + req, err := client.BreakLeasePreparer(ctx, containerName, input) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "BreakLease", nil, "Failure preparing request") return @@ -68,7 +64,7 @@ func (client Client) BreakLease(ctx context.Context, accountName, containerName } // BreakLeasePreparer prepares the BreakLease request. -func (client Client) BreakLeasePreparer(ctx context.Context, accountName string, containerName string, input BreakLeaseInput) (*http.Request, error) { +func (client Client) BreakLeasePreparer(ctx context.Context, containerName string, input BreakLeaseInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -91,7 +87,7 @@ func (client Client) BreakLeasePreparer(ctx context.Context, accountName string, preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/lease_change.go b/storage/2020-08-04/blob/containers/lease_change.go index dfbcb13..e648f37 100644 --- a/storage/2020-08-04/blob/containers/lease_change.go +++ b/storage/2020-08-04/blob/containers/lease_change.go @@ -7,7 +7,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 ChangeLeaseInput struct { @@ -22,10 +21,7 @@ type ChangeLeaseResponse struct { } // ChangeLease changes the lock from one Lease ID to another Lease ID -func (client Client) ChangeLease(ctx context.Context, accountName, containerName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "ChangeLease", "`accountName` cannot be an empty string.") - } +func (client Client) ChangeLease(ctx context.Context, containerName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "ChangeLease", "`containerName` cannot be an empty string.") } @@ -36,7 +32,7 @@ func (client Client) ChangeLease(ctx context.Context, accountName, containerName return result, validation.NewError("containers.Client", "ChangeLease", "`input.ProposedLeaseID` cannot be an empty string.") } - req, err := client.ChangeLeasePreparer(ctx, accountName, containerName, input) + req, err := client.ChangeLeasePreparer(ctx, containerName, input) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "ChangeLease", nil, "Failure preparing request") return @@ -59,7 +55,7 @@ func (client Client) ChangeLease(ctx context.Context, accountName, containerName } // ChangeLeasePreparer prepares the ChangeLease request. -func (client Client) ChangeLeasePreparer(ctx context.Context, accountName string, containerName string, input ChangeLeaseInput) (*http.Request, error) { +func (client Client) ChangeLeasePreparer(ctx context.Context, containerName string, input ChangeLeaseInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -79,7 +75,7 @@ func (client Client) ChangeLeasePreparer(ctx context.Context, accountName string preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/lease_release.go b/storage/2020-08-04/blob/containers/lease_release.go index fafcf98..7c90ad8 100644 --- a/storage/2020-08-04/blob/containers/lease_release.go +++ b/storage/2020-08-04/blob/containers/lease_release.go @@ -7,14 +7,10 @@ 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" ) // ReleaseLease releases the lock based on the Lease ID -func (client Client) ReleaseLease(ctx context.Context, accountName, containerName, leaseID string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "ReleaseLease", "`accountName` cannot be an empty string.") - } +func (client Client) ReleaseLease(ctx context.Context, containerName, leaseID string) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "ReleaseLease", "`containerName` cannot be an empty string.") } @@ -22,7 +18,7 @@ func (client Client) ReleaseLease(ctx context.Context, accountName, containerNam return result, validation.NewError("containers.Client", "ReleaseLease", "`leaseID` cannot be an empty string.") } - req, err := client.ReleaseLeasePreparer(ctx, accountName, containerName, leaseID) + req, err := client.ReleaseLeasePreparer(ctx, containerName, leaseID) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "ReleaseLease", nil, "Failure preparing request") return @@ -45,7 +41,7 @@ func (client Client) ReleaseLease(ctx context.Context, accountName, containerNam } // ReleaseLeasePreparer prepares the ReleaseLease request. -func (client Client) ReleaseLeasePreparer(ctx context.Context, accountName string, containerName string, leaseID string) (*http.Request, error) { +func (client Client) ReleaseLeasePreparer(ctx context.Context, containerName string, leaseID string) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -64,7 +60,7 @@ func (client Client) ReleaseLeasePreparer(ctx context.Context, accountName strin preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/lease_renew.go b/storage/2020-08-04/blob/containers/lease_renew.go index cab50bf..f6632dd 100644 --- a/storage/2020-08-04/blob/containers/lease_renew.go +++ b/storage/2020-08-04/blob/containers/lease_renew.go @@ -7,14 +7,10 @@ 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" ) // RenewLease renews the lock based on the Lease ID -func (client Client) RenewLease(ctx context.Context, accountName, containerName, leaseID string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "RenewLease", "`accountName` cannot be an empty string.") - } +func (client Client) RenewLease(ctx context.Context, containerName, leaseID string) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "RenewLease", "`containerName` cannot be an empty string.") } @@ -22,7 +18,7 @@ func (client Client) RenewLease(ctx context.Context, accountName, containerName, return result, validation.NewError("containers.Client", "RenewLease", "`leaseID` cannot be an empty string.") } - req, err := client.RenewLeasePreparer(ctx, accountName, containerName, leaseID) + req, err := client.RenewLeasePreparer(ctx, containerName, leaseID) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", nil, "Failure preparing request") return @@ -45,7 +41,7 @@ func (client Client) RenewLease(ctx context.Context, accountName, containerName, } // RenewLeasePreparer prepares the RenewLease request. -func (client Client) RenewLeasePreparer(ctx context.Context, accountName string, containerName string, leaseID string) (*http.Request, error) { +func (client Client) RenewLeasePreparer(ctx context.Context, containerName string, leaseID string) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -64,7 +60,7 @@ func (client Client) RenewLeasePreparer(ctx context.Context, accountName string, preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/lifecycle_test.go b/storage/2020-08-04/blob/containers/lifecycle_test.go index 4b77ffa..4eb4008 100644 --- a/storage/2020-08-04/blob/containers/lifecycle_test.go +++ b/storage/2020-08-04/blob/containers/lifecycle_test.go @@ -36,17 +36,17 @@ func TestContainerLifecycle(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - containersClient := NewWithEnvironment(client.AutoRestEnvironment) + containersClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) containersClient.Client = client.PrepareWithAuthorizer(containersClient.Client, storageAuth) // first let's test an empty container input := CreateInput{} - _, err = containersClient.Create(ctx, accountName, containerName, input) + _, err = containersClient.Create(ctx, containerName, input) if err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } - container, err := containersClient.GetProperties(ctx, accountName, containerName) + container, err := containersClient.GetProperties(ctx, containerName) if err != nil { t.Fatal(fmt.Errorf("Error retrieving: %s", err)) } @@ -65,7 +65,7 @@ func TestContainerLifecycle(t *testing.T) { metaData := map[string]string{ "dont": "kill-my-vibe", } - _, err = containersClient.SetMetaData(ctx, accountName, containerName, metaData) + _, err = containersClient.SetMetaData(ctx, containerName, metaData) if err != nil { t.Fatal(fmt.Errorf("Error updating metadata: %s", err)) } @@ -74,7 +74,7 @@ func TestContainerLifecycle(t *testing.T) { time.Sleep(2 * time.Second) // then assert that - container, err = containersClient.GetProperties(ctx, accountName, containerName) + container, err = containersClient.GetProperties(ctx, containerName) if err != nil { t.Fatal(fmt.Errorf("Error re-retrieving: %s", err)) } @@ -92,7 +92,7 @@ func TestContainerLifecycle(t *testing.T) { } // then update the ACL - _, err = containersClient.SetAccessControl(ctx, accountName, containerName, Blob) + _, err = containersClient.SetAccessControl(ctx, containerName, Blob) if err != nil { t.Fatal(fmt.Errorf("Error updating ACL's: %s", err)) } @@ -101,7 +101,7 @@ func TestContainerLifecycle(t *testing.T) { time.Sleep(2 * time.Second) // then assert that - container, err = containersClient.GetProperties(ctx, accountName, containerName) + container, err = containersClient.GetProperties(ctx, containerName) if err != nil { t.Fatal(fmt.Errorf("Error re-retrieving: %s", err)) } @@ -119,7 +119,7 @@ func TestContainerLifecycle(t *testing.T) { acquireLeaseInput := AcquireLeaseInput{ LeaseDuration: 30, } - acquireLeaseResp, err := containersClient.AcquireLease(ctx, accountName, containerName, acquireLeaseInput) + acquireLeaseResp, err := containersClient.AcquireLease(ctx, containerName, acquireLeaseInput) if err != nil { t.Fatalf("Error acquiring lease: %s", err) } @@ -131,13 +131,13 @@ func TestContainerLifecycle(t *testing.T) { ExistingLeaseID: acquireLeaseResp.LeaseID, ProposedLeaseID: "aaaabbbb-aaaa-bbbb-cccc-aaaabbbbcccc", } - updateLeaseResp, err := containersClient.ChangeLease(ctx, accountName, containerName, updateLeaseInput) + updateLeaseResp, err := containersClient.ChangeLease(ctx, containerName, updateLeaseInput) if err != nil { t.Fatalf("Error changing lease: %s", err) } // then renew it - _, err = containersClient.RenewLease(ctx, accountName, containerName, updateLeaseResp.LeaseID) + _, err = containersClient.RenewLease(ctx, containerName, updateLeaseResp.LeaseID) if err != nil { t.Fatalf("Error renewing lease: %s", err) } @@ -148,7 +148,7 @@ func TestContainerLifecycle(t *testing.T) { LeaseID: updateLeaseResp.LeaseID, BreakPeriod: &breakPeriod, } - breakLeaseResp, err := containersClient.BreakLease(ctx, accountName, containerName, breakLeaseInput) + breakLeaseResp, err := containersClient.BreakLease(ctx, containerName, breakLeaseInput) if err != nil { t.Fatalf("Error breaking lease: %s", err) } @@ -157,14 +157,14 @@ func TestContainerLifecycle(t *testing.T) { } // and finally ditch it - _, err = containersClient.ReleaseLease(ctx, accountName, containerName, updateLeaseResp.LeaseID) + _, err = containersClient.ReleaseLease(ctx, containerName, updateLeaseResp.LeaseID) if err != nil { t.Fatalf("Error releasing lease: %s", err) } t.Logf("[DEBUG] Listing blobs in the container..") listInput := ListBlobsInput{} - listResult, err := containersClient.ListBlobs(ctx, accountName, containerName, listInput) + listResult, err := containersClient.ListBlobs(ctx, containerName, listInput) if err != nil { t.Fatalf("Error listing blobs: %s", err) } @@ -174,7 +174,7 @@ func TestContainerLifecycle(t *testing.T) { } t.Logf("[DEBUG] Deleting..") - _, err = containersClient.Delete(ctx, accountName, containerName) + _, err = containersClient.Delete(ctx, containerName) if err != nil { t.Fatal(fmt.Errorf("Error deleting: %s", err)) } diff --git a/storage/2020-08-04/blob/containers/list_blobs.go b/storage/2020-08-04/blob/containers/list_blobs.go index 82797d0..fa4ba39 100644 --- a/storage/2020-08-04/blob/containers/list_blobs.go +++ b/storage/2020-08-04/blob/containers/list_blobs.go @@ -8,7 +8,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 ListBlobsInput struct { @@ -78,10 +77,7 @@ type BlobPrefix struct { } // ListBlobs lists the blobs matching the specified query within the specified Container -func (client Client) ListBlobs(ctx context.Context, accountName, containerName string, input ListBlobsInput) (result ListBlobsResult, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "ListBlobs", "`accountName` cannot be an empty string.") - } +func (client Client) ListBlobs(ctx context.Context, containerName string, input ListBlobsInput) (result ListBlobsResult, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "ListBlobs", "`containerName` cannot be an empty string.") } @@ -89,7 +85,7 @@ func (client Client) ListBlobs(ctx context.Context, accountName, containerName s return result, validation.NewError("containers.Client", "ListBlobs", "`input.MaxResults` can either be nil or between 0 and 5000.") } - req, err := client.ListBlobsPreparer(ctx, accountName, containerName, input) + req, err := client.ListBlobsPreparer(ctx, containerName, input) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "ListBlobs", nil, "Failure preparing request") return @@ -112,7 +108,7 @@ func (client Client) ListBlobs(ctx context.Context, accountName, containerName s } // ListBlobsPreparer prepares the ListBlobs request. -func (client Client) ListBlobsPreparer(ctx context.Context, accountName, containerName string, input ListBlobsInput) (*http.Request, error) { +func (client Client) ListBlobsPreparer(ctx context.Context, containerName string, input ListBlobsInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -150,7 +146,7 @@ func (client Client) ListBlobsPreparer(ctx context.Context, accountName, contain preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/resource_id.go b/storage/2020-08-04/blob/containers/resource_id.go index d35674a..86252f9 100644 --- a/storage/2020-08-04/blob/containers/resource_id.go +++ b/storage/2020-08-04/blob/containers/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given Container // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, containerName string) string { - domain := endpoints.GetBlobEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s", domain, containerName) +func (client Client) GetResourceID(containerName string) string { + return fmt.Sprintf("%s/%s", client.endpoint, containerName) } // GetResourceManagerResourceID returns the Resource Manager specific diff --git a/storage/2020-08-04/blob/containers/resource_id_test.go b/storage/2020-08-04/blob/containers/resource_id_test.go index 874302e..59e7ed8 100644 --- a/storage/2020-08-04/blob/containers/resource_id_test.go +++ b/storage/2020-08-04/blob/containers/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "container1") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("container1") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } @@ -62,7 +62,7 @@ func TestGetResourceManagerResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) + c := NewWithEnvironment("account1", v.Environment) actual := c.GetResourceManagerResourceID("11112222-3333-4444-5555-666677778888", "group1", "account1", "container1") if actual != v.Expected { t.Fatalf("Expected the Resource Manager Resource ID to be %q but got %q", v.Expected, actual) diff --git a/storage/2020-08-04/blob/containers/set_acl.go b/storage/2020-08-04/blob/containers/set_acl.go index fcf4e10..9131a4c 100644 --- a/storage/2020-08-04/blob/containers/set_acl.go +++ b/storage/2020-08-04/blob/containers/set_acl.go @@ -7,24 +7,20 @@ 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" ) // SetAccessControl sets the Access Control for a Container without a Lease ID -func (client Client) SetAccessControl(ctx context.Context, accountName, containerName string, level AccessLevel) (autorest.Response, error) { - return client.SetAccessControlWithLeaseID(ctx, accountName, containerName, "", level) +func (client Client) SetAccessControl(ctx context.Context, containerName string, level AccessLevel) (autorest.Response, error) { + return client.SetAccessControlWithLeaseID(ctx, containerName, "", level) } // SetAccessControlWithLeaseID sets the Access Control for a Container using the specified Lease ID -func (client Client) SetAccessControlWithLeaseID(ctx context.Context, accountName, containerName, leaseID string, level AccessLevel) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "SetAccessControl", "`accountName` cannot be an empty string.") - } +func (client Client) SetAccessControlWithLeaseID(ctx context.Context, containerName, leaseID string, level AccessLevel) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "SetAccessControl", "`containerName` cannot be an empty string.") } - req, err := client.SetAccessControlWithLeaseIDPreparer(ctx, accountName, containerName, leaseID, level) + req, err := client.SetAccessControlWithLeaseIDPreparer(ctx, containerName, leaseID, level) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "SetAccessControl", nil, "Failure preparing request") return @@ -47,7 +43,7 @@ func (client Client) SetAccessControlWithLeaseID(ctx context.Context, accountNam } // SetAccessControlWithLeaseIDPreparer prepares the SetAccessControlWithLeaseID request. -func (client Client) SetAccessControlWithLeaseIDPreparer(ctx context.Context, accountName, containerName, leaseID string, level AccessLevel) (*http.Request, error) { +func (client Client) SetAccessControlWithLeaseIDPreparer(ctx context.Context, containerName, leaseID string, level AccessLevel) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -72,7 +68,7 @@ func (client Client) SetAccessControlWithLeaseIDPreparer(ctx context.Context, ac preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/blob/containers/set_metadata.go b/storage/2020-08-04/blob/containers/set_metadata.go index fb9e07f..d7a12d1 100644 --- a/storage/2020-08-04/blob/containers/set_metadata.go +++ b/storage/2020-08-04/blob/containers/set_metadata.go @@ -8,20 +8,16 @@ 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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) // SetMetaData sets the specified MetaData on the Container without a Lease ID -func (client Client) SetMetaData(ctx context.Context, accountName, containerName string, metaData map[string]string) (autorest.Response, error) { - return client.SetMetaDataWithLeaseID(ctx, accountName, containerName, "", metaData) +func (client Client) SetMetaData(ctx context.Context, containerName string, metaData map[string]string) (autorest.Response, error) { + return client.SetMetaDataWithLeaseID(ctx, containerName, "", metaData) } // SetMetaDataWithLeaseID sets the specified MetaData on the Container using the specified Lease ID -func (client Client) SetMetaDataWithLeaseID(ctx context.Context, accountName, containerName, leaseID string, metaData map[string]string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "SetMetaData", "`accountName` cannot be an empty string.") - } +func (client Client) SetMetaDataWithLeaseID(ctx context.Context, containerName, leaseID string, metaData map[string]string) (result autorest.Response, err error) { if containerName == "" { return result, validation.NewError("containers.Client", "SetMetaData", "`containerName` cannot be an empty string.") } @@ -29,7 +25,7 @@ func (client Client) SetMetaDataWithLeaseID(ctx context.Context, accountName, co return result, validation.NewError("containers.Client", "SetMetaData", fmt.Sprintf("`metaData` is not valid: %s.", err)) } - req, err := client.SetMetaDataWithLeaseIDPreparer(ctx, accountName, containerName, leaseID, metaData) + req, err := client.SetMetaDataWithLeaseIDPreparer(ctx, containerName, leaseID, metaData) if err != nil { err = autorest.NewErrorWithError(err, "containers.Client", "SetMetaData", nil, "Failure preparing request") return @@ -52,7 +48,7 @@ func (client Client) SetMetaDataWithLeaseID(ctx context.Context, accountName, co } // SetMetaDataWithLeaseIDPreparer prepares the SetMetaDataWithLeaseID request. -func (client Client) SetMetaDataWithLeaseIDPreparer(ctx context.Context, accountName, containerName, leaseID string, metaData map[string]string) (*http.Request, error) { +func (client Client) SetMetaDataWithLeaseIDPreparer(ctx context.Context, containerName, leaseID string, metaData map[string]string) (*http.Request, error) { pathParameters := map[string]interface{}{ "containerName": autorest.Encode("path", containerName), } @@ -77,7 +73,7 @@ func (client Client) SetMetaDataWithLeaseIDPreparer(ctx context.Context, account preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{containerName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/datalakestore/filesystems/README.md b/storage/2020-08-04/datalakestore/filesystems/README.md index be6fb76..bd09bc2 100644 --- a/storage/2020-08-04/datalakestore/filesystems/README.md +++ b/storage/2020-08-04/datalakestore/filesystems/README.md @@ -69,16 +69,16 @@ func Example() error { } - fileSystemsClient := filesystems.NewWithEnvironment(env) + fileSystemsClient := filesystems.NewWithEnvironment(accountName, env) fileSystemsClient.Client.Authorizer = storageAuth input := filesystems.CreateInput{ Properties: map[string]string{}, } - if _, err = fileSystemsClient.Create(ctx, accountName, fileSystemName, input); err != nil { + if _, err = fileSystemsClient.Create(ctx, fileSystemName, input); err != nil { return fmt.Errorf("Error creating: %s", err) } return nil } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/datalakestore/filesystems/client.go b/storage/2020-08-04/datalakestore/filesystems/client.go index 91d3fe1..8ed9a49 100644 --- a/storage/2020-08-04/datalakestore/filesystems/client.go +++ b/storage/2020-08-04/datalakestore/filesystems/client.go @@ -3,23 +3,32 @@ package filesystems 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 Data Lake Storage FileSystem type Client struct { autorest.Client - BaseURI string + endpoint string } // New creates an instance of the Data Lake Storage FileSystem client. -func New() Client { - return NewWithEnvironment(azure.PublicCloud) +func New(accountName string) Client { + return NewWithEnvironment(accountName, azure.PublicCloud) } // NewWithEnvironment creates an instance of the Data Lake Storage FileSystem 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.BuildDataLakeStoreEndpoint(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, } } diff --git a/storage/2020-08-04/datalakestore/filesystems/create.go b/storage/2020-08-04/datalakestore/filesystems/create.go index 4217cb8..ba5ecf8 100644 --- a/storage/2020-08-04/datalakestore/filesystems/create.go +++ b/storage/2020-08-04/datalakestore/filesystems/create.go @@ -7,7 +7,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 CreateInput struct { @@ -19,15 +18,12 @@ type CreateInput struct { } // Create creates a Data Lake Store Gen2 FileSystem within a Storage Account -func (client Client) Create(ctx context.Context, accountName string, fileSystemName string, input CreateInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("datalakestore.Client", "Create", "`accountName` cannot be an empty string.") - } +func (client Client) Create(ctx context.Context, fileSystemName string, input CreateInput) (result autorest.Response, err error) { if fileSystemName == "" { return result, validation.NewError("datalakestore.Client", "Create", "`fileSystemName` cannot be an empty string.") } - req, err := client.CreatePreparer(ctx, accountName, fileSystemName, input) + req, err := client.CreatePreparer(ctx, fileSystemName, input) if err != nil { err = autorest.NewErrorWithError(err, "datalakestore.Client", "Create", nil, "Failure preparing request") return @@ -49,7 +45,7 @@ func (client Client) Create(ctx context.Context, accountName string, fileSystemN } // CreatePreparer prepares the Create request. -func (client Client) CreatePreparer(ctx context.Context, accountName string, fileSystemName string, input CreateInput) (*http.Request, error) { +func (client Client) CreatePreparer(ctx context.Context, fileSystemName string, input CreateInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "fileSystemName": autorest.Encode("path", fileSystemName), } @@ -65,7 +61,7 @@ func (client Client) CreatePreparer(ctx context.Context, accountName string, fil preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{fileSystemName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/datalakestore/filesystems/create_test.go b/storage/2020-08-04/datalakestore/filesystems/create_test.go index 10f671f..a0dae1a 100644 --- a/storage/2020-08-04/datalakestore/filesystems/create_test.go +++ b/storage/2020-08-04/datalakestore/filesystems/create_test.go @@ -28,19 +28,19 @@ func TestCreateHasNoTagsByDefault(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - fileSystemsClient := NewWithEnvironment(client.AutoRestEnvironment) + fileSystemsClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) fileSystemsClient.Client = client.PrepareWithStorageResourceManagerAuth(fileSystemsClient.Client) t.Logf("[DEBUG] Creating an empty File System..") input := CreateInput{ Properties: map[string]string{}, } - if _, err = fileSystemsClient.Create(ctx, accountName, fileSystemName, input); err != nil { + if _, err = fileSystemsClient.Create(ctx, fileSystemName, input); err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } t.Logf("[DEBUG] Retrieving the Properties..") - props, err := fileSystemsClient.GetProperties(ctx, accountName, fileSystemName) + props, err := fileSystemsClient.GetProperties(ctx, fileSystemName) if err != nil { t.Fatal(fmt.Errorf("Error getting properties: %s", err)) } @@ -50,7 +50,7 @@ func TestCreateHasNoTagsByDefault(t *testing.T) { } t.Logf("[DEBUG] Deleting File System..") - if _, err := fileSystemsClient.Delete(ctx, accountName, fileSystemName); err != nil { + if _, err := fileSystemsClient.Delete(ctx, fileSystemName); err != nil { t.Fatalf("Error deleting: %s", err) } } diff --git a/storage/2020-08-04/datalakestore/filesystems/delete.go b/storage/2020-08-04/datalakestore/filesystems/delete.go index fabc589..45472b6 100644 --- a/storage/2020-08-04/datalakestore/filesystems/delete.go +++ b/storage/2020-08-04/datalakestore/filesystems/delete.go @@ -7,19 +7,15 @@ 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" ) // Delete deletes a Data Lake Store Gen2 FileSystem within a Storage Account -func (client Client) Delete(ctx context.Context, accountName string, fileSystemName string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("datalakestore.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, fileSystemName string) (result autorest.Response, err error) { if fileSystemName == "" { return result, validation.NewError("datalakestore.Client", "Delete", "`fileSystemName` cannot be an empty string.") } - req, err := client.DeletePreparer(ctx, accountName, fileSystemName) + req, err := client.DeletePreparer(ctx, fileSystemName) if err != nil { err = autorest.NewErrorWithError(err, "datalakestore.Client", "Delete", nil, "Failure preparing request") return @@ -41,7 +37,7 @@ func (client Client) Delete(ctx context.Context, accountName string, fileSystemN } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName string, fileSystemName string) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, fileSystemName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "fileSystemName": autorest.Encode("path", fileSystemName), } @@ -56,7 +52,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName string, fil preparer := autorest.CreatePreparer( autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{fileSystemName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/datalakestore/filesystems/lifecycle_test.go b/storage/2020-08-04/datalakestore/filesystems/lifecycle_test.go index c496c92..36ea61a 100644 --- a/storage/2020-08-04/datalakestore/filesystems/lifecycle_test.go +++ b/storage/2020-08-04/datalakestore/filesystems/lifecycle_test.go @@ -27,7 +27,7 @@ func TestLifecycle(t *testing.T) { t.Fatal(err) } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - fileSystemsClient := NewWithEnvironment(client.AutoRestEnvironment) + fileSystemsClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) fileSystemsClient.Client = client.PrepareWithStorageResourceManagerAuth(fileSystemsClient.Client) t.Logf("[DEBUG] Creating an empty File System..") @@ -36,12 +36,12 @@ func TestLifecycle(t *testing.T) { "hello": "aGVsbG8=", }, } - if _, err = fileSystemsClient.Create(ctx, accountName, fileSystemName, input); err != nil { + if _, err = fileSystemsClient.Create(ctx, fileSystemName, input); err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } t.Logf("[DEBUG] Retrieving the Properties..") - props, err := fileSystemsClient.GetProperties(ctx, accountName, fileSystemName) + props, err := fileSystemsClient.GetProperties(ctx, fileSystemName) if err != nil { t.Fatal(fmt.Errorf("Error getting properties: %s", err)) } @@ -60,12 +60,12 @@ func TestLifecycle(t *testing.T) { "private": "ZXll", }, } - if _, err := fileSystemsClient.SetProperties(ctx, accountName, fileSystemName, setInput); err != nil { + if _, err := fileSystemsClient.SetProperties(ctx, fileSystemName, setInput); err != nil { t.Fatalf("Error setting properties: %s", err) } t.Logf("[DEBUG] Re-Retrieving the Properties..") - props, err = fileSystemsClient.GetProperties(ctx, accountName, fileSystemName) + props, err = fileSystemsClient.GetProperties(ctx, fileSystemName) if err != nil { t.Fatal(fmt.Errorf("Error getting properties: %s", err)) } @@ -80,7 +80,7 @@ func TestLifecycle(t *testing.T) { } t.Logf("[DEBUG] Deleting File System..") - if _, err := fileSystemsClient.Delete(ctx, accountName, fileSystemName); err != nil { + if _, err := fileSystemsClient.Delete(ctx, fileSystemName); err != nil { t.Fatalf("Error deleting: %s", err) } } diff --git a/storage/2020-08-04/datalakestore/filesystems/properties_get.go b/storage/2020-08-04/datalakestore/filesystems/properties_get.go index 0b96c95..d51cfc6 100644 --- a/storage/2020-08-04/datalakestore/filesystems/properties_get.go +++ b/storage/2020-08-04/datalakestore/filesystems/properties_get.go @@ -8,7 +8,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 GetPropertiesResponse struct { @@ -25,15 +24,12 @@ type GetPropertiesResponse struct { } // GetProperties gets the properties for a Data Lake Store Gen2 FileSystem within a Storage Account -func (client Client) GetProperties(ctx context.Context, accountName string, fileSystemName string) (result GetPropertiesResponse, err error) { - if accountName == "" { - return result, validation.NewError("datalakestore.Client", "GetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) GetProperties(ctx context.Context, fileSystemName string) (result GetPropertiesResponse, err error) { if fileSystemName == "" { return result, validation.NewError("datalakestore.Client", "GetProperties", "`fileSystemName` cannot be an empty string.") } - req, err := client.GetPropertiesPreparer(ctx, accountName, fileSystemName) + req, err := client.GetPropertiesPreparer(ctx, fileSystemName) if err != nil { err = autorest.NewErrorWithError(err, "datalakestore.Client", "GetProperties", nil, "Failure preparing request") return @@ -55,7 +51,7 @@ func (client Client) GetProperties(ctx context.Context, accountName string, file } // GetPropertiesPreparer prepares the GetProperties request. -func (client Client) GetPropertiesPreparer(ctx context.Context, accountName string, fileSystemName string) (*http.Request, error) { +func (client Client) GetPropertiesPreparer(ctx context.Context, fileSystemName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "fileSystemName": autorest.Encode("path", fileSystemName), } @@ -70,7 +66,7 @@ func (client Client) GetPropertiesPreparer(ctx context.Context, accountName stri preparer := autorest.CreatePreparer( autorest.AsHead(), - autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{fileSystemName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/datalakestore/filesystems/properties_set.go b/storage/2020-08-04/datalakestore/filesystems/properties_set.go index dde02a4..c21899f 100644 --- a/storage/2020-08-04/datalakestore/filesystems/properties_set.go +++ b/storage/2020-08-04/datalakestore/filesystems/properties_set.go @@ -7,7 +7,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 SetPropertiesInput struct { @@ -27,15 +26,12 @@ type SetPropertiesInput struct { } // SetProperties sets the Properties for a Data Lake Store Gen2 FileSystem within a Storage Account -func (client Client) SetProperties(ctx context.Context, accountName string, fileSystemName string, input SetPropertiesInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("datalakestore.Client", "SetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) SetProperties(ctx context.Context, fileSystemName string, input SetPropertiesInput) (result autorest.Response, err error) { if fileSystemName == "" { return result, validation.NewError("datalakestore.Client", "SetProperties", "`fileSystemName` cannot be an empty string.") } - req, err := client.SetPropertiesPreparer(ctx, accountName, fileSystemName, input) + req, err := client.SetPropertiesPreparer(ctx, fileSystemName, input) if err != nil { err = autorest.NewErrorWithError(err, "datalakestore.Client", "SetProperties", nil, "Failure preparing request") return @@ -57,7 +53,7 @@ func (client Client) SetProperties(ctx context.Context, accountName string, file } // SetPropertiesPreparer prepares the SetProperties request. -func (client Client) SetPropertiesPreparer(ctx context.Context, accountName string, fileSystemName string, input SetPropertiesInput) (*http.Request, error) { +func (client Client) SetPropertiesPreparer(ctx context.Context, fileSystemName string, input SetPropertiesInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "fileSystemName": autorest.Encode("path", fileSystemName), } @@ -80,7 +76,7 @@ func (client Client) SetPropertiesPreparer(ctx context.Context, accountName stri preparer := autorest.CreatePreparer( autorest.AsPatch(), - autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{fileSystemName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/datalakestore/filesystems/resource_id.go b/storage/2020-08-04/datalakestore/filesystems/resource_id.go index 34797b2..2a9c875 100644 --- a/storage/2020-08-04/datalakestore/filesystems/resource_id.go +++ b/storage/2020-08-04/datalakestore/filesystems/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given Data Lake Storage FileSystem // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, shareName string) string { - domain := endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s", domain, shareName) +func (client Client) GetResourceID(shareName string) string { + return fmt.Sprintf("%s/%s", client.endpoint, shareName) } type ResourceID struct { diff --git a/storage/2020-08-04/datalakestore/filesystems/resource_id_test.go b/storage/2020-08-04/datalakestore/filesystems/resource_id_test.go index 7e0d401..c40ea29 100644 --- a/storage/2020-08-04/datalakestore/filesystems/resource_id_test.go +++ b/storage/2020-08-04/datalakestore/filesystems/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "directory1") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("directory1") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } diff --git a/storage/2020-08-04/datalakestore/paths/client.go b/storage/2020-08-04/datalakestore/paths/client.go index 3fb087b..f81cb47 100644 --- a/storage/2020-08-04/datalakestore/paths/client.go +++ b/storage/2020-08-04/datalakestore/paths/client.go @@ -3,23 +3,32 @@ package paths 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 Data Lake Storage Path type Client struct { autorest.Client - BaseURI string + endpoint string } // New creates an instance of the Data Lake Storage Path client. -func New() Client { - return NewWithEnvironment(azure.PublicCloud) +func New(accountName string) Client { + return NewWithEnvironment(accountName, azure.PublicCloud) } // NewWithEnvironment creates an instance of the Data Lake Storage Path 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.BuildDataLakeStoreEndpoint(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, } } diff --git a/storage/2020-08-04/datalakestore/paths/create.go b/storage/2020-08-04/datalakestore/paths/create.go index 600bd75..48f7a54 100644 --- a/storage/2020-08-04/datalakestore/paths/create.go +++ b/storage/2020-08-04/datalakestore/paths/create.go @@ -7,7 +7,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 PathResource string @@ -20,15 +19,12 @@ type CreateInput struct { } // Create creates a Data Lake Store Gen2 Path within a Storage Account -func (client Client) Create(ctx context.Context, accountName string, fileSystemName string, path string, input CreateInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("datalakestore.Client", "Create", "`accountName` cannot be an empty string.") - } +func (client Client) Create(ctx context.Context, fileSystemName string, path string, input CreateInput) (result autorest.Response, err error) { if fileSystemName == "" { return result, validation.NewError("datalakestore.Client", "Create", "`fileSystemName` cannot be an empty string.") } - req, err := client.CreatePreparer(ctx, accountName, fileSystemName, path, input) + req, err := client.CreatePreparer(ctx, fileSystemName, path, input) if err != nil { err = autorest.NewErrorWithError(err, "datalakestore.Client", "Create", nil, "Failure preparing request") return @@ -50,7 +46,7 @@ func (client Client) Create(ctx context.Context, accountName string, fileSystemN } // CreatePreparer prepares the Create request. -func (client Client) CreatePreparer(ctx context.Context, accountName string, fileSystemName string, path string, input CreateInput) (*http.Request, error) { +func (client Client) CreatePreparer(ctx context.Context, fileSystemName string, path string, input CreateInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "fileSystemName": autorest.Encode("path", fileSystemName), "path": autorest.Encode("path", path), @@ -66,7 +62,7 @@ func (client Client) CreatePreparer(ctx context.Context, accountName string, fil preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{fileSystemName}/{path}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/datalakestore/paths/create_test.go b/storage/2020-08-04/datalakestore/paths/create_test.go index 675afbb..d4c1ab7 100644 --- a/storage/2020-08-04/datalakestore/paths/create_test.go +++ b/storage/2020-08-04/datalakestore/paths/create_test.go @@ -30,31 +30,31 @@ func TestCreateDirectory(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - fileSystemsClient := filesystems.NewWithEnvironment(client.AutoRestEnvironment) + fileSystemsClient := filesystems.NewWithEnvironment(accountName, client.AutoRestEnvironment) fileSystemsClient.Client = client.PrepareWithStorageResourceManagerAuth(fileSystemsClient.Client) t.Logf("[DEBUG] Creating an empty File System..") fileSystemInput := filesystems.CreateInput{ Properties: map[string]string{}, } - if _, err = fileSystemsClient.Create(ctx, accountName, fileSystemName, fileSystemInput); err != nil { + if _, err = fileSystemsClient.Create(ctx, fileSystemName, fileSystemInput); err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } t.Logf("[DEBUG] Creating path..") - pathsClient := NewWithEnvironment(client.AutoRestEnvironment) + pathsClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) pathsClient.Client = client.PrepareWithStorageResourceManagerAuth(pathsClient.Client) input := CreateInput{ Resource: PathResourceDirectory, } - if _, err = pathsClient.Create(ctx, accountName, fileSystemName, path, input); err != nil { + if _, err = pathsClient.Create(ctx, fileSystemName, path, input); err != nil { t.Fatal(fmt.Errorf("Error creating path: %s", err)) } t.Logf("[DEBUG] Deleting File System..") - if _, err := fileSystemsClient.Delete(ctx, accountName, fileSystemName); err != nil { + if _, err := fileSystemsClient.Delete(ctx, fileSystemName); err != nil { t.Fatalf("Error deleting: %s", err) } } diff --git a/storage/2020-08-04/datalakestore/paths/delete.go b/storage/2020-08-04/datalakestore/paths/delete.go index 078be57..c8dfc91 100644 --- a/storage/2020-08-04/datalakestore/paths/delete.go +++ b/storage/2020-08-04/datalakestore/paths/delete.go @@ -7,19 +7,15 @@ 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" ) // Delete deletes a Data Lake Store Gen2 FileSystem within a Storage Account -func (client Client) Delete(ctx context.Context, accountName string, fileSystemName string, path string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("datalakestore.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, fileSystemName string, path string) (result autorest.Response, err error) { if fileSystemName == "" { return result, validation.NewError("datalakestore.Client", "Delete", "`fileSystemName` cannot be an empty string.") } - req, err := client.DeletePreparer(ctx, accountName, fileSystemName, path) + req, err := client.DeletePreparer(ctx, fileSystemName, path) if err != nil { err = autorest.NewErrorWithError(err, "datalakestore.Client", "Delete", nil, "Failure preparing request") return @@ -41,7 +37,7 @@ func (client Client) Delete(ctx context.Context, accountName string, fileSystemN } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName string, fileSystemName string, path string) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, fileSystemName string, path string) (*http.Request, error) { pathParameters := map[string]interface{}{ "fileSystemName": autorest.Encode("path", fileSystemName), "path": autorest.Encode("path", path), @@ -53,7 +49,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName string, fil preparer := autorest.CreatePreparer( autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{fileSystemName}/{path}", pathParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/datalakestore/paths/lifecycle_test.go b/storage/2020-08-04/datalakestore/paths/lifecycle_test.go index 4161b4d..0ebd793 100644 --- a/storage/2020-08-04/datalakestore/paths/lifecycle_test.go +++ b/storage/2020-08-04/datalakestore/paths/lifecycle_test.go @@ -31,14 +31,14 @@ func TestLifecycle(t *testing.T) { t.Fatal(err) } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - fileSystemsClient := filesystems.NewWithEnvironment(client.AutoRestEnvironment) + fileSystemsClient := filesystems.NewWithEnvironment(accountName, client.AutoRestEnvironment) fileSystemsClient.Client = client.PrepareWithStorageResourceManagerAuth(fileSystemsClient.Client) - pathsClient := NewWithEnvironment(client.AutoRestEnvironment) + pathsClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) pathsClient.Client = client.PrepareWithStorageResourceManagerAuth(fileSystemsClient.Client) t.Logf("[DEBUG] Creating an empty File System..") fileSystemInput := filesystems.CreateInput{} - if _, err = fileSystemsClient.Create(ctx, accountName, fileSystemName, fileSystemInput); err != nil { + if _, err = fileSystemsClient.Create(ctx, fileSystemName, fileSystemInput); err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } @@ -46,12 +46,12 @@ func TestLifecycle(t *testing.T) { input := CreateInput{ Resource: PathResourceDirectory, } - if _, err = pathsClient.Create(ctx, accountName, fileSystemName, path, input); err != nil { + if _, err = pathsClient.Create(ctx, fileSystemName, path, input); err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } t.Logf("[DEBUG] Getting properties for folder 'test' ..") - props, err := pathsClient.GetProperties(ctx, accountName, fileSystemName, path, GetPropertiesActionGetAccessControl) + props, err := pathsClient.GetProperties(ctx, fileSystemName, path, GetPropertiesActionGetAccessControl) if err != nil { t.Fatal(fmt.Errorf("Error getting properties: %s", err)) } @@ -69,12 +69,12 @@ func TestLifecycle(t *testing.T) { ACL: &newACL, } t.Logf("[DEBUG] Setting Access Control for folder 'test' ..") - if _, err = pathsClient.SetAccessControl(ctx, accountName, fileSystemName, path, accessControlInput); err != nil { + if _, err = pathsClient.SetAccessControl(ctx, fileSystemName, path, accessControlInput); err != nil { t.Fatal(fmt.Errorf("Error setting Access Control %s", err)) } t.Logf("[DEBUG] Getting properties for folder 'test' (2) ..") - props, err = pathsClient.GetProperties(ctx, accountName, fileSystemName, path, GetPropertiesActionGetAccessControl) + props, err = pathsClient.GetProperties(ctx, fileSystemName, path, GetPropertiesActionGetAccessControl) if err != nil { t.Fatal(fmt.Errorf("Error getting properties (2): %s", err)) } @@ -83,18 +83,18 @@ func TestLifecycle(t *testing.T) { } t.Logf("[DEBUG] Deleting path 'test' ..") - if _, err = pathsClient.Delete(ctx, accountName, fileSystemName, path); err != nil { + if _, err = pathsClient.Delete(ctx, fileSystemName, path); err != nil { t.Fatal(fmt.Errorf("Error deleting path: %s", err)) } t.Logf("[DEBUG] Getting properties for folder 'test' (3) ..") - props, err = pathsClient.GetProperties(ctx, accountName, fileSystemName, path, GetPropertiesActionGetAccessControl) + props, err = pathsClient.GetProperties(ctx, fileSystemName, path, GetPropertiesActionGetAccessControl) if err == nil { t.Fatal(fmt.Errorf("Didn't get error getting properties after deleting path (3)")) } t.Logf("[DEBUG] Deleting File System..") - if _, err := fileSystemsClient.Delete(ctx, accountName, fileSystemName); err != nil { + if _, err := fileSystemsClient.Delete(ctx, fileSystemName); err != nil { t.Fatalf("Error deleting filesystem: %s", err) } } diff --git a/storage/2020-08-04/datalakestore/paths/properties_get.go b/storage/2020-08-04/datalakestore/paths/properties_get.go index 263dc53..a2dad69 100644 --- a/storage/2020-08-04/datalakestore/paths/properties_get.go +++ b/storage/2020-08-04/datalakestore/paths/properties_get.go @@ -8,7 +8,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 GetPropertiesResponse struct { @@ -32,15 +31,12 @@ const ( ) // GetProperties gets the properties for a Data Lake Store Gen2 Path in a FileSystem within a Storage Account -func (client Client) GetProperties(ctx context.Context, accountName string, fileSystemName string, path string, action GetPropertiesAction) (result GetPropertiesResponse, err error) { - if accountName == "" { - return result, validation.NewError("datalakestore.Client", "GetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) GetProperties(ctx context.Context, fileSystemName string, path string, action GetPropertiesAction) (result GetPropertiesResponse, err error) { if fileSystemName == "" { return result, validation.NewError("datalakestore.Client", "GetProperties", "`fileSystemName` cannot be an empty string.") } - req, err := client.GetPropertiesPreparer(ctx, accountName, fileSystemName, path, action) + req, err := client.GetPropertiesPreparer(ctx, fileSystemName, path, action) if err != nil { err = autorest.NewErrorWithError(err, "datalakestore.Client", "GetProperties", nil, "Failure preparing request") return @@ -62,7 +58,7 @@ func (client Client) GetProperties(ctx context.Context, accountName string, file } // GetPropertiesPreparer prepares the GetProperties request. -func (client Client) GetPropertiesPreparer(ctx context.Context, accountName string, fileSystemName string, path string, action GetPropertiesAction) (*http.Request, error) { +func (client Client) GetPropertiesPreparer(ctx context.Context, fileSystemName string, path string, action GetPropertiesAction) (*http.Request, error) { pathParameters := map[string]interface{}{ "fileSystemName": autorest.Encode("path", fileSystemName), "path": autorest.Encode("path", path), @@ -78,7 +74,7 @@ func (client Client) GetPropertiesPreparer(ctx context.Context, accountName stri preparer := autorest.CreatePreparer( autorest.AsHead(), - autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{fileSystemName}/{path}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/datalakestore/paths/properties_set.go b/storage/2020-08-04/datalakestore/paths/properties_set.go index 7c0d677..0c8196e 100644 --- a/storage/2020-08-04/datalakestore/paths/properties_set.go +++ b/storage/2020-08-04/datalakestore/paths/properties_set.go @@ -7,7 +7,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 SetAccessControlInput struct { @@ -25,15 +24,12 @@ type SetAccessControlInput struct { } // SetProperties sets the access control properties for a Data Lake Store Gen2 Path within a Storage Account File System -func (client Client) SetAccessControl(ctx context.Context, accountName string, fileSystemName string, path string, input SetAccessControlInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("datalakestore.Client", "SetAccessControl", "`accountName` cannot be an empty string.") - } +func (client Client) SetAccessControl(ctx context.Context, fileSystemName string, path string, input SetAccessControlInput) (result autorest.Response, err error) { if fileSystemName == "" { return result, validation.NewError("datalakestore.Client", "SetAccessControl", "`fileSystemName` cannot be an empty string.") } - req, err := client.SetAccessControlPreparer(ctx, accountName, fileSystemName, path, input) + req, err := client.SetAccessControlPreparer(ctx, fileSystemName, path, input) if err != nil { err = autorest.NewErrorWithError(err, "datalakestore.Client", "SetAccessControl", nil, "Failure preparing request") return @@ -55,7 +51,7 @@ func (client Client) SetAccessControl(ctx context.Context, accountName string, f } // SetAccessControlPreparer prepares the SetAccessControl request. -func (client Client) SetAccessControlPreparer(ctx context.Context, accountName string, fileSystemName string, path string, input SetAccessControlInput) (*http.Request, error) { +func (client Client) SetAccessControlPreparer(ctx context.Context, fileSystemName string, path string, input SetAccessControlInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "fileSystemName": autorest.Encode("path", fileSystemName), "path": autorest.Encode("path", path), @@ -88,7 +84,7 @@ func (client Client) SetAccessControlPreparer(ctx context.Context, accountName s preparer := autorest.CreatePreparer( autorest.AsPatch(), - autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{fileSystemName}/{path}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/datalakestore/paths/resource_id.go b/storage/2020-08-04/datalakestore/paths/resource_id.go index c328418..f9a8742 100644 --- a/storage/2020-08-04/datalakestore/paths/resource_id.go +++ b/storage/2020-08-04/datalakestore/paths/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given Data Lake Storage FileSystem // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, fileSystemName, path string) string { - domain := endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s/%s", domain, fileSystemName, path) +func (client Client) GetResourceID(fileSystemName, path string) string { + return fmt.Sprintf("%s/%s/%s", client.endpoint, fileSystemName, path) } type ResourceID struct { diff --git a/storage/2020-08-04/datalakestore/paths/resource_id_test.go b/storage/2020-08-04/datalakestore/paths/resource_id_test.go index da94e23..c972db3 100644 --- a/storage/2020-08-04/datalakestore/paths/resource_id_test.go +++ b/storage/2020-08-04/datalakestore/paths/resource_id_test.go @@ -34,8 +34,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Path %q", v.Path) - c := NewWithEnvironment(azure.PublicCloud) - actual := c.GetResourceID(v.AccountName, v.FileSystemName, v.Path) + c := NewWithEnvironment(v.AccountName, azure.PublicCloud) + actual := c.GetResourceID(v.FileSystemName, v.Path) if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } diff --git a/storage/2020-08-04/file/directories/api.go b/storage/2020-08-04/file/directories/api.go index 2699e66..381e5d6 100644 --- a/storage/2020-08-04/file/directories/api.go +++ b/storage/2020-08-04/file/directories/api.go @@ -7,10 +7,10 @@ import ( ) type StorageDirectory interface { - Delete(ctx context.Context, accountName, shareName, path string) (result autorest.Response, err error) - GetMetaData(ctx context.Context, accountName, shareName, path string) (result GetMetaDataResult, err error) - SetMetaData(ctx context.Context, accountName, shareName, path string, metaData map[string]string) (result autorest.Response, err error) - Create(ctx context.Context, accountName, shareName, path string, input CreateDirectoryInput) (result autorest.Response, err error) - GetResourceID(accountName, shareName, directoryName string) string - Get(ctx context.Context, accountName, shareName, path string) (result GetResult, err error) + Delete(ctx context.Context, shareName, path string) (result autorest.Response, err error) + GetMetaData(ctx context.Context, shareName, path string) (result GetMetaDataResult, err error) + SetMetaData(ctx context.Context, shareName, path string, metaData map[string]string) (result autorest.Response, err error) + Create(ctx context.Context, shareName, path string, input CreateDirectoryInput) (result autorest.Response, err error) + GetResourceID(shareName, directoryName string) string + Get(ctx context.Context, shareName, path string) (result GetResult, err error) } diff --git a/storage/2020-08-04/file/directories/client.go b/storage/2020-08-04/file/directories/client.go index bf2d315..a8b2d25 100644 --- a/storage/2020-08-04/file/directories/client.go +++ b/storage/2020-08-04/file/directories/client.go @@ -3,23 +3,32 @@ package directories 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 File Storage Shares. 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) } // NewWithEnvironment 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.BuildFileEndpoint(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, } } diff --git a/storage/2020-08-04/file/directories/create.go b/storage/2020-08-04/file/directories/create.go index 3729831..c463df7 100644 --- a/storage/2020-08-04/file/directories/create.go +++ b/storage/2020-08-04/file/directories/create.go @@ -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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -30,10 +29,7 @@ type CreateDirectoryInput struct { } // Create creates a new directory under the specified share or parent directory. -func (client Client) Create(ctx context.Context, accountName, shareName, path string, input CreateDirectoryInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("directories.Client", "Create", "`accountName` cannot be an empty string.") - } +func (client Client) Create(ctx context.Context, shareName, path string, input CreateDirectoryInput) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("directories.Client", "Create", "`shareName` cannot be an empty string.") } @@ -47,7 +43,7 @@ func (client Client) Create(ctx context.Context, accountName, shareName, path st return result, validation.NewError("directories.Client", "Create", fmt.Sprintf("`metadata` is not valid: %s.", err)) } - req, err := client.CreatePreparer(ctx, accountName, shareName, path, input) + req, err := client.CreatePreparer(ctx, shareName, path, input) if err != nil { err = autorest.NewErrorWithError(err, "directories.Client", "Create", nil, "Failure preparing request") return @@ -70,7 +66,7 @@ func (client Client) Create(ctx context.Context, accountName, shareName, path st } // CreatePreparer prepares the Create request. -func (client Client) CreatePreparer(ctx context.Context, accountName, shareName, path string, input CreateDirectoryInput) (*http.Request, error) { +func (client Client) CreatePreparer(ctx context.Context, shareName, path string, input CreateDirectoryInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), "directory": autorest.Encode("path", path), @@ -103,7 +99,7 @@ func (client Client) CreatePreparer(ctx context.Context, accountName, shareName, preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/directories/delete.go b/storage/2020-08-04/file/directories/delete.go index 9443c25..12483f1 100644 --- a/storage/2020-08-04/file/directories/delete.go +++ b/storage/2020-08-04/file/directories/delete.go @@ -8,15 +8,11 @@ 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" ) // Delete removes the specified empty directory // Note that the directory must be empty before it can be deleted. -func (client Client) Delete(ctx context.Context, accountName, shareName, path string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("directories.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, shareName, path string) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("directories.Client", "Delete", "`shareName` cannot be an empty string.") } @@ -27,7 +23,7 @@ func (client Client) Delete(ctx context.Context, accountName, shareName, path st return result, validation.NewError("directories.Client", "Delete", "`path` cannot be an empty string.") } - req, err := client.DeletePreparer(ctx, accountName, shareName, path) + req, err := client.DeletePreparer(ctx, shareName, path) if err != nil { err = autorest.NewErrorWithError(err, "directories.Client", "Delete", nil, "Failure preparing request") return @@ -50,7 +46,7 @@ func (client Client) Delete(ctx context.Context, accountName, shareName, path st } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName, shareName, path string) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, shareName, path string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), "directory": autorest.Encode("path", path), @@ -67,7 +63,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName, shareName, preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/directories/get.go b/storage/2020-08-04/file/directories/get.go index 817d680..179cb2a 100644 --- a/storage/2020-08-04/file/directories/get.go +++ b/storage/2020-08-04/file/directories/get.go @@ -8,7 +8,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -25,10 +24,7 @@ type GetResult struct { // Get returns all system properties for the specified directory, // and can also be used to check the existence of a directory. -func (client Client) Get(ctx context.Context, accountName, shareName, path string) (result GetResult, err error) { - if accountName == "" { - return result, validation.NewError("directories.Client", "Get", "`accountName` cannot be an empty string.") - } +func (client Client) Get(ctx context.Context, shareName, path string) (result GetResult, err error) { if shareName == "" { return result, validation.NewError("directories.Client", "Get", "`shareName` cannot be an empty string.") } @@ -39,7 +35,7 @@ func (client Client) Get(ctx context.Context, accountName, shareName, path strin return result, validation.NewError("directories.Client", "Get", "`path` cannot be an empty string.") } - req, err := client.GetPreparer(ctx, accountName, shareName, path) + req, err := client.GetPreparer(ctx, shareName, path) if err != nil { err = autorest.NewErrorWithError(err, "directories.Client", "Get", nil, "Failure preparing request") return @@ -62,7 +58,7 @@ func (client Client) Get(ctx context.Context, accountName, shareName, path strin } // GetPreparer prepares the Get request. -func (client Client) GetPreparer(ctx context.Context, accountName, shareName, path string) (*http.Request, error) { +func (client Client) GetPreparer(ctx context.Context, shareName, path string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), "directory": autorest.Encode("path", path), @@ -79,7 +75,7 @@ func (client Client) GetPreparer(ctx context.Context, accountName, shareName, pa preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/directories/lifecycle_test.go b/storage/2020-08-04/file/directories/lifecycle_test.go index a89d3d9..a8f02f9 100644 --- a/storage/2020-08-04/file/directories/lifecycle_test.go +++ b/storage/2020-08-04/file/directories/lifecycle_test.go @@ -38,20 +38,20 @@ func TestDirectoriesLifeCycle(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - sharesClient := shares.NewWithEnvironment(client.AutoRestEnvironment) + sharesClient := shares.NewWithEnvironment(accountName, client.AutoRestEnvironment) sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth) - directoriesClient := NewWithEnvironment(client.AutoRestEnvironment) + directoriesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) directoriesClient.Client = client.PrepareWithAuthorizer(directoriesClient.Client, storageAuth) input := shares.CreateInput{ QuotaInGB: 1, } - _, err = sharesClient.Create(ctx, accountName, shareName, input) + _, err = sharesClient.Create(ctx, shareName, input) if err != nil { t.Fatalf("Error creating fileshare: %s", err) } - defer sharesClient.Delete(ctx, accountName, shareName, true) + defer sharesClient.Delete(ctx, shareName, true) metaData := map[string]string{ "hello": "world", @@ -61,17 +61,17 @@ func TestDirectoriesLifeCycle(t *testing.T) { createInput := CreateDirectoryInput{ MetaData: metaData, } - if _, err := directoriesClient.Create(ctx, accountName, shareName, "hello", createInput); err != nil { + if _, err := directoriesClient.Create(ctx, shareName, "hello", createInput); err != nil { t.Fatalf("Error creating Top Level Directory: %s", err) } log.Printf("[DEBUG] Creating Inner..") - if _, err := directoriesClient.Create(ctx, accountName, shareName, "hello/there", createInput); err != nil { + if _, err := directoriesClient.Create(ctx, shareName, "hello/there", createInput); err != nil { t.Fatalf("Error creating Inner Directory: %s", err) } log.Printf("[DEBUG] Retrieving share") - innerDir, err := directoriesClient.Get(ctx, accountName, shareName, "hello/there") + innerDir, err := directoriesClient.Get(ctx, shareName, "hello/there") if err != nil { t.Fatalf("Error retrieving Inner Directory: %s", err) } @@ -91,12 +91,12 @@ func TestDirectoriesLifeCycle(t *testing.T) { updatedMetaData := map[string]string{ "panda": "pops", } - if _, err := directoriesClient.SetMetaData(ctx, accountName, shareName, "hello/there", updatedMetaData); err != nil { + if _, err := directoriesClient.SetMetaData(ctx, shareName, "hello/there", updatedMetaData); err != nil { t.Fatalf("Error updating MetaData: %s", err) } log.Printf("[DEBUG] Retrieving MetaData") - retrievedMetaData, err := directoriesClient.GetMetaData(ctx, accountName, shareName, "hello/there") + retrievedMetaData, err := directoriesClient.GetMetaData(ctx, shareName, "hello/there") if err != nil { t.Fatalf("Error retrieving the updated metadata: %s", err) } @@ -108,12 +108,12 @@ func TestDirectoriesLifeCycle(t *testing.T) { } t.Logf("[DEBUG] Deleting Inner..") - if _, err := directoriesClient.Delete(ctx, accountName, shareName, "hello/there"); err != nil { + if _, err := directoriesClient.Delete(ctx, shareName, "hello/there"); err != nil { t.Fatalf("Error deleting Inner Directory: %s", err) } t.Logf("[DEBUG] Deleting Top Level..") - if _, err := directoriesClient.Delete(ctx, accountName, shareName, "hello"); err != nil { + if _, err := directoriesClient.Delete(ctx, shareName, "hello"); err != nil { t.Fatalf("Error deleting Top Level Directory: %s", err) } } diff --git a/storage/2020-08-04/file/directories/metadata_get.go b/storage/2020-08-04/file/directories/metadata_get.go index 173716d..a312542 100644 --- a/storage/2020-08-04/file/directories/metadata_get.go +++ b/storage/2020-08-04/file/directories/metadata_get.go @@ -8,7 +8,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -19,10 +18,7 @@ type GetMetaDataResult struct { } // GetMetaData returns all user-defined metadata for the specified directory -func (client Client) GetMetaData(ctx context.Context, accountName, shareName, path string) (result GetMetaDataResult, err error) { - if accountName == "" { - return result, validation.NewError("directories.Client", "GetMetaData", "`accountName` cannot be an empty string.") - } +func (client Client) GetMetaData(ctx context.Context, shareName, path string) (result GetMetaDataResult, err error) { if shareName == "" { return result, validation.NewError("directories.Client", "GetMetaData", "`shareName` cannot be an empty string.") } @@ -33,7 +29,7 @@ func (client Client) GetMetaData(ctx context.Context, accountName, shareName, pa return result, validation.NewError("directories.Client", "GetMetaData", "`path` cannot be an empty string.") } - req, err := client.GetMetaDataPreparer(ctx, accountName, shareName, path) + req, err := client.GetMetaDataPreparer(ctx, shareName, path) if err != nil { err = autorest.NewErrorWithError(err, "directories.Client", "GetMetaData", nil, "Failure preparing request") return @@ -56,7 +52,7 @@ func (client Client) GetMetaData(ctx context.Context, accountName, shareName, pa } // GetMetaDataPreparer prepares the GetMetaData request. -func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, shareName, path string) (*http.Request, error) { +func (client Client) GetMetaDataPreparer(ctx context.Context, shareName, path string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), "directory": autorest.Encode("path", path), @@ -74,7 +70,7 @@ func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, share preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/directories/metadata_set.go b/storage/2020-08-04/file/directories/metadata_set.go index cb13312..d2fba8c 100644 --- a/storage/2020-08-04/file/directories/metadata_set.go +++ b/storage/2020-08-04/file/directories/metadata_set.go @@ -9,15 +9,11 @@ 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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) // SetMetaData updates user defined metadata for the specified directory -func (client Client) SetMetaData(ctx context.Context, accountName, shareName, path string, metaData map[string]string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("directories.Client", "SetMetaData", "`accountName` cannot be an empty string.") - } +func (client Client) SetMetaData(ctx context.Context, shareName, path string, metaData map[string]string) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("directories.Client", "SetMetaData", "`shareName` cannot be an empty string.") } @@ -31,7 +27,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, shareName, pa return result, validation.NewError("directories.Client", "SetMetaData", fmt.Sprintf("`metaData` is not valid: %s.", err)) } - req, err := client.SetMetaDataPreparer(ctx, accountName, shareName, path, metaData) + req, err := client.SetMetaDataPreparer(ctx, shareName, path, metaData) if err != nil { err = autorest.NewErrorWithError(err, "directories.Client", "SetMetaData", nil, "Failure preparing request") return @@ -54,7 +50,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, shareName, pa } // SetMetaDataPreparer prepares the SetMetaData request. -func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, shareName, path string, metaData map[string]string) (*http.Request, error) { +func (client Client) SetMetaDataPreparer(ctx context.Context, shareName, path string, metaData map[string]string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), "directory": autorest.Encode("path", path), @@ -74,7 +70,7 @@ func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, share preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/directories/resource_id.go b/storage/2020-08-04/file/directories/resource_id.go index 712ed3a..a0896cf 100644 --- a/storage/2020-08-04/file/directories/resource_id.go +++ b/storage/2020-08-04/file/directories/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given Directory // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, shareName, directoryName string) string { - domain := endpoints.GetFileEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s/%s", domain, shareName, directoryName) +func (client Client) GetResourceID(shareName, directoryName string) string { + return fmt.Sprintf("%s/%s/%s", client.endpoint, shareName, directoryName) } type ResourceID struct { diff --git a/storage/2020-08-04/file/directories/resource_id_test.go b/storage/2020-08-04/file/directories/resource_id_test.go index d3c15ab..63e9213 100644 --- a/storage/2020-08-04/file/directories/resource_id_test.go +++ b/storage/2020-08-04/file/directories/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "share1", "directory1") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("share1", "directory1") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } diff --git a/storage/2020-08-04/file/files/README.md b/storage/2020-08-04/file/files/README.md index 6ce6bbb..87eadbd 100644 --- a/storage/2020-08-04/file/files/README.md +++ b/storage/2020-08-04/file/files/README.md @@ -38,10 +38,10 @@ func Example() error { ctx := context.TODO() input := files.CreateInput{} - if _, err := filesClient.Create(ctx, accountName, shareName, directoryName, fileName, input); err != nil { + if _, err := filesClient.Create(ctx, shareName, directoryName, fileName, input); err != nil { return fmt.Errorf("Error creating File: %s", err) } return nil } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/file/files/api.go b/storage/2020-08-04/file/files/api.go index 96a0491..8b9f7b2 100644 --- a/storage/2020-08-04/file/files/api.go +++ b/storage/2020-08-04/file/files/api.go @@ -9,20 +9,20 @@ import ( ) type StorageFile interface { - PutByteRange(ctx context.Context, accountName, shareName, path, fileName string, input PutByteRangeInput) (result autorest.Response, err error) - GetByteRange(ctx context.Context, accountName, shareName, path, fileName string, input GetByteRangeInput) (result GetByteRangeResult, err error) - ClearByteRange(ctx context.Context, accountName, shareName, path, fileName string, input ClearByteRangeInput) (result autorest.Response, err error) - SetProperties(ctx context.Context, accountName, shareName, path, fileName string, input SetPropertiesInput) (result autorest.Response, err error) - PutFile(ctx context.Context, accountName, shareName, path, fileName string, file *os.File, parallelism int) error - Copy(ctx context.Context, accountName, shareName, path, fileName string, input CopyInput) (result CopyResult, err error) - SetMetaData(ctx context.Context, accountName, shareName, path, fileName string, metaData map[string]string) (result autorest.Response, err error) - GetMetaData(ctx context.Context, accountName, shareName, path, fileName string) (result GetMetaDataResult, err error) - AbortCopy(ctx context.Context, accountName, shareName, path, fileName, copyID string) (result autorest.Response, err error) - GetFile(ctx context.Context, accountName, shareName, path, fileName string, parallelism int) (result autorest.Response, outputBytes []byte, err error) - GetResourceID(accountName, shareName, directoryName, filePath string) string - ListRanges(ctx context.Context, accountName, shareName, path, fileName string) (result ListRangesResult, err error) - GetProperties(ctx context.Context, accountName, shareName, path, fileName string) (result GetResult, err error) - Delete(ctx context.Context, accountName, shareName, path, fileName string) (result autorest.Response, err error) - Create(ctx context.Context, accountName, shareName, path, fileName string, input CreateInput) (result autorest.Response, err error) - CopyAndWait(ctx context.Context, accountName, shareName, path, fileName string, input CopyInput, pollDuration time.Duration) (result CopyResult, err error) + PutByteRange(ctx context.Context, shareName, path, fileName string, input PutByteRangeInput) (result autorest.Response, err error) + GetByteRange(ctx context.Context, shareName, path, fileName string, input GetByteRangeInput) (result GetByteRangeResult, err error) + ClearByteRange(ctx context.Context, shareName, path, fileName string, input ClearByteRangeInput) (result autorest.Response, err error) + SetProperties(ctx context.Context, shareName, path, fileName string, input SetPropertiesInput) (result autorest.Response, err error) + PutFile(ctx context.Context, shareName, path, fileName string, file *os.File, parallelism int) error + Copy(ctx context.Context, shareName, path, fileName string, input CopyInput) (result CopyResult, err error) + SetMetaData(ctx context.Context, shareName, path, fileName string, metaData map[string]string) (result autorest.Response, err error) + GetMetaData(ctx context.Context, shareName, path, fileName string) (result GetMetaDataResult, err error) + AbortCopy(ctx context.Context, shareName, path, fileName, copyID string) (result autorest.Response, err error) + GetFile(ctx context.Context, shareName, path, fileName string, parallelism int) (result autorest.Response, outputBytes []byte, err error) + GetResourceID(shareName, directoryName, filePath string) string + ListRanges(ctx context.Context, shareName, path, fileName string) (result ListRangesResult, err error) + GetProperties(ctx context.Context, shareName, path, fileName string) (result GetResult, err error) + Delete(ctx context.Context, shareName, path, fileName string) (result autorest.Response, err error) + Create(ctx context.Context, shareName, path, fileName string, input CreateInput) (result autorest.Response, err error) + CopyAndWait(ctx context.Context, shareName, path, fileName string, input CopyInput, pollDuration time.Duration) (result CopyResult, err error) } diff --git a/storage/2020-08-04/file/files/client.go b/storage/2020-08-04/file/files/client.go index ecca815..320c04b 100644 --- a/storage/2020-08-04/file/files/client.go +++ b/storage/2020-08-04/file/files/client.go @@ -3,23 +3,32 @@ package files 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 File Storage Shares. 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) } // NewWithEnvironment 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.BuildFileEndpoint(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, } } diff --git a/storage/2020-08-04/file/files/copy.go b/storage/2020-08-04/file/files/copy.go index 31768b3..a78102b 100644 --- a/storage/2020-08-04/file/files/copy.go +++ b/storage/2020-08-04/file/files/copy.go @@ -9,7 +9,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -37,10 +36,7 @@ type CopyResult struct { } // Copy copies a blob or file to a destination file within the storage account asynchronously. -func (client Client) Copy(ctx context.Context, accountName, shareName, path, fileName string, input CopyInput) (result CopyResult, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "Copy", "`accountName` cannot be an empty string.") - } +func (client Client) Copy(ctx context.Context, shareName, path, fileName string, input CopyInput) (result CopyResult, err error) { if shareName == "" { return result, validation.NewError("files.Client", "Copy", "`shareName` cannot be an empty string.") } @@ -57,7 +53,7 @@ func (client Client) Copy(ctx context.Context, accountName, shareName, path, fil return result, validation.NewError("files.Client", "Copy", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) } - req, err := client.CopyPreparer(ctx, accountName, shareName, path, fileName, input) + req, err := client.CopyPreparer(ctx, shareName, path, fileName, input) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "Copy", nil, "Failure preparing request") return @@ -80,7 +76,7 @@ func (client Client) Copy(ctx context.Context, accountName, shareName, path, fil } // CopyPreparer prepares the Copy request. -func (client Client) CopyPreparer(ctx context.Context, accountName, shareName, path, fileName string, input CopyInput) (*http.Request, error) { +func (client Client) CopyPreparer(ctx context.Context, shareName, path, fileName string, input CopyInput) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -100,7 +96,7 @@ func (client Client) CopyPreparer(ctx context.Context, accountName, shareName, p preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/file/files/copy_abort.go b/storage/2020-08-04/file/files/copy_abort.go index 2f09131..6afe431 100644 --- a/storage/2020-08-04/file/files/copy_abort.go +++ b/storage/2020-08-04/file/files/copy_abort.go @@ -9,14 +9,10 @@ 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" ) // AbortCopy aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata -func (client Client) AbortCopy(ctx context.Context, accountName, shareName, path, fileName, copyID string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "AbortCopy", "`accountName` cannot be an empty string.") - } +func (client Client) AbortCopy(ctx context.Context, shareName, path, fileName, copyID string) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("files.Client", "AbortCopy", "`shareName` cannot be an empty string.") } @@ -30,7 +26,7 @@ func (client Client) AbortCopy(ctx context.Context, accountName, shareName, path return result, validation.NewError("files.Client", "AbortCopy", "`copyID` cannot be an empty string.") } - req, err := client.AbortCopyPreparer(ctx, accountName, shareName, path, fileName, copyID) + req, err := client.AbortCopyPreparer(ctx, shareName, path, fileName, copyID) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "AbortCopy", nil, "Failure preparing request") return @@ -53,7 +49,7 @@ func (client Client) AbortCopy(ctx context.Context, accountName, shareName, path } // AbortCopyPreparer prepares the AbortCopy request. -func (client Client) AbortCopyPreparer(ctx context.Context, accountName, shareName, path, fileName, copyID string) (*http.Request, error) { +func (client Client) AbortCopyPreparer(ctx context.Context, shareName, path, fileName, copyID string) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -76,7 +72,7 @@ func (client Client) AbortCopyPreparer(ctx context.Context, accountName, shareNa preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/files/copy_wait.go b/storage/2020-08-04/file/files/copy_wait.go index e6a646b..37ed211 100644 --- a/storage/2020-08-04/file/files/copy_wait.go +++ b/storage/2020-08-04/file/files/copy_wait.go @@ -18,8 +18,8 @@ type CopyAndWaitResult struct { const DefaultCopyPollDuration = 15 * time.Second // CopyAndWait is a convenience method which doesn't exist in the API, which copies the file and then waits for the copy to complete -func (client Client) CopyAndWait(ctx context.Context, accountName, shareName, path, fileName string, input CopyInput, pollDuration time.Duration) (result CopyResult, err error) { - copy, e := client.Copy(ctx, accountName, shareName, path, fileName, input) +func (client Client) CopyAndWait(ctx context.Context, shareName, path, fileName string, input CopyInput, pollDuration time.Duration) (result CopyResult, err error) { + copy, e := client.Copy(ctx, shareName, path, fileName, input) if err != nil { result.Response = copy.Response err = fmt.Errorf("Error copying: %s", e) @@ -30,7 +30,7 @@ func (client Client) CopyAndWait(ctx context.Context, accountName, shareName, pa // since the API doesn't return a LRO, this is a hack which also polls every 10s, but should be sufficient for true { - props, e := client.GetProperties(ctx, accountName, shareName, path, fileName) + props, e := client.GetProperties(ctx, shareName, path, fileName) if e != nil { result.Response = copy.Response err = fmt.Errorf("Error waiting for copy: %s", e) diff --git a/storage/2020-08-04/file/files/copy_wait_test.go b/storage/2020-08-04/file/files/copy_wait_test.go index 0a5b282..ae37daf 100644 --- a/storage/2020-08-04/file/files/copy_wait_test.go +++ b/storage/2020-08-04/file/files/copy_wait_test.go @@ -10,7 +10,6 @@ import ( "github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage" "github.com/Azure/go-autorest/autorest" "github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" "github.com/tombuildsstuff/giovanni/storage/internal/testhelpers" ) @@ -22,7 +21,7 @@ func TestFilesCopyAndWaitFromURL(t *testing.T) { if err != nil { t.Fatal(err) } - + resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt()) accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString()) shareName := fmt.Sprintf("share-%d", testhelpers.RandomInt()) @@ -37,19 +36,19 @@ func TestFilesCopyAndWaitFromURL(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - sharesClient := shares.NewWithEnvironment(client.AutoRestEnvironment) + sharesClient := shares.NewWithEnvironment(accountName, client.AutoRestEnvironment) sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth) input := shares.CreateInput{ QuotaInGB: 10, } - _, err = sharesClient.Create(ctx, accountName, shareName, input) + _, err = sharesClient.Create(ctx, shareName, input) if err != nil { t.Fatalf("Error creating fileshare: %s", err) } - defer sharesClient.Delete(ctx, accountName, shareName, false) + defer sharesClient.Delete(ctx, shareName, false) - filesClient := NewWithEnvironment(client.AutoRestEnvironment) + filesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) filesClient.Client = client.PrepareWithAuthorizer(filesClient.Client, storageAuth) copiedFileName := "ubuntu.iso" @@ -58,13 +57,13 @@ func TestFilesCopyAndWaitFromURL(t *testing.T) { } t.Logf("[DEBUG] Copy And Waiting..") - if _, err := filesClient.CopyAndWait(ctx, accountName, shareName, "", copiedFileName, copyInput, DefaultCopyPollDuration); err != nil { + if _, err := filesClient.CopyAndWait(ctx, shareName, "", copiedFileName, copyInput, DefaultCopyPollDuration); err != nil { t.Fatalf("Error copy & waiting: %s", err) } t.Logf("[DEBUG] Asserting that the file's ready..") - props, err := filesClient.GetProperties(ctx, accountName, shareName, "", copiedFileName) + props, err := filesClient.GetProperties(ctx, shareName, "", copiedFileName) if err != nil { t.Fatalf("Error retrieving file: %s", err) } @@ -97,19 +96,19 @@ func TestFilesCopyAndWaitFromBlob(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - sharesClient := shares.NewWithEnvironment(client.AutoRestEnvironment) + sharesClient := shares.NewWithEnvironment(accountName, client.AutoRestEnvironment) sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth) input := shares.CreateInput{ QuotaInGB: 10, } - _, err = sharesClient.Create(ctx, accountName, shareName, input) + _, err = sharesClient.Create(ctx, shareName, input) if err != nil { t.Fatalf("Error creating fileshare: %s", err) } - defer sharesClient.Delete(ctx, accountName, shareName, false) + defer sharesClient.Delete(ctx, shareName, false) - filesClient := NewWithEnvironment(client.AutoRestEnvironment) + filesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) filesClient.Client = client.PrepareWithAuthorizer(filesClient.Client, storageAuth) originalFileName := "ubuntu.iso" @@ -118,20 +117,20 @@ func TestFilesCopyAndWaitFromBlob(t *testing.T) { CopySource: "http://releases.ubuntu.com/14.04/ubuntu-14.04.6-desktop-amd64.iso", } t.Logf("[DEBUG] Copy And Waiting the original file..") - if _, err := filesClient.CopyAndWait(ctx, accountName, shareName, "", originalFileName, copyInput, DefaultCopyPollDuration); err != nil { + if _, err := filesClient.CopyAndWait(ctx, shareName, "", originalFileName, copyInput, DefaultCopyPollDuration); err != nil { t.Fatalf("Error copy & waiting: %s", err) } t.Logf("[DEBUG] Now copying that blob..") duplicateInput := CopyInput{ - CopySource: fmt.Sprintf("%s/%s/%s", endpoints.GetFileEndpoint(filesClient.BaseURI, accountName), shareName, originalFileName), + CopySource: fmt.Sprintf("%s/%s/%s", filesClient.endpoint, shareName, originalFileName), } - if _, err := filesClient.CopyAndWait(ctx, accountName, shareName, "", copiedFileName, duplicateInput, DefaultCopyPollDuration); err != nil { + if _, err := filesClient.CopyAndWait(ctx, shareName, "", copiedFileName, duplicateInput, DefaultCopyPollDuration); err != nil { t.Fatalf("Error copying duplicate: %s", err) } t.Logf("[DEBUG] Asserting that the file's ready..") - props, err := filesClient.GetProperties(ctx, accountName, shareName, "", copiedFileName) + props, err := filesClient.GetProperties(ctx, shareName, "", copiedFileName) if err != nil { t.Fatalf("Error retrieving file: %s", err) } diff --git a/storage/2020-08-04/file/files/create.go b/storage/2020-08-04/file/files/create.go index d2b4ff3..4b3c566 100644 --- a/storage/2020-08-04/file/files/create.go +++ b/storage/2020-08-04/file/files/create.go @@ -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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -52,10 +51,7 @@ type CreateInput struct { } // Create creates a new file or replaces a file. -func (client Client) Create(ctx context.Context, accountName, shareName, path, fileName string, input CreateInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "Create", "`accountName` cannot be an empty string.") - } +func (client Client) Create(ctx context.Context, shareName, path, fileName string, input CreateInput) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("files.Client", "Create", "`shareName` cannot be an empty string.") } @@ -69,7 +65,7 @@ func (client Client) Create(ctx context.Context, accountName, shareName, path, f return result, validation.NewError("files.Client", "Create", "`input.MetaData` cannot be an empty string.") } - req, err := client.CreatePreparer(ctx, accountName, shareName, path, fileName, input) + req, err := client.CreatePreparer(ctx, shareName, path, fileName, input) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "Create", nil, "Failure preparing request") return @@ -92,7 +88,7 @@ func (client Client) Create(ctx context.Context, accountName, shareName, path, f } // CreatePreparer prepares the Create request. -func (client Client) CreatePreparer(ctx context.Context, accountName, shareName, path, fileName string, input CreateInput) (*http.Request, error) { +func (client Client) CreatePreparer(ctx context.Context, shareName, path, fileName string, input CreateInput) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -142,7 +138,7 @@ func (client Client) CreatePreparer(ctx context.Context, accountName, shareName, preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/file/files/delete.go b/storage/2020-08-04/file/files/delete.go index 5debd76..04fa313 100644 --- a/storage/2020-08-04/file/files/delete.go +++ b/storage/2020-08-04/file/files/delete.go @@ -9,14 +9,10 @@ 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" ) // Delete immediately deletes the file from the File Share. -func (client Client) Delete(ctx context.Context, accountName, shareName, path, fileName string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, shareName, path, fileName string) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("files.Client", "Delete", "`shareName` cannot be an empty string.") } @@ -27,7 +23,7 @@ func (client Client) Delete(ctx context.Context, accountName, shareName, path, f return result, validation.NewError("files.Client", "Delete", "`fileName` cannot be an empty string.") } - req, err := client.DeletePreparer(ctx, accountName, shareName, path, fileName) + req, err := client.DeletePreparer(ctx, shareName, path, fileName) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "Delete", nil, "Failure preparing request") return @@ -50,7 +46,7 @@ func (client Client) Delete(ctx context.Context, accountName, shareName, path, f } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName, shareName, path, fileName string) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, shareName, path, fileName string) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -67,7 +63,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName, shareName, preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/file/files/lifecycle_test.go b/storage/2020-08-04/file/files/lifecycle_test.go index 77399a4..33bc17c 100644 --- a/storage/2020-08-04/file/files/lifecycle_test.go +++ b/storage/2020-08-04/file/files/lifecycle_test.go @@ -37,19 +37,19 @@ func TestFilesLifeCycle(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - sharesClient := shares.NewWithEnvironment(client.AutoRestEnvironment) + sharesClient := shares.NewWithEnvironment(accountName, client.AutoRestEnvironment) sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth) input := shares.CreateInput{ QuotaInGB: 1, } - _, err = sharesClient.Create(ctx, accountName, shareName, input) + _, err = sharesClient.Create(ctx, shareName, input) if err != nil { t.Fatalf("Error creating fileshare: %s", err) } - defer sharesClient.Delete(ctx, accountName, shareName, false) + defer sharesClient.Delete(ctx, shareName, false) - filesClient := NewWithEnvironment(client.AutoRestEnvironment) + filesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) filesClient.Client = client.PrepareWithAuthorizer(filesClient.Client, storageAuth) fileName := "bled5.png" @@ -60,12 +60,12 @@ func TestFilesLifeCycle(t *testing.T) { ContentLength: 1024, ContentEncoding: &contentEncoding, } - if _, err := filesClient.Create(ctx, accountName, shareName, "", fileName, createInput); err != nil { + if _, err := filesClient.Create(ctx, shareName, "", fileName, createInput); err != nil { t.Fatalf("Error creating Top-Level File: %s", err) } t.Logf("[DEBUG] Retrieving Properties for the Top-Level File..") - file, err := filesClient.GetProperties(ctx, accountName, shareName, "", fileName) + file, err := filesClient.GetProperties(ctx, shareName, "", fileName) if err != nil { t.Fatalf("Error retrieving Top-Level File: %s", err) } @@ -88,12 +88,12 @@ func TestFilesLifeCycle(t *testing.T) { }, } t.Logf("[DEBUG] Setting Properties for the Top-Level File..") - if _, err := filesClient.SetProperties(ctx, accountName, shareName, "", fileName, updatedInput); err != nil { + if _, err := filesClient.SetProperties(ctx, shareName, "", fileName, updatedInput); err != nil { t.Fatalf("Error setting properties: %s", err) } t.Logf("[DEBUG] Re-retrieving Properties for the Top-Level File..") - file, err = filesClient.GetProperties(ctx, accountName, shareName, "", fileName) + file, err = filesClient.GetProperties(ctx, shareName, "", fileName) if err != nil { t.Fatalf("Error retrieving Top-Level File: %s", err) } @@ -117,12 +117,12 @@ func TestFilesLifeCycle(t *testing.T) { metaData := map[string]string{ "hello": "there", } - if _, err := filesClient.SetMetaData(ctx, accountName, shareName, "", fileName, metaData); err != nil { + if _, err := filesClient.SetMetaData(ctx, shareName, "", fileName, metaData); err != nil { t.Fatalf("Error setting MetaData: %s", err) } t.Logf("[DEBUG] Retrieving MetaData..") - retrievedMetaData, err := filesClient.GetMetaData(ctx, accountName, shareName, "", fileName) + retrievedMetaData, err := filesClient.GetMetaData(ctx, shareName, "", fileName) if err != nil { t.Fatalf("Error retrieving MetaData: %s", err) } @@ -138,12 +138,12 @@ func TestFilesLifeCycle(t *testing.T) { "hello": "there", "second": "thing", } - if _, err := filesClient.SetMetaData(ctx, accountName, shareName, "", fileName, metaData); err != nil { + if _, err := filesClient.SetMetaData(ctx, shareName, "", fileName, metaData); err != nil { t.Fatalf("Error setting MetaData: %s", err) } t.Logf("[DEBUG] Re-Retrieving MetaData..") - retrievedMetaData, err = filesClient.GetMetaData(ctx, accountName, shareName, "", fileName) + retrievedMetaData, err = filesClient.GetMetaData(ctx, shareName, "", fileName) if err != nil { t.Fatalf("Error retrieving MetaData: %s", err) } @@ -158,7 +158,7 @@ func TestFilesLifeCycle(t *testing.T) { } t.Logf("[DEBUG] Deleting Top Level File..") - if _, err := filesClient.Delete(ctx, accountName, shareName, "", fileName); err != nil { + if _, err := filesClient.Delete(ctx, shareName, "", fileName); err != nil { t.Fatalf("Error deleting Top-Level File: %s", err) } } diff --git a/storage/2020-08-04/file/files/metadata_get.go b/storage/2020-08-04/file/files/metadata_get.go index fd62f90..a146ef9 100644 --- a/storage/2020-08-04/file/files/metadata_get.go +++ b/storage/2020-08-04/file/files/metadata_get.go @@ -9,7 +9,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -20,10 +19,7 @@ type GetMetaDataResult struct { } // GetMetaData returns the MetaData for the specified File. -func (client Client) GetMetaData(ctx context.Context, accountName, shareName, path, fileName string) (result GetMetaDataResult, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "GetMetaData", "`accountName` cannot be an empty string.") - } +func (client Client) GetMetaData(ctx context.Context, shareName, path, fileName string) (result GetMetaDataResult, err error) { if shareName == "" { return result, validation.NewError("files.Client", "GetMetaData", "`shareName` cannot be an empty string.") } @@ -34,7 +30,7 @@ func (client Client) GetMetaData(ctx context.Context, accountName, shareName, pa return result, validation.NewError("files.Client", "GetMetaData", "`fileName` cannot be an empty string.") } - req, err := client.GetMetaDataPreparer(ctx, accountName, shareName, path, fileName) + req, err := client.GetMetaDataPreparer(ctx, shareName, path, fileName) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "GetMetaData", nil, "Failure preparing request") return @@ -57,7 +53,7 @@ func (client Client) GetMetaData(ctx context.Context, accountName, shareName, pa } // GetMetaDataPreparer prepares the GetMetaData request. -func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, shareName, path, fileName string) (*http.Request, error) { +func (client Client) GetMetaDataPreparer(ctx context.Context, shareName, path, fileName string) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -78,7 +74,7 @@ func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, share preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/files/metadata_set.go b/storage/2020-08-04/file/files/metadata_set.go index 41e3ffc..78c33e5 100644 --- a/storage/2020-08-04/file/files/metadata_set.go +++ b/storage/2020-08-04/file/files/metadata_set.go @@ -9,15 +9,11 @@ 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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) // SetMetaData updates the specified File to have the specified MetaData. -func (client Client) SetMetaData(ctx context.Context, accountName, shareName, path, fileName string, metaData map[string]string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "SetMetaData", "`accountName` cannot be an empty string.") - } +func (client Client) SetMetaData(ctx context.Context, shareName, path, fileName string, metaData map[string]string) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("files.Client", "SetMetaData", "`shareName` cannot be an empty string.") } @@ -31,7 +27,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, shareName, pa return result, validation.NewError("files.Client", "SetMetaData", fmt.Sprintf("`metaData` is not valid: %s.", err)) } - req, err := client.SetMetaDataPreparer(ctx, accountName, shareName, path, fileName, metaData) + req, err := client.SetMetaDataPreparer(ctx, shareName, path, fileName, metaData) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "SetMetaData", nil, "Failure preparing request") return @@ -54,7 +50,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, shareName, pa } // SetMetaDataPreparer prepares the SetMetaData request. -func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, shareName, path, fileName string, metaData map[string]string) (*http.Request, error) { +func (client Client) SetMetaDataPreparer(ctx context.Context, shareName, path, fileName string, metaData map[string]string) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -77,7 +73,7 @@ func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, share preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/files/properties_get.go b/storage/2020-08-04/file/files/properties_get.go index 0300b1c..9d2a6d0 100644 --- a/storage/2020-08-04/file/files/properties_get.go +++ b/storage/2020-08-04/file/files/properties_get.go @@ -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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -36,10 +35,7 @@ type GetResult struct { } // GetProperties returns the Properties for the specified file -func (client Client) GetProperties(ctx context.Context, accountName, shareName, path, fileName string) (result GetResult, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "GetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) GetProperties(ctx context.Context, shareName, path, fileName string) (result GetResult, err error) { if shareName == "" { return result, validation.NewError("files.Client", "GetProperties", "`shareName` cannot be an empty string.") } @@ -50,7 +46,7 @@ func (client Client) GetProperties(ctx context.Context, accountName, shareName, return result, validation.NewError("files.Client", "GetProperties", "`fileName` cannot be an empty string.") } - req, err := client.GetPropertiesPreparer(ctx, accountName, shareName, path, fileName) + req, err := client.GetPropertiesPreparer(ctx, shareName, path, fileName) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "GetProperties", nil, "Failure preparing request") return @@ -73,7 +69,7 @@ func (client Client) GetProperties(ctx context.Context, accountName, shareName, } // GetPropertiesPreparer prepares the GetProperties request. -func (client Client) GetPropertiesPreparer(ctx context.Context, accountName, shareName, path, fileName string) (*http.Request, error) { +func (client Client) GetPropertiesPreparer(ctx context.Context, shareName, path, fileName string) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -90,7 +86,7 @@ func (client Client) GetPropertiesPreparer(ctx context.Context, accountName, sha preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsHead(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/file/files/properties_set.go b/storage/2020-08-04/file/files/properties_set.go index 521b1bb..14f83b0 100644 --- a/storage/2020-08-04/file/files/properties_set.go +++ b/storage/2020-08-04/file/files/properties_set.go @@ -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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -69,10 +68,7 @@ type SetPropertiesInput struct { } // SetProperties sets the specified properties on the specified File -func (client Client) SetProperties(ctx context.Context, accountName, shareName, path, fileName string, input SetPropertiesInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "SetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) SetProperties(ctx context.Context, shareName, path, fileName string, input SetPropertiesInput) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("files.Client", "SetProperties", "`shareName` cannot be an empty string.") } @@ -83,7 +79,7 @@ func (client Client) SetProperties(ctx context.Context, accountName, shareName, return result, validation.NewError("files.Client", "SetProperties", "`fileName` cannot be an empty string.") } - req, err := client.SetPropertiesPreparer(ctx, accountName, shareName, path, fileName, input) + req, err := client.SetPropertiesPreparer(ctx, shareName, path, fileName, input) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "SetProperties", nil, "Failure preparing request") return @@ -106,7 +102,7 @@ func (client Client) SetProperties(ctx context.Context, accountName, shareName, } // SetPropertiesPreparer prepares the SetProperties request. -func (client Client) SetPropertiesPreparer(ctx context.Context, accountName, shareName, path, fileName string, input SetPropertiesInput) (*http.Request, error) { +func (client Client) SetPropertiesPreparer(ctx context.Context, shareName, path, fileName string, input SetPropertiesInput) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -159,7 +155,7 @@ func (client Client) SetPropertiesPreparer(ctx context.Context, accountName, sha preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/file/files/range_clear.go b/storage/2020-08-04/file/files/range_clear.go index 5d8145f..6bc0c23 100644 --- a/storage/2020-08-04/file/files/range_clear.go +++ b/storage/2020-08-04/file/files/range_clear.go @@ -9,7 +9,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 ClearByteRangeInput struct { @@ -18,10 +17,7 @@ type ClearByteRangeInput struct { } // ClearByteRange clears the specified Byte Range from within the specified File -func (client Client) ClearByteRange(ctx context.Context, accountName, shareName, path, fileName string, input ClearByteRangeInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "ClearByteRange", "`accountName` cannot be an empty string.") - } +func (client Client) ClearByteRange(ctx context.Context, shareName, path, fileName string, input ClearByteRangeInput) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("files.Client", "ClearByteRange", "`shareName` cannot be an empty string.") } @@ -38,7 +34,7 @@ func (client Client) ClearByteRange(ctx context.Context, accountName, shareName, return result, validation.NewError("files.Client", "ClearByteRange", "`input.EndBytes` must be greater than 0.") } - req, err := client.ClearByteRangePreparer(ctx, accountName, shareName, path, fileName, input) + req, err := client.ClearByteRangePreparer(ctx, shareName, path, fileName, input) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "ClearByteRange", nil, "Failure preparing request") return @@ -61,7 +57,7 @@ func (client Client) ClearByteRange(ctx context.Context, accountName, shareName, } // ClearByteRangePreparer prepares the ClearByteRange request. -func (client Client) ClearByteRangePreparer(ctx context.Context, accountName, shareName, path, fileName string, input ClearByteRangeInput) (*http.Request, error) { +func (client Client) ClearByteRangePreparer(ctx context.Context, shareName, path, fileName string, input ClearByteRangeInput) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -84,7 +80,7 @@ func (client Client) ClearByteRangePreparer(ctx context.Context, accountName, sh preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/file/files/range_get.go b/storage/2020-08-04/file/files/range_get.go index 733d3f5..450ae80 100644 --- a/storage/2020-08-04/file/files/range_get.go +++ b/storage/2020-08-04/file/files/range_get.go @@ -9,7 +9,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 GetByteRangeInput struct { @@ -24,10 +23,7 @@ type GetByteRangeResult struct { } // GetByteRange returns the specified Byte Range from the specified File. -func (client Client) GetByteRange(ctx context.Context, accountName, shareName, path, fileName string, input GetByteRangeInput) (result GetByteRangeResult, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "GetByteRange", "`accountName` cannot be an empty string.") - } +func (client Client) GetByteRange(ctx context.Context, shareName, path, fileName string, input GetByteRangeInput) (result GetByteRangeResult, err error) { if shareName == "" { return result, validation.NewError("files.Client", "GetByteRange", "`shareName` cannot be an empty string.") } @@ -51,7 +47,7 @@ func (client Client) GetByteRange(ctx context.Context, accountName, shareName, p return result, validation.NewError("files.Client", "GetByteRange", "Requested Byte Range must be at most 4MB.") } - req, err := client.GetByteRangePreparer(ctx, accountName, shareName, path, fileName, input) + req, err := client.GetByteRangePreparer(ctx, shareName, path, fileName, input) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "GetByteRange", nil, "Failure preparing request") return @@ -74,7 +70,7 @@ func (client Client) GetByteRange(ctx context.Context, accountName, shareName, p } // GetByteRangePreparer prepares the GetByteRange request. -func (client Client) GetByteRangePreparer(ctx context.Context, accountName, shareName, path, fileName string, input GetByteRangeInput) (*http.Request, error) { +func (client Client) GetByteRangePreparer(ctx context.Context, shareName, path, fileName string, input GetByteRangeInput) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -91,7 +87,7 @@ func (client Client) GetByteRangePreparer(ctx context.Context, accountName, shar preparer := autorest.CreatePreparer( autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/file/files/range_get_file.go b/storage/2020-08-04/file/files/range_get_file.go index 9e5be17..dcdd7bb 100644 --- a/storage/2020-08-04/file/files/range_get_file.go +++ b/storage/2020-08-04/file/files/range_get_file.go @@ -12,10 +12,10 @@ import ( ) // GetFile is a helper method to download a file by chunking it automatically -func (client Client) GetFile(ctx context.Context, accountName, shareName, path, fileName string, parallelism int) (result autorest.Response, outputBytes []byte, err error) { +func (client Client) GetFile(ctx context.Context, shareName, path, fileName string, parallelism int) (result autorest.Response, outputBytes []byte, err error) { // first look up the file and check out how many bytes it is - file, e := client.GetProperties(ctx, accountName, shareName, path, fileName) + file, e := client.GetProperties(ctx, shareName, path, fileName) if err != nil { result = file.Response err = e @@ -57,7 +57,7 @@ func (client Client) GetFile(ctx context.Context, accountName, shareName, path, fileSize: length, } - result, err := client.downloadFileChunk(ctx, accountName, shareName, path, fileName, dfci) + result, err := client.downloadFileChunk(ctx, shareName, path, fileName, dfci) if err != nil { errors <- err waitGroup.Done() @@ -100,7 +100,7 @@ type downloadFileChunkResult struct { bytes []byte } -func (client Client) downloadFileChunk(ctx context.Context, accountName, shareName, path, fileName string, input downloadFileChunkInput) (*downloadFileChunkResult, error) { +func (client Client) downloadFileChunk(ctx context.Context, shareName, path, fileName string, input downloadFileChunkInput) (*downloadFileChunkResult, error) { startBytes := input.chunkSize * int64(input.thisChunk) endBytes := startBytes + input.chunkSize @@ -114,7 +114,7 @@ func (client Client) downloadFileChunk(ctx context.Context, accountName, shareNa StartBytes: startBytes, EndBytes: endBytes, } - result, err := client.GetByteRange(ctx, accountName, shareName, path, fileName, getInput) + result, err := client.GetByteRange(ctx, shareName, path, fileName, getInput) if err != nil { return nil, fmt.Errorf("Error putting bytes: %s", err) } diff --git a/storage/2020-08-04/file/files/range_get_file_test.go b/storage/2020-08-04/file/files/range_get_file_test.go index 46e6e30..28af476 100644 --- a/storage/2020-08-04/file/files/range_get_file_test.go +++ b/storage/2020-08-04/file/files/range_get_file_test.go @@ -46,19 +46,19 @@ func testGetFile(t *testing.T, fileName string, contentType string) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - sharesClient := shares.NewWithEnvironment(client.AutoRestEnvironment) + sharesClient := shares.NewWithEnvironment(accountName, client.AutoRestEnvironment) sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth) input := shares.CreateInput{ QuotaInGB: 10, } - _, err = sharesClient.Create(ctx, accountName, shareName, input) + _, err = sharesClient.Create(ctx, shareName, input) if err != nil { t.Fatalf("Error creating fileshare: %s", err) } - defer sharesClient.Delete(ctx, accountName, shareName, false) + defer sharesClient.Delete(ctx, shareName, false) - filesClient := NewWithEnvironment(client.AutoRestEnvironment) + filesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) filesClient.Client = client.PrepareWithAuthorizer(filesClient.Client, storageAuth) // store files outside of this directory, since they're reused @@ -77,17 +77,17 @@ func testGetFile(t *testing.T, fileName string, contentType string) { ContentLength: info.Size(), ContentType: &contentType, } - if _, err := filesClient.Create(ctx, accountName, shareName, "", fileName, createFileInput); err != nil { + if _, err := filesClient.Create(ctx, shareName, "", fileName, createFileInput); err != nil { t.Fatalf("Error creating Top-Level File: %s", err) } t.Logf("[DEBUG] Uploading File..") - if err := filesClient.PutFile(ctx, accountName, shareName, "", fileName, file, 4); err != nil { + if err := filesClient.PutFile(ctx, shareName, "", fileName, file, 4); err != nil { t.Fatalf("Error uploading File: %s", err) } t.Logf("[DEBUG] Downloading file..") - _, downloadedBytes, err := filesClient.GetFile(ctx, accountName, shareName, "", fileName, 4) + _, downloadedBytes, err := filesClient.GetFile(ctx, shareName, "", fileName, 4) if err != nil { t.Fatalf("Error downloading file: %s", err) } @@ -108,7 +108,7 @@ func testGetFile(t *testing.T, fileName string, contentType string) { } t.Logf("[DEBUG] Deleting Top Level File..") - if _, err := filesClient.Delete(ctx, accountName, shareName, "", fileName); err != nil { + if _, err := filesClient.Delete(ctx, shareName, "", fileName); err != nil { t.Fatalf("Error deleting Top-Level File: %s", err) } diff --git a/storage/2020-08-04/file/files/range_put.go b/storage/2020-08-04/file/files/range_put.go index 20e4d39..32a3f30 100644 --- a/storage/2020-08-04/file/files/range_put.go +++ b/storage/2020-08-04/file/files/range_put.go @@ -9,7 +9,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 PutByteRangeInput struct { @@ -22,10 +21,7 @@ type PutByteRangeInput struct { } // PutByteRange puts the specified Byte Range in the specified File. -func (client Client) PutByteRange(ctx context.Context, accountName, shareName, path, fileName string, input PutByteRangeInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "PutByteRange", "`accountName` cannot be an empty string.") - } +func (client Client) PutByteRange(ctx context.Context, shareName, path, fileName string, input PutByteRangeInput) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("files.Client", "PutByteRange", "`shareName` cannot be an empty string.") } @@ -52,7 +48,7 @@ func (client Client) PutByteRange(ctx context.Context, accountName, shareName, p return result, validation.NewError("files.Client", "PutByteRange", "Specified Byte Range must be at most 4MB.") } - req, err := client.PutByteRangePreparer(ctx, accountName, shareName, path, fileName, input) + req, err := client.PutByteRangePreparer(ctx, shareName, path, fileName, input) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "PutByteRange", nil, "Failure preparing request") return @@ -75,7 +71,7 @@ func (client Client) PutByteRange(ctx context.Context, accountName, shareName, p } // PutByteRangePreparer prepares the PutByteRange request. -func (client Client) PutByteRangePreparer(ctx context.Context, accountName, shareName, path, fileName string, input PutByteRangeInput) (*http.Request, error) { +func (client Client) PutByteRangePreparer(ctx context.Context, shareName, path, fileName string, input PutByteRangeInput) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -98,7 +94,7 @@ func (client Client) PutByteRangePreparer(ctx context.Context, accountName, shar preparer := autorest.CreatePreparer( autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters), diff --git a/storage/2020-08-04/file/files/range_put_file.go b/storage/2020-08-04/file/files/range_put_file.go index a74845d..1b381d3 100644 --- a/storage/2020-08-04/file/files/range_put_file.go +++ b/storage/2020-08-04/file/files/range_put_file.go @@ -13,7 +13,7 @@ import ( ) // PutFile is a helper method which takes a file, and automatically chunks it up, rather than having to do this yourself -func (client Client) PutFile(ctx context.Context, accountName, shareName, path, fileName string, file *os.File, parallelism int) error { +func (client Client) PutFile(ctx context.Context, shareName, path, fileName string, file *os.File, parallelism int) error { fileInfo, err := file.Stat() if err != nil { return fmt.Errorf("Error loading file info: %s", err) @@ -48,7 +48,7 @@ func (client Client) PutFile(ctx context.Context, accountName, shareName, path, fileSize: fileSize, } - _, err := client.uploadChunk(ctx, accountName, shareName, path, fileName, uci, file) + _, err := client.uploadChunk(ctx, shareName, path, fileName, uci, file) if err != nil { errors <- err } @@ -77,7 +77,7 @@ type uploadChunkInput struct { fileSize int64 } -func (client Client) uploadChunk(ctx context.Context, accountName, shareName, path, fileName string, input uploadChunkInput, file *os.File) (result autorest.Response, err error) { +func (client Client) uploadChunk(ctx context.Context, shareName, path, fileName string, input uploadChunkInput, file *os.File) (result autorest.Response, err error) { startBytes := int64(input.chunkSize * input.thisChunk) endBytes := startBytes + int64(input.chunkSize) @@ -102,7 +102,7 @@ func (client Client) uploadChunk(ctx context.Context, accountName, shareName, pa EndBytes: endBytes, Content: bytes, } - result, err = client.PutByteRange(ctx, accountName, shareName, path, fileName, putBytesInput) + result, err = client.PutByteRange(ctx, shareName, path, fileName, putBytesInput) if err != nil { return result, fmt.Errorf("Error putting bytes: %s", err) } diff --git a/storage/2020-08-04/file/files/range_put_file_test.go b/storage/2020-08-04/file/files/range_put_file_test.go index 6843d9d..9b21743 100644 --- a/storage/2020-08-04/file/files/range_put_file_test.go +++ b/storage/2020-08-04/file/files/range_put_file_test.go @@ -51,19 +51,19 @@ func testPutFile(t *testing.T, fileName string, contentType string) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - sharesClient := shares.NewWithEnvironment(client.AutoRestEnvironment) + sharesClient := shares.NewWithEnvironment(accountName, client.AutoRestEnvironment) sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth) input := shares.CreateInput{ QuotaInGB: 10, } - _, err = sharesClient.Create(ctx, accountName, shareName, input) + _, err = sharesClient.Create(ctx, shareName, input) if err != nil { t.Fatalf("Error creating fileshare: %s", err) } - defer sharesClient.Delete(ctx, accountName, shareName, false) + defer sharesClient.Delete(ctx, shareName, false) - filesClient := NewWithEnvironment(client.AutoRestEnvironment) + filesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) filesClient.Client = client.PrepareWithAuthorizer(filesClient.Client, storageAuth) // store files outside of this directory, since they're reused @@ -82,17 +82,17 @@ func testPutFile(t *testing.T, fileName string, contentType string) { ContentLength: info.Size(), ContentType: &contentType, } - if _, err := filesClient.Create(ctx, accountName, shareName, "", fileName, createFileInput); err != nil { + if _, err := filesClient.Create(ctx, shareName, "", fileName, createFileInput); err != nil { t.Fatalf("Error creating Top-Level File: %s", err) } t.Logf("[DEBUG] Uploading File..") - if err := filesClient.PutFile(ctx, accountName, shareName, "", fileName, file, 4); err != nil { + if err := filesClient.PutFile(ctx, shareName, "", fileName, file, 4); err != nil { t.Fatalf("Error uploading File: %s", err) } t.Logf("[DEBUG] Deleting Top Level File..") - if _, err := filesClient.Delete(ctx, accountName, shareName, "", fileName); err != nil { + if _, err := filesClient.Delete(ctx, shareName, "", fileName); err != nil { t.Fatalf("Error deleting Top-Level File: %s", err) } } diff --git a/storage/2020-08-04/file/files/ranges_list.go b/storage/2020-08-04/file/files/ranges_list.go index ea309f9..444d14e 100644 --- a/storage/2020-08-04/file/files/ranges_list.go +++ b/storage/2020-08-04/file/files/ranges_list.go @@ -9,7 +9,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 ListRangesResult struct { @@ -24,10 +23,7 @@ type Range struct { } // ListRanges returns the list of valid ranges for the specified File. -func (client Client) ListRanges(ctx context.Context, accountName, shareName, path, fileName string) (result ListRangesResult, err error) { - if accountName == "" { - return result, validation.NewError("files.Client", "ListRanges", "`accountName` cannot be an empty string.") - } +func (client Client) ListRanges(ctx context.Context, shareName, path, fileName string) (result ListRangesResult, err error) { if shareName == "" { return result, validation.NewError("files.Client", "ListRanges", "`shareName` cannot be an empty string.") } @@ -41,7 +37,7 @@ func (client Client) ListRanges(ctx context.Context, accountName, shareName, pat return result, validation.NewError("files.Client", "ListRanges", "`fileName` cannot be an empty string.") } - req, err := client.ListRangesPreparer(ctx, accountName, shareName, path, fileName) + req, err := client.ListRangesPreparer(ctx, shareName, path, fileName) if err != nil { err = autorest.NewErrorWithError(err, "files.Client", "ListRanges", nil, "Failure preparing request") return @@ -64,7 +60,7 @@ func (client Client) ListRanges(ctx context.Context, accountName, shareName, pat } // ListRangesPreparer prepares the ListRanges request. -func (client Client) ListRangesPreparer(ctx context.Context, accountName, shareName, path, fileName string) (*http.Request, error) { +func (client Client) ListRangesPreparer(ctx context.Context, shareName, path, fileName string) (*http.Request, error) { if path != "" { path = fmt.Sprintf("%s/", path) } @@ -85,7 +81,7 @@ func (client Client) ListRangesPreparer(ctx context.Context, accountName, shareN preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), autorest.WithHeaders(headers), autorest.WithQueryParameters(queryParameters)) diff --git a/storage/2020-08-04/file/files/resource_id.go b/storage/2020-08-04/file/files/resource_id.go index f18e702..30323ea 100644 --- a/storage/2020-08-04/file/files/resource_id.go +++ b/storage/2020-08-04/file/files/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given File // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, shareName, directoryName, filePath string) string { - domain := endpoints.GetFileEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s/%s/%s", domain, shareName, directoryName, filePath) +func (client Client) GetResourceID(shareName, directoryName, filePath string) string { + return fmt.Sprintf("%s/%s/%s/%s", client.endpoint, shareName, directoryName, filePath) } type ResourceID struct { diff --git a/storage/2020-08-04/file/files/resource_id_test.go b/storage/2020-08-04/file/files/resource_id_test.go index 01d9008..ca3a38f 100644 --- a/storage/2020-08-04/file/files/resource_id_test.go +++ b/storage/2020-08-04/file/files/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "share1", "directory1", "file1.txt") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("share1", "directory1", "file1.txt") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } diff --git a/storage/2020-08-04/file/shares/README.md b/storage/2020-08-04/file/shares/README.md index ecc0f13..39c2df4 100644 --- a/storage/2020-08-04/file/shares/README.md +++ b/storage/2020-08-04/file/shares/README.md @@ -34,10 +34,10 @@ func Example() error { input := shares.CreateInput{ QuotaInGB: 2, } - if _, err := sharesClient.Create(ctx, accountName, shareName, input); err != nil { + if _, err := sharesClient.Create(ctx, shareName, input); err != nil { return fmt.Errorf("Error creating Share: %s", err) } return nil } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/file/shares/acl_get.go b/storage/2020-08-04/file/shares/acl_get.go index ea6ff4c..733192e 100644 --- a/storage/2020-08-04/file/shares/acl_get.go +++ b/storage/2020-08-04/file/shares/acl_get.go @@ -8,7 +8,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 GetACLResult struct { @@ -18,10 +17,7 @@ type GetACLResult struct { } // GetACL get the Access Control List for the specified Storage Share -func (client Client) GetACL(ctx context.Context, accountName, shareName string) (result GetACLResult, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "GetACL", "`accountName` cannot be an empty string.") - } +func (client Client) GetACL(ctx context.Context, shareName string) (result GetACLResult, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "GetACL", "`shareName` cannot be an empty string.") } @@ -29,7 +25,7 @@ func (client Client) GetACL(ctx context.Context, accountName, shareName string) return result, validation.NewError("shares.Client", "GetACL", "`shareName` must be a lower-cased string.") } - req, err := client.GetACLPreparer(ctx, accountName, shareName) + req, err := client.GetACLPreparer(ctx, shareName) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "GetACL", nil, "Failure preparing request") return @@ -52,7 +48,7 @@ func (client Client) GetACL(ctx context.Context, accountName, shareName string) } // GetACLPreparer prepares the GetACL request. -func (client Client) GetACLPreparer(ctx context.Context, accountName, shareName string) (*http.Request, error) { +func (client Client) GetACLPreparer(ctx context.Context, shareName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -69,7 +65,7 @@ func (client Client) GetACLPreparer(ctx context.Context, accountName, shareName preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/acl_set.go b/storage/2020-08-04/file/shares/acl_set.go index 18d1788..1cbffb7 100644 --- a/storage/2020-08-04/file/shares/acl_set.go +++ b/storage/2020-08-04/file/shares/acl_set.go @@ -9,7 +9,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 setAcl struct { @@ -19,10 +18,7 @@ type setAcl struct { } // SetACL sets the specified Access Control List on the specified Storage Share -func (client Client) SetACL(ctx context.Context, accountName, shareName string, acls []SignedIdentifier) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "SetACL", "`accountName` cannot be an empty string.") - } +func (client Client) SetACL(ctx context.Context, shareName string, acls []SignedIdentifier) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "SetACL", "`shareName` cannot be an empty string.") } @@ -30,7 +26,7 @@ func (client Client) SetACL(ctx context.Context, accountName, shareName string, return result, validation.NewError("shares.Client", "SetACL", "`shareName` must be a lower-cased string.") } - req, err := client.SetACLPreparer(ctx, accountName, shareName, acls) + req, err := client.SetACLPreparer(ctx, shareName, acls) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "SetACL", nil, "Failure preparing request") return @@ -53,7 +49,7 @@ func (client Client) SetACL(ctx context.Context, accountName, shareName string, } // SetACLPreparer prepares the SetACL request. -func (client Client) SetACLPreparer(ctx context.Context, accountName, shareName string, acls []SignedIdentifier) (*http.Request, error) { +func (client Client) SetACLPreparer(ctx context.Context, shareName string, acls []SignedIdentifier) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -74,7 +70,7 @@ func (client Client) SetACLPreparer(ctx context.Context, accountName, shareName preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers), diff --git a/storage/2020-08-04/file/shares/api.go b/storage/2020-08-04/file/shares/api.go index 9164591..1ca2f04 100644 --- a/storage/2020-08-04/file/shares/api.go +++ b/storage/2020-08-04/file/shares/api.go @@ -7,18 +7,18 @@ import ( ) type StorageShare interface { - SetACL(ctx context.Context, accountName, shareName string, acls []SignedIdentifier) (result autorest.Response, err error) - GetSnapshot(ctx context.Context, accountName, shareName, snapshotShare string) (result GetSnapshotPropertiesResult, err error) - GetStats(ctx context.Context, accountName, shareName string) (result GetStatsResult, err error) - GetACL(ctx context.Context, accountName, shareName string) (result GetACLResult, err error) - SetMetaData(ctx context.Context, accountName, shareName string, metaData map[string]string) (result autorest.Response, err error) - GetMetaData(ctx context.Context, accountName, shareName string) (result GetMetaDataResult, err error) - SetProperties(ctx context.Context, accountName, shareName string, properties ShareProperties) (result autorest.Response, err error) - DeleteSnapshot(ctx context.Context, accountName, shareName string, shareSnapshot string) (result autorest.Response, err error) - CreateSnapshot(ctx context.Context, accountName, shareName string, input CreateSnapshotInput) (result CreateSnapshotResult, err error) - GetResourceID(accountName, shareName string) string + SetACL(ctx context.Context, shareName string, acls []SignedIdentifier) (result autorest.Response, err error) + GetSnapshot(ctx context.Context, shareName, snapshotShare string) (result GetSnapshotPropertiesResult, err error) + GetStats(ctx context.Context, shareName string) (result GetStatsResult, err error) + GetACL(ctx context.Context, shareName string) (result GetACLResult, err error) + SetMetaData(ctx context.Context, shareName string, metaData map[string]string) (result autorest.Response, err error) + GetMetaData(ctx context.Context, shareName string) (result GetMetaDataResult, err error) + SetProperties(ctx context.Context, shareName string, properties ShareProperties) (result autorest.Response, err error) + DeleteSnapshot(ctx context.Context, shareName string, shareSnapshot string) (result autorest.Response, err error) + CreateSnapshot(ctx context.Context, shareName string, input CreateSnapshotInput) (result CreateSnapshotResult, err error) + GetResourceID(shareName string) string GetResourceManagerResourceID(subscriptionID, resourceGroup, accountName, shareName string) string - GetProperties(ctx context.Context, accountName, shareName string) (result GetPropertiesResult, err error) - Delete(ctx context.Context, accountName, shareName string, deleteSnapshots bool) (result autorest.Response, err error) - Create(ctx context.Context, accountName, shareName string, input CreateInput) (result autorest.Response, err error) + GetProperties(ctx context.Context, shareName string) (result GetPropertiesResult, err error) + Delete(ctx context.Context, shareName string, deleteSnapshots bool) (result autorest.Response, err error) + Create(ctx context.Context, shareName string, input CreateInput) (result autorest.Response, err error) } diff --git a/storage/2020-08-04/file/shares/client.go b/storage/2020-08-04/file/shares/client.go index 4f3a6f9..f8be431 100644 --- a/storage/2020-08-04/file/shares/client.go +++ b/storage/2020-08-04/file/shares/client.go @@ -3,23 +3,32 @@ package shares 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 File Storage Shares. 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) } // NewWithEnvironment 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.BuildFileEndpoint(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, } } diff --git a/storage/2020-08-04/file/shares/create.go b/storage/2020-08-04/file/shares/create.go index 10a1148..77bf387 100644 --- a/storage/2020-08-04/file/shares/create.go +++ b/storage/2020-08-04/file/shares/create.go @@ -9,7 +9,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -37,10 +36,7 @@ type CreateInput struct { } // Create creates the specified Storage Share within the specified Storage Account -func (client Client) Create(ctx context.Context, accountName, shareName string, input CreateInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "Create", "`accountName` cannot be an empty string.") - } +func (client Client) Create(ctx context.Context, shareName string, input CreateInput) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "Create", "`shareName` cannot be an empty string.") } @@ -54,7 +50,7 @@ func (client Client) Create(ctx context.Context, accountName, shareName string, return result, validation.NewError("shares.Client", "Create", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) } - req, err := client.CreatePreparer(ctx, accountName, shareName, input) + req, err := client.CreatePreparer(ctx, shareName, input) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "Create", nil, "Failure preparing request") return @@ -77,7 +73,7 @@ func (client Client) Create(ctx context.Context, accountName, shareName string, } // CreatePreparer prepares the Create request. -func (client Client) CreatePreparer(ctx context.Context, accountName, shareName string, input CreateInput) (*http.Request, error) { +func (client Client) CreatePreparer(ctx context.Context, shareName string, input CreateInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -106,7 +102,7 @@ func (client Client) CreatePreparer(ctx context.Context, accountName, shareName preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/delete.go b/storage/2020-08-04/file/shares/delete.go index 70ef985..a496f94 100644 --- a/storage/2020-08-04/file/shares/delete.go +++ b/storage/2020-08-04/file/shares/delete.go @@ -8,14 +8,10 @@ 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" ) // Delete deletes the specified Storage Share from within a Storage Account -func (client Client) Delete(ctx context.Context, accountName, shareName string, deleteSnapshots bool) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, shareName string, deleteSnapshots bool) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "Delete", "`shareName` cannot be an empty string.") } @@ -23,7 +19,7 @@ func (client Client) Delete(ctx context.Context, accountName, shareName string, return result, validation.NewError("shares.Client", "Delete", "`shareName` must be a lower-cased string.") } - req, err := client.DeletePreparer(ctx, accountName, shareName, deleteSnapshots) + req, err := client.DeletePreparer(ctx, shareName, deleteSnapshots) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "Delete", nil, "Failure preparing request") return @@ -46,7 +42,7 @@ func (client Client) Delete(ctx context.Context, accountName, shareName string, } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName, shareName string, deleteSnapshots bool) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, shareName string, deleteSnapshots bool) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -66,7 +62,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName, shareName preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/lifecycle_test.go b/storage/2020-08-04/file/shares/lifecycle_test.go index d971eee..6927df6 100644 --- a/storage/2020-08-04/file/shares/lifecycle_test.go +++ b/storage/2020-08-04/file/shares/lifecycle_test.go @@ -36,7 +36,7 @@ func TestSharesLifecycle(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - sharesClient := NewWithEnvironment(client.AutoRestEnvironment) + sharesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth) tier := CoolAccessTier @@ -44,30 +44,30 @@ func TestSharesLifecycle(t *testing.T) { QuotaInGB: 1, AccessTier: &tier, } - _, err = sharesClient.Create(ctx, accountName, shareName, input) + _, err = sharesClient.Create(ctx, shareName, input) if err != nil { t.Fatalf("Error creating fileshare: %s", err) } - snapshot, err := sharesClient.CreateSnapshot(ctx, accountName, shareName, CreateSnapshotInput{}) + snapshot, err := sharesClient.CreateSnapshot(ctx, shareName, CreateSnapshotInput{}) if err != nil { t.Fatalf("Error taking snapshot: %s", err) } t.Logf("Snapshot Date Time: %s", snapshot.SnapshotDateTime) - snapshotDetails, err := sharesClient.GetSnapshot(ctx, accountName, shareName, snapshot.SnapshotDateTime) + snapshotDetails, err := sharesClient.GetSnapshot(ctx, shareName, snapshot.SnapshotDateTime) if err != nil { t.Fatalf("Error retrieving snapshot: %s", err) } t.Logf("MetaData: %s", snapshotDetails.MetaData) - _, err = sharesClient.DeleteSnapshot(ctx, accountName, shareName, snapshot.SnapshotDateTime) + _, err = sharesClient.DeleteSnapshot(ctx, shareName, snapshot.SnapshotDateTime) if err != nil { t.Fatalf("Error deleting snapshot: %s", err) } - stats, err := sharesClient.GetStats(ctx, accountName, shareName) + stats, err := sharesClient.GetStats(ctx, shareName) if err != nil { t.Fatalf("Error retrieving stats: %s", err) } @@ -76,7 +76,7 @@ func TestSharesLifecycle(t *testing.T) { t.Fatalf("Expected `stats.ShareUsageBytes` to be 0 but got: %d", stats.ShareUsageBytes) } - share, err := sharesClient.GetProperties(ctx, accountName, shareName) + share, err := sharesClient.GetProperties(ctx, shareName) if err != nil { t.Fatalf("Error retrieving share: %s", err) } @@ -96,12 +96,12 @@ func TestSharesLifecycle(t *testing.T) { AccessTier: &newTier, QuotaInGb: "a, } - _, err = sharesClient.SetProperties(ctx, accountName, shareName, props) + _, err = sharesClient.SetProperties(ctx, shareName, props) if err != nil { t.Fatalf("Error updating quota: %s", err) } - share, err = sharesClient.GetProperties(ctx, accountName, shareName) + share, err = sharesClient.GetProperties(ctx, shareName) if err != nil { t.Fatalf("Error retrieving share: %s", err) } @@ -116,12 +116,12 @@ func TestSharesLifecycle(t *testing.T) { updatedMetaData := map[string]string{ "hello": "world", } - _, err = sharesClient.SetMetaData(ctx, accountName, shareName, updatedMetaData) + _, err = sharesClient.SetMetaData(ctx, shareName, updatedMetaData) if err != nil { t.Fatalf("Erorr setting metadata: %s", err) } - result, err := sharesClient.GetMetaData(ctx, accountName, shareName) + result, err := sharesClient.GetMetaData(ctx, shareName) if err != nil { t.Fatalf("Error retrieving metadata: %s", err) } @@ -133,7 +133,7 @@ func TestSharesLifecycle(t *testing.T) { t.Fatalf("Expected metadata to be 1 item but got: %s", result.MetaData) } - acls, err := sharesClient.GetACL(ctx, accountName, shareName) + acls, err := sharesClient.GetACL(ctx, shareName) if err != nil { t.Fatalf("Error retrieving ACL's: %s", err) } @@ -159,12 +159,12 @@ func TestSharesLifecycle(t *testing.T) { }, }, } - _, err = sharesClient.SetACL(ctx, accountName, shareName, updatedAcls) + _, err = sharesClient.SetACL(ctx, shareName, updatedAcls) if err != nil { t.Fatalf("Error setting ACL's: %s", err) } - acls, err = sharesClient.GetACL(ctx, accountName, shareName) + acls, err = sharesClient.GetACL(ctx, shareName) if err != nil { t.Fatalf("Error retrieving ACL's: %s", err) } @@ -172,7 +172,7 @@ func TestSharesLifecycle(t *testing.T) { t.Fatalf("Expected 2 identifiers but got %d", len(acls.SignedIdentifiers)) } - _, err = sharesClient.Delete(ctx, accountName, shareName, false) + _, err = sharesClient.Delete(ctx, shareName, false) if err != nil { t.Fatalf("Error deleting Share: %s", err) } @@ -201,36 +201,36 @@ func TestSharesLifecycleLargeQuota(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - sharesClient := NewWithEnvironment(client.AutoRestEnvironment) + sharesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth) input := CreateInput{ QuotaInGB: 1001, } - _, err = sharesClient.Create(ctx, accountName, shareName, input) + _, err = sharesClient.Create(ctx, shareName, input) if err != nil { t.Fatalf("Error creating fileshare: %s", err) } - snapshot, err := sharesClient.CreateSnapshot(ctx, accountName, shareName, CreateSnapshotInput{}) + snapshot, err := sharesClient.CreateSnapshot(ctx, shareName, CreateSnapshotInput{}) if err != nil { t.Fatalf("Error taking snapshot: %s", err) } t.Logf("Snapshot Date Time: %s", snapshot.SnapshotDateTime) - snapshotDetails, err := sharesClient.GetSnapshot(ctx, accountName, shareName, snapshot.SnapshotDateTime) + snapshotDetails, err := sharesClient.GetSnapshot(ctx, shareName, snapshot.SnapshotDateTime) if err != nil { t.Fatalf("Error retrieving snapshot: %s", err) } t.Logf("MetaData: %s", snapshotDetails.MetaData) - _, err = sharesClient.DeleteSnapshot(ctx, accountName, shareName, snapshot.SnapshotDateTime) + _, err = sharesClient.DeleteSnapshot(ctx, shareName, snapshot.SnapshotDateTime) if err != nil { t.Fatalf("Error deleting snapshot: %s", err) } - stats, err := sharesClient.GetStats(ctx, accountName, shareName) + stats, err := sharesClient.GetStats(ctx, shareName) if err != nil { t.Fatalf("Error retrieving stats: %s", err) } @@ -239,7 +239,7 @@ func TestSharesLifecycleLargeQuota(t *testing.T) { t.Fatalf("Expected `stats.ShareUsageBytes` to be 0 but got: %d", stats.ShareUsageBytes) } - share, err := sharesClient.GetProperties(ctx, accountName, shareName) + share, err := sharesClient.GetProperties(ctx, shareName) if err != nil { t.Fatalf("Error retrieving share: %s", err) } @@ -251,12 +251,12 @@ func TestSharesLifecycleLargeQuota(t *testing.T) { props := ShareProperties{ QuotaInGb: &newQuota, } - _, err = sharesClient.SetProperties(ctx, accountName, shareName, props) + _, err = sharesClient.SetProperties(ctx, shareName, props) if err != nil { t.Fatalf("Error updating quota: %s", err) } - share, err = sharesClient.GetProperties(ctx, accountName, shareName) + share, err = sharesClient.GetProperties(ctx, shareName) if err != nil { t.Fatalf("Error retrieving share: %s", err) } @@ -267,12 +267,12 @@ func TestSharesLifecycleLargeQuota(t *testing.T) { updatedMetaData := map[string]string{ "hello": "world", } - _, err = sharesClient.SetMetaData(ctx, accountName, shareName, updatedMetaData) + _, err = sharesClient.SetMetaData(ctx, shareName, updatedMetaData) if err != nil { t.Fatalf("Erorr setting metadata: %s", err) } - result, err := sharesClient.GetMetaData(ctx, accountName, shareName) + result, err := sharesClient.GetMetaData(ctx, shareName) if err != nil { t.Fatalf("Error retrieving metadata: %s", err) } @@ -284,7 +284,7 @@ func TestSharesLifecycleLargeQuota(t *testing.T) { t.Fatalf("Expected metadata to be 1 item but got: %s", result.MetaData) } - acls, err := sharesClient.GetACL(ctx, accountName, shareName) + acls, err := sharesClient.GetACL(ctx, shareName) if err != nil { t.Fatalf("Error retrieving ACL's: %s", err) } @@ -310,12 +310,12 @@ func TestSharesLifecycleLargeQuota(t *testing.T) { }, }, } - _, err = sharesClient.SetACL(ctx, accountName, shareName, updatedAcls) + _, err = sharesClient.SetACL(ctx, shareName, updatedAcls) if err != nil { t.Fatalf("Error setting ACL's: %s", err) } - acls, err = sharesClient.GetACL(ctx, accountName, shareName) + acls, err = sharesClient.GetACL(ctx, shareName) if err != nil { t.Fatalf("Error retrieving ACL's: %s", err) } @@ -323,7 +323,7 @@ func TestSharesLifecycleLargeQuota(t *testing.T) { t.Fatalf("Expected 2 identifiers but got %d", len(acls.SignedIdentifiers)) } - _, err = sharesClient.Delete(ctx, accountName, shareName, false) + _, err = sharesClient.Delete(ctx, shareName, false) if err != nil { t.Fatalf("Error deleting Share: %s", err) } @@ -337,7 +337,7 @@ func TestSharesLifecycleNFSProtocol(t *testing.T) { if err != nil { t.Fatal(err) } - + resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt()) accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString()) shareName := fmt.Sprintf("share-%d", testhelpers.RandomInt()) @@ -352,19 +352,19 @@ func TestSharesLifecycleNFSProtocol(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - sharesClient := NewWithEnvironment(client.AutoRestEnvironment) + sharesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth) input := CreateInput{ QuotaInGB: 1000, EnabledProtocol: NFS, } - _, err = sharesClient.Create(ctx, accountName, shareName, input) + _, err = sharesClient.Create(ctx, shareName, input) if err != nil { t.Fatalf("Error creating fileshare: %s", err) } - share, err := sharesClient.GetProperties(ctx, accountName, shareName) + share, err := sharesClient.GetProperties(ctx, shareName) if err != nil { t.Fatalf("Error retrieving share: %s", err) } @@ -372,7 +372,7 @@ func TestSharesLifecycleNFSProtocol(t *testing.T) { t.Fatalf(`Expected enabled protocol to be "NFS" but got: %q`, share.EnabledProtocol) } - _, err = sharesClient.Delete(ctx, accountName, shareName, false) + _, err = sharesClient.Delete(ctx, shareName, false) if err != nil { t.Fatalf("Error deleting Share: %s", err) } diff --git a/storage/2020-08-04/file/shares/metadata_get.go b/storage/2020-08-04/file/shares/metadata_get.go index 9fa4d9f..170ae5f 100644 --- a/storage/2020-08-04/file/shares/metadata_get.go +++ b/storage/2020-08-04/file/shares/metadata_get.go @@ -8,7 +8,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -19,10 +18,7 @@ type GetMetaDataResult struct { } // GetMetaData returns the MetaData associated with the specified Storage Share -func (client Client) GetMetaData(ctx context.Context, accountName, shareName string) (result GetMetaDataResult, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "GetMetaData", "`accountName` cannot be an empty string.") - } +func (client Client) GetMetaData(ctx context.Context, shareName string) (result GetMetaDataResult, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "GetMetaData", "`shareName` cannot be an empty string.") } @@ -30,7 +26,7 @@ func (client Client) GetMetaData(ctx context.Context, accountName, shareName str return result, validation.NewError("shares.Client", "GetMetaData", "`shareName` must be a lower-cased string.") } - req, err := client.GetMetaDataPreparer(ctx, accountName, shareName) + req, err := client.GetMetaDataPreparer(ctx, shareName) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "GetMetaData", nil, "Failure preparing request") return @@ -53,7 +49,7 @@ func (client Client) GetMetaData(ctx context.Context, accountName, shareName str } // GetMetaDataPreparer prepares the GetMetaData request. -func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, shareName string) (*http.Request, error) { +func (client Client) GetMetaDataPreparer(ctx context.Context, shareName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -70,7 +66,7 @@ func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, share preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/metadata_set.go b/storage/2020-08-04/file/shares/metadata_set.go index 7e64e60..354f86c 100644 --- a/storage/2020-08-04/file/shares/metadata_set.go +++ b/storage/2020-08-04/file/shares/metadata_set.go @@ -9,15 +9,11 @@ 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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) // SetMetaData sets the MetaData on the specified Storage Share -func (client Client) SetMetaData(ctx context.Context, accountName, shareName string, metaData map[string]string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "SetMetaData", "`accountName` cannot be an empty string.") - } +func (client Client) SetMetaData(ctx context.Context, shareName string, metaData map[string]string) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "SetMetaData", "`shareName` cannot be an empty string.") } @@ -28,7 +24,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, shareName str return result, validation.NewError("shares.Client", "SetMetaData", fmt.Sprintf("`metadata` is not valid: %s.", err)) } - req, err := client.SetMetaDataPreparer(ctx, accountName, shareName, metaData) + req, err := client.SetMetaDataPreparer(ctx, shareName, metaData) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "SetMetaData", nil, "Failure preparing request") return @@ -51,7 +47,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, shareName str } // SetMetaDataPreparer prepares the SetMetaData request. -func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, shareName string, metaData map[string]string) (*http.Request, error) { +func (client Client) SetMetaDataPreparer(ctx context.Context, shareName string, metaData map[string]string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -69,7 +65,7 @@ func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, share preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/properties_get.go b/storage/2020-08-04/file/shares/properties_get.go index 28e36e6..234baab 100644 --- a/storage/2020-08-04/file/shares/properties_get.go +++ b/storage/2020-08-04/file/shares/properties_get.go @@ -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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -24,10 +23,7 @@ type GetPropertiesResult struct { } // GetProperties returns the properties about the specified Storage Share -func (client Client) GetProperties(ctx context.Context, accountName, shareName string) (result GetPropertiesResult, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "GetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) GetProperties(ctx context.Context, shareName string) (result GetPropertiesResult, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "GetProperties", "`shareName` cannot be an empty string.") } @@ -35,7 +31,7 @@ func (client Client) GetProperties(ctx context.Context, accountName, shareName s return result, validation.NewError("shares.Client", "GetProperties", "`shareName` must be a lower-cased string.") } - req, err := client.GetPropertiesPreparer(ctx, accountName, shareName) + req, err := client.GetPropertiesPreparer(ctx, shareName) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "GetProperties", nil, "Failure preparing request") return @@ -58,7 +54,7 @@ func (client Client) GetProperties(ctx context.Context, accountName, shareName s } // GetPropertiesPreparer prepares the GetProperties request. -func (client Client) GetPropertiesPreparer(ctx context.Context, accountName, shareName string) (*http.Request, error) { +func (client Client) GetPropertiesPreparer(ctx context.Context, shareName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -74,7 +70,7 @@ func (client Client) GetPropertiesPreparer(ctx context.Context, accountName, sha preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/properties_set.go b/storage/2020-08-04/file/shares/properties_set.go index 70953c7..d0ae4bc 100644 --- a/storage/2020-08-04/file/shares/properties_set.go +++ b/storage/2020-08-04/file/shares/properties_set.go @@ -8,7 +8,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 ShareProperties struct { @@ -17,10 +16,7 @@ type ShareProperties struct { } // SetProperties lets you update the Quota for the specified Storage Share -func (client Client) SetProperties(ctx context.Context, accountName, shareName string, properties ShareProperties) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "SetProperties", "`accountName` cannot be an empty string.") - } +func (client Client) SetProperties(ctx context.Context, shareName string, properties ShareProperties) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "SetProperties", "`shareName` cannot be an empty string.") } @@ -31,7 +27,7 @@ func (client Client) SetProperties(ctx context.Context, accountName, shareName s return result, validation.NewError("shares.Client", "SetProperties", "`newQuotaGB` must be greater than 0, and less than/equal to 100TB (102400 GB)") } - req, err := client.SetPropertiesPreparer(ctx, accountName, shareName, properties) + req, err := client.SetPropertiesPreparer(ctx, shareName, properties) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "SetProperties", nil, "Failure preparing request") return @@ -54,7 +50,7 @@ func (client Client) SetProperties(ctx context.Context, accountName, shareName s } // SetPropertiesPreparer prepares the SetProperties request. -func (client Client) SetPropertiesPreparer(ctx context.Context, accountName, shareName string, properties ShareProperties) (*http.Request, error) { +func (client Client) SetPropertiesPreparer(ctx context.Context, shareName string, properties ShareProperties) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -78,7 +74,7 @@ func (client Client) SetPropertiesPreparer(ctx context.Context, accountName, sha preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/resource_id.go b/storage/2020-08-04/file/shares/resource_id.go index c51d399..5b7190e 100644 --- a/storage/2020-08-04/file/shares/resource_id.go +++ b/storage/2020-08-04/file/shares/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given File Share // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, shareName string) string { - domain := endpoints.GetFileEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s", domain, shareName) +func (client Client) GetResourceID(shareName string) string { + return fmt.Sprintf("%s/%s", client.endpoint, shareName) } // GetResourceManagerResourceID returns the Resource Manager specific diff --git a/storage/2020-08-04/file/shares/resource_id_test.go b/storage/2020-08-04/file/shares/resource_id_test.go index d810253..36f640a 100644 --- a/storage/2020-08-04/file/shares/resource_id_test.go +++ b/storage/2020-08-04/file/shares/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "share1") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("share1") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } @@ -62,7 +62,7 @@ func TestGetResourceManagerResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) + c := NewWithEnvironment("account1", v.Environment) actual := c.GetResourceManagerResourceID("11112222-3333-4444-5555-666677778888", "group1", "account1", "share1") if actual != v.Expected { t.Fatalf("Expected the Resource Manager Resource ID to be %q but got %q", v.Expected, actual) diff --git a/storage/2020-08-04/file/shares/snapshot_create.go b/storage/2020-08-04/file/shares/snapshot_create.go index 0ded38b..da14d9e 100644 --- a/storage/2020-08-04/file/shares/snapshot_create.go +++ b/storage/2020-08-04/file/shares/snapshot_create.go @@ -9,7 +9,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -29,10 +28,7 @@ type CreateSnapshotResult struct { // CreateSnapshot creates a read-only snapshot of the share // A share can support creation of 200 share snapshots. Attempting to create more than 200 share snapshots fails with 409 (Conflict). // Attempting to create a share snapshot while a previous Snapshot Share operation is in progress fails with 409 (Conflict). -func (client Client) CreateSnapshot(ctx context.Context, accountName, shareName string, input CreateSnapshotInput) (result CreateSnapshotResult, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "CreateSnapshot", "`accountName` cannot be an empty string.") - } +func (client Client) CreateSnapshot(ctx context.Context, shareName string, input CreateSnapshotInput) (result CreateSnapshotResult, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "CreateSnapshot", "`shareName` cannot be an empty string.") } @@ -43,7 +39,7 @@ func (client Client) CreateSnapshot(ctx context.Context, accountName, shareName return result, validation.NewError("shares.Client", "CreateSnapshot", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) } - req, err := client.CreateSnapshotPreparer(ctx, accountName, shareName, input) + req, err := client.CreateSnapshotPreparer(ctx, shareName, input) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "CreateSnapshot", nil, "Failure preparing request") return @@ -66,7 +62,7 @@ func (client Client) CreateSnapshot(ctx context.Context, accountName, shareName } // CreateSnapshotPreparer prepares the CreateSnapshot request. -func (client Client) CreateSnapshotPreparer(ctx context.Context, accountName, shareName string, input CreateSnapshotInput) (*http.Request, error) { +func (client Client) CreateSnapshotPreparer(ctx context.Context, shareName string, input CreateSnapshotInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -85,7 +81,7 @@ func (client Client) CreateSnapshotPreparer(ctx context.Context, accountName, sh preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/snapshot_delete.go b/storage/2020-08-04/file/shares/snapshot_delete.go index 1f5d665..320cbdb 100644 --- a/storage/2020-08-04/file/shares/snapshot_delete.go +++ b/storage/2020-08-04/file/shares/snapshot_delete.go @@ -8,14 +8,10 @@ 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" ) // DeleteSnapshot deletes the specified Snapshot of a Storage Share -func (client Client) DeleteSnapshot(ctx context.Context, accountName, shareName string, shareSnapshot string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "DeleteSnapshot", "`accountName` cannot be an empty string.") - } +func (client Client) DeleteSnapshot(ctx context.Context, shareName string, shareSnapshot string) (result autorest.Response, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "DeleteSnapshot", "`shareName` cannot be an empty string.") } @@ -26,7 +22,7 @@ func (client Client) DeleteSnapshot(ctx context.Context, accountName, shareName return result, validation.NewError("shares.Client", "DeleteSnapshot", "`shareSnapshot` cannot be an empty string.") } - req, err := client.DeleteSnapshotPreparer(ctx, accountName, shareName, shareSnapshot) + req, err := client.DeleteSnapshotPreparer(ctx, shareName, shareSnapshot) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "DeleteSnapshot", nil, "Failure preparing request") return @@ -49,7 +45,7 @@ func (client Client) DeleteSnapshot(ctx context.Context, accountName, shareName } // DeleteSnapshotPreparer prepares the DeleteSnapshot request. -func (client Client) DeleteSnapshotPreparer(ctx context.Context, accountName, shareName string, shareSnapshot string) (*http.Request, error) { +func (client Client) DeleteSnapshotPreparer(ctx context.Context, shareName string, shareSnapshot string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -66,7 +62,7 @@ func (client Client) DeleteSnapshotPreparer(ctx context.Context, accountName, sh preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/snapshot_get.go b/storage/2020-08-04/file/shares/snapshot_get.go index 2cf5f16..0a17138 100644 --- a/storage/2020-08-04/file/shares/snapshot_get.go +++ b/storage/2020-08-04/file/shares/snapshot_get.go @@ -8,7 +8,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -19,10 +18,7 @@ type GetSnapshotPropertiesResult struct { } // GetSnapshot gets information about the specified Snapshot of the specified Storage Share -func (client Client) GetSnapshot(ctx context.Context, accountName, shareName, snapshotShare string) (result GetSnapshotPropertiesResult, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "GetSnapshot", "`accountName` cannot be an empty string.") - } +func (client Client) GetSnapshot(ctx context.Context, shareName, snapshotShare string) (result GetSnapshotPropertiesResult, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "GetSnapshot", "`shareName` cannot be an empty string.") } @@ -33,7 +29,7 @@ func (client Client) GetSnapshot(ctx context.Context, accountName, shareName, sn return result, validation.NewError("shares.Client", "GetSnapshot", "`snapshotShare` cannot be an empty string.") } - req, err := client.GetSnapshotPreparer(ctx, accountName, shareName, snapshotShare) + req, err := client.GetSnapshotPreparer(ctx, shareName, snapshotShare) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "GetSnapshot", nil, "Failure preparing request") return @@ -56,7 +52,7 @@ func (client Client) GetSnapshot(ctx context.Context, accountName, shareName, sn } // GetSnapshotPreparer prepares the GetSnapshot request. -func (client Client) GetSnapshotPreparer(ctx context.Context, accountName, shareName, snapshotShare string) (*http.Request, error) { +func (client Client) GetSnapshotPreparer(ctx context.Context, shareName, snapshotShare string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -73,7 +69,7 @@ func (client Client) GetSnapshotPreparer(ctx context.Context, accountName, share preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/file/shares/stats.go b/storage/2020-08-04/file/shares/stats.go index 3539ecc..a9ad236 100644 --- a/storage/2020-08-04/file/shares/stats.go +++ b/storage/2020-08-04/file/shares/stats.go @@ -8,7 +8,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 GetStatsResult struct { @@ -20,10 +19,7 @@ type GetStatsResult struct { } // GetStats returns information about the specified Storage Share -func (client Client) GetStats(ctx context.Context, accountName, shareName string) (result GetStatsResult, err error) { - if accountName == "" { - return result, validation.NewError("shares.Client", "GetStats", "`accountName` cannot be an empty string.") - } +func (client Client) GetStats(ctx context.Context, shareName string) (result GetStatsResult, err error) { if shareName == "" { return result, validation.NewError("shares.Client", "GetStats", "`shareName` cannot be an empty string.") } @@ -31,7 +27,7 @@ func (client Client) GetStats(ctx context.Context, accountName, shareName string return result, validation.NewError("shares.Client", "GetStats", "`shareName` must be a lower-cased string.") } - req, err := client.GetStatsPreparer(ctx, accountName, shareName) + req, err := client.GetStatsPreparer(ctx, shareName) if err != nil { err = autorest.NewErrorWithError(err, "shares.Client", "GetStats", nil, "Failure preparing request") return @@ -54,7 +50,7 @@ func (client Client) GetStats(ctx context.Context, accountName, shareName string } // GetStatsPreparer prepares the GetStats request. -func (client Client) GetStatsPreparer(ctx context.Context, accountName, shareName string) (*http.Request, error) { +func (client Client) GetStatsPreparer(ctx context.Context, shareName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "shareName": autorest.Encode("path", shareName), } @@ -71,7 +67,7 @@ func (client Client) GetStatsPreparer(ctx context.Context, accountName, shareNam preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/queue/messages/README.md b/storage/2020-08-04/queue/messages/README.md index c6df9df..0d739d5 100644 --- a/storage/2020-08-04/queue/messages/README.md +++ b/storage/2020-08-04/queue/messages/README.md @@ -34,10 +34,10 @@ func Example() error { input := messages.PutInput{ Message: "hello", } - if _, err := messagesClient.Put(ctx, accountName, queueName, input); err != nil { + if _, err := messagesClient.Put(ctx, queueName, input); err != nil { return fmt.Errorf("Error creating Message: %s", err) } return nil } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/queue/messages/api.go b/storage/2020-08-04/queue/messages/api.go index ca31bfd..4560f13 100644 --- a/storage/2020-08-04/queue/messages/api.go +++ b/storage/2020-08-04/queue/messages/api.go @@ -7,10 +7,10 @@ import ( ) type StorageQueueMessage interface { - Delete(ctx context.Context, accountName, queueName, messageID, popReceipt string) (result autorest.Response, err error) - Peek(ctx context.Context, accountName, queueName string, numberOfMessages int) (result QueueMessagesListResult, err error) - GetResourceID(accountName, queueName, messageID string) string - Put(ctx context.Context, accountName, queueName string, input PutInput) (result QueueMessagesListResult, err error) - Get(ctx context.Context, accountName, queueName string, numberOfMessages int, input GetInput) (result QueueMessagesListResult, err error) - Update(ctx context.Context, accountName, queueName string, messageID string, input UpdateInput) (result autorest.Response, err error) + Delete(ctx context.Context, queueName, messageID, popReceipt string) (result autorest.Response, err error) + Peek(ctx context.Context, queueName string, numberOfMessages int) (result QueueMessagesListResult, err error) + GetResourceID(queueName, messageID string) string + Put(ctx context.Context, queueName string, input PutInput) (result QueueMessagesListResult, err error) + Get(ctx context.Context, queueName string, numberOfMessages int, input GetInput) (result QueueMessagesListResult, err error) + Update(ctx context.Context, queueName string, messageID string, input UpdateInput) (result autorest.Response, err error) } diff --git a/storage/2020-08-04/queue/messages/client.go b/storage/2020-08-04/queue/messages/client.go index 08b1801..52e46df 100644 --- a/storage/2020-08-04/queue/messages/client.go +++ b/storage/2020-08-04/queue/messages/client.go @@ -3,23 +3,32 @@ package messages 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 Messages. 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) } // NewWithEnvironment 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.BuildQueueEndpoint(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, } } diff --git a/storage/2020-08-04/queue/messages/delete.go b/storage/2020-08-04/queue/messages/delete.go index 1ec0e1a..a6c4898 100644 --- a/storage/2020-08-04/queue/messages/delete.go +++ b/storage/2020-08-04/queue/messages/delete.go @@ -8,14 +8,10 @@ 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" ) // Delete deletes a specific message -func (client Client) Delete(ctx context.Context, accountName, queueName, messageID, popReceipt string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("messages.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, queueName, messageID, popReceipt string) (result autorest.Response, err error) { if queueName == "" { return result, validation.NewError("messages.Client", "Delete", "`queueName` cannot be an empty string.") } @@ -29,7 +25,7 @@ func (client Client) Delete(ctx context.Context, accountName, queueName, message return result, validation.NewError("messages.Client", "Delete", "`popReceipt` cannot be an empty string.") } - req, err := client.DeletePreparer(ctx, accountName, queueName, messageID, popReceipt) + req, err := client.DeletePreparer(ctx, queueName, messageID, popReceipt) if err != nil { err = autorest.NewErrorWithError(err, "messages.Client", "Delete", nil, "Failure preparing request") return @@ -52,7 +48,7 @@ func (client Client) Delete(ctx context.Context, accountName, queueName, message } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName, queueName, messageID, popReceipt string) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, queueName, messageID, popReceipt string) (*http.Request, error) { pathParameters := map[string]interface{}{ "queueName": autorest.Encode("path", queueName), "messageID": autorest.Encode("path", messageID), @@ -69,7 +65,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName, queueName, preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{queueName}/messages/{messageID}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/queue/messages/get.go b/storage/2020-08-04/queue/messages/get.go index 4edeb6d..b0d2a6b 100644 --- a/storage/2020-08-04/queue/messages/get.go +++ b/storage/2020-08-04/queue/messages/get.go @@ -9,7 +9,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 GetInput struct { @@ -19,10 +18,7 @@ type GetInput struct { } // Get retrieves one or more messages from the front of the queue -func (client Client) Get(ctx context.Context, accountName, queueName string, numberOfMessages int, input GetInput) (result QueueMessagesListResult, err error) { - if accountName == "" { - return result, validation.NewError("messages.Client", "Get", "`accountName` cannot be an empty string.") - } +func (client Client) Get(ctx context.Context, queueName string, numberOfMessages int, input GetInput) (result QueueMessagesListResult, err error) { if queueName == "" { return result, validation.NewError("messages.Client", "Get", "`queueName` cannot be an empty string.") } @@ -40,7 +36,7 @@ func (client Client) Get(ctx context.Context, accountName, queueName string, num } } - req, err := client.GetPreparer(ctx, accountName, queueName, numberOfMessages, input) + req, err := client.GetPreparer(ctx, queueName, numberOfMessages, input) if err != nil { err = autorest.NewErrorWithError(err, "messages.Client", "Get", nil, "Failure preparing request") return @@ -63,7 +59,7 @@ func (client Client) Get(ctx context.Context, accountName, queueName string, num } // GetPreparer prepares the Get request. -func (client Client) GetPreparer(ctx context.Context, accountName, queueName string, numberOfMessages int, input GetInput) (*http.Request, error) { +func (client Client) GetPreparer(ctx context.Context, queueName string, numberOfMessages int, input GetInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "queueName": autorest.Encode("path", queueName), } @@ -83,7 +79,7 @@ func (client Client) GetPreparer(ctx context.Context, accountName, queueName str preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{queueName}/messages", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/queue/messages/lifecycle_test.go b/storage/2020-08-04/queue/messages/lifecycle_test.go index 2723bd3..d936685 100644 --- a/storage/2020-08-04/queue/messages/lifecycle_test.go +++ b/storage/2020-08-04/queue/messages/lifecycle_test.go @@ -33,26 +33,26 @@ func TestLifeCycle(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - queuesClient := queues.NewWithEnvironment(client.AutoRestEnvironment) + queuesClient := queues.NewWithEnvironment(accountName, client.AutoRestEnvironment) queuesClient.Client = client.PrepareWithStorageResourceManagerAuth(queuesClient.Client) storageAuth, err := autorest.NewSharedKeyAuthorizer(accountName, testData.StorageAccountKey, autorest.SharedKeyLite) if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - messagesClient := NewWithEnvironment(client.AutoRestEnvironment) + messagesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) messagesClient.Client = client.PrepareWithAuthorizer(messagesClient.Client, storageAuth) - _, err = queuesClient.Create(ctx, accountName, queueName, map[string]string{}) + _, err = queuesClient.Create(ctx, queueName, map[string]string{}) if err != nil { t.Fatalf("Error creating queue: %s", err) } - defer queuesClient.Delete(ctx, accountName, queueName) + defer queuesClient.Delete(ctx, queueName) input := PutInput{ Message: "ohhai", } - putResp, err := messagesClient.Put(ctx, accountName, queueName, input) + putResp, err := messagesClient.Put(ctx, queueName, input) if err != nil { t.Fatalf("Error putting message in queue: %s", err) } @@ -60,7 +60,7 @@ func TestLifeCycle(t *testing.T) { messageId := (*putResp.QueueMessages)[0].MessageId popReceipt := (*putResp.QueueMessages)[0].PopReceipt - _, err = messagesClient.Update(ctx, accountName, queueName, messageId, UpdateInput{ + _, err = messagesClient.Update(ctx, queueName, messageId, UpdateInput{ PopReceipt: popReceipt, Message: "Updated message", VisibilityTimeout: 65, @@ -73,13 +73,13 @@ func TestLifeCycle(t *testing.T) { input := PutInput{ Message: fmt.Sprintf("Message %d", i), } - _, err := messagesClient.Put(ctx, accountName, queueName, input) + _, err := messagesClient.Put(ctx, queueName, input) if err != nil { t.Fatalf("Error putting message %d in queue: %s", i, err) } } - peakedMessages, err := messagesClient.Peek(ctx, accountName, queueName, 3) + peakedMessages, err := messagesClient.Peek(ctx, queueName, 3) if err != nil { t.Fatalf("Error peaking messages: %s", err) } @@ -88,7 +88,7 @@ func TestLifeCycle(t *testing.T) { t.Logf("Message: %q", v.MessageId) } - retrievedMessages, err := messagesClient.Get(ctx, accountName, queueName, 6, GetInput{}) + retrievedMessages, err := messagesClient.Get(ctx, queueName, 6, GetInput{}) if err != nil { t.Fatalf("Error retrieving messages: %s", err) } @@ -96,7 +96,7 @@ func TestLifeCycle(t *testing.T) { for _, v := range *retrievedMessages.QueueMessages { t.Logf("Message: %q", v.MessageId) - _, err = messagesClient.Delete(ctx, accountName, queueName, v.MessageId, v.PopReceipt) + _, err = messagesClient.Delete(ctx, queueName, v.MessageId, v.PopReceipt) if err != nil { t.Fatalf("Error deleting message from queue: %s", err) } diff --git a/storage/2020-08-04/queue/messages/peek.go b/storage/2020-08-04/queue/messages/peek.go index 7288bd5..2fecca2 100644 --- a/storage/2020-08-04/queue/messages/peek.go +++ b/storage/2020-08-04/queue/messages/peek.go @@ -8,14 +8,10 @@ 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" ) // Peek retrieves one or more messages from the front of the queue, but doesn't alter the visibility of the messages -func (client Client) Peek(ctx context.Context, accountName, queueName string, numberOfMessages int) (result QueueMessagesListResult, err error) { - if accountName == "" { - return result, validation.NewError("messages.Client", "Peek", "`accountName` cannot be an empty string.") - } +func (client Client) Peek(ctx context.Context, queueName string, numberOfMessages int) (result QueueMessagesListResult, err error) { if queueName == "" { return result, validation.NewError("messages.Client", "Peek", "`queueName` cannot be an empty string.") } @@ -26,7 +22,7 @@ func (client Client) Peek(ctx context.Context, accountName, queueName string, nu return result, validation.NewError("messages.Client", "Peek", "`numberOfMessages` must be between 1 and 32.") } - req, err := client.PeekPreparer(ctx, accountName, queueName, numberOfMessages) + req, err := client.PeekPreparer(ctx, queueName, numberOfMessages) if err != nil { err = autorest.NewErrorWithError(err, "messages.Client", "Peek", nil, "Failure preparing request") return @@ -49,7 +45,7 @@ func (client Client) Peek(ctx context.Context, accountName, queueName string, nu } // PeekPreparer prepares the Peek request. -func (client Client) PeekPreparer(ctx context.Context, accountName, queueName string, numberOfMessages int) (*http.Request, error) { +func (client Client) PeekPreparer(ctx context.Context, queueName string, numberOfMessages int) (*http.Request, error) { pathParameters := map[string]interface{}{ "queueName": autorest.Encode("path", queueName), } @@ -66,7 +62,7 @@ func (client Client) PeekPreparer(ctx context.Context, accountName, queueName st preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{queueName}/messages", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/queue/messages/put.go b/storage/2020-08-04/queue/messages/put.go index 612b4a1..28b35a1 100644 --- a/storage/2020-08-04/queue/messages/put.go +++ b/storage/2020-08-04/queue/messages/put.go @@ -8,7 +8,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 PutInput struct { @@ -30,10 +29,7 @@ type PutInput struct { } // Put adds a new message to the back of the message queue -func (client Client) Put(ctx context.Context, accountName, queueName string, input PutInput) (result QueueMessagesListResult, err error) { - if accountName == "" { - return result, validation.NewError("messages.Client", "Put", "`accountName` cannot be an empty string.") - } +func (client Client) Put(ctx context.Context, queueName string, input PutInput) (result QueueMessagesListResult, err error) { if queueName == "" { return result, validation.NewError("messages.Client", "Put", "`queueName` cannot be an empty string.") } @@ -41,7 +37,7 @@ func (client Client) Put(ctx context.Context, accountName, queueName string, inp return result, validation.NewError("messages.Client", "Put", "`queueName` must be a lower-cased string.") } - req, err := client.PutPreparer(ctx, accountName, queueName, input) + req, err := client.PutPreparer(ctx, queueName, input) if err != nil { err = autorest.NewErrorWithError(err, "messages.Client", "Put", nil, "Failure preparing request") return @@ -64,7 +60,7 @@ func (client Client) Put(ctx context.Context, accountName, queueName string, inp } // PutPreparer prepares the Put request. -func (client Client) PutPreparer(ctx context.Context, accountName, queueName string, input PutInput) (*http.Request, error) { +func (client Client) PutPreparer(ctx context.Context, queueName string, input PutInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "queueName": autorest.Encode("path", queueName), } @@ -90,7 +86,7 @@ func (client Client) PutPreparer(ctx context.Context, accountName, queueName str preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPost(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{queueName}/messages", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithXML(body), diff --git a/storage/2020-08-04/queue/messages/resource_id.go b/storage/2020-08-04/queue/messages/resource_id.go index 0d242b0..c9f6b7a 100644 --- a/storage/2020-08-04/queue/messages/resource_id.go +++ b/storage/2020-08-04/queue/messages/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given Message within a Queue // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, queueName, messageID string) string { - domain := endpoints.GetQueueEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s/messages/%s", domain, queueName, messageID) +func (client Client) GetResourceID(queueName, messageID string) string { + return fmt.Sprintf("%s/%s/messages/%s", client.endpoint, queueName, messageID) } type ResourceID struct { diff --git a/storage/2020-08-04/queue/messages/resource_id_test.go b/storage/2020-08-04/queue/messages/resource_id_test.go index 468d7b8..f27a5da 100644 --- a/storage/2020-08-04/queue/messages/resource_id_test.go +++ b/storage/2020-08-04/queue/messages/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "queue1", "message1") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("queue1", "message1") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } diff --git a/storage/2020-08-04/queue/messages/update.go b/storage/2020-08-04/queue/messages/update.go index fb10fad..644c091 100644 --- a/storage/2020-08-04/queue/messages/update.go +++ b/storage/2020-08-04/queue/messages/update.go @@ -8,7 +8,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 UpdateInput struct { @@ -27,10 +26,7 @@ type UpdateInput struct { } // Update updates an existing message based on it's Pop Receipt -func (client Client) Update(ctx context.Context, accountName, queueName string, messageID string, input UpdateInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("messages.Client", "Update", "`accountName` cannot be an empty string.") - } +func (client Client) Update(ctx context.Context, queueName string, messageID string, input UpdateInput) (result autorest.Response, err error) { if queueName == "" { return result, validation.NewError("messages.Client", "Update", "`queueName` cannot be an empty string.") } @@ -41,7 +37,7 @@ func (client Client) Update(ctx context.Context, accountName, queueName string, return result, validation.NewError("messages.Client", "Update", "`input.PopReceipt` cannot be an empty string.") } - req, err := client.UpdatePreparer(ctx, accountName, queueName, messageID, input) + req, err := client.UpdatePreparer(ctx, queueName, messageID, input) if err != nil { err = autorest.NewErrorWithError(err, "messages.Client", "Update", nil, "Failure preparing request") return @@ -64,7 +60,7 @@ func (client Client) Update(ctx context.Context, accountName, queueName string, } // UpdatePreparer prepares the Update request. -func (client Client) UpdatePreparer(ctx context.Context, accountName, queueName string, messageID string, input UpdateInput) (*http.Request, error) { +func (client Client) UpdatePreparer(ctx context.Context, queueName string, messageID string, input UpdateInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "queueName": autorest.Encode("path", queueName), "messageID": autorest.Encode("path", messageID), @@ -86,7 +82,7 @@ func (client Client) UpdatePreparer(ctx context.Context, accountName, queueName preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{queueName}/messages/{messageID}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithXML(body), diff --git a/storage/2020-08-04/queue/queues/README.md b/storage/2020-08-04/queue/queues/README.md index b8b84a3..ccb2a46 100644 --- a/storage/2020-08-04/queue/queues/README.md +++ b/storage/2020-08-04/queue/queues/README.md @@ -34,10 +34,10 @@ func Example() error { metadata := map[string]string{ "hello": "world", } - if _, err := queuesClient.Create(ctx, accountName, queueName, metadata); err != nil { + if _, err := queuesClient.Create(ctx, queueName, metadata); err != nil { return fmt.Errorf("Error creating Queue: %s", err) } return nil } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/queue/queues/api.go b/storage/2020-08-04/queue/queues/api.go index e4c1422..7838f3a 100644 --- a/storage/2020-08-04/queue/queues/api.go +++ b/storage/2020-08-04/queue/queues/api.go @@ -7,11 +7,11 @@ import ( ) type StorageQueue interface { - Delete(ctx context.Context, accountName, queueName string) (result autorest.Response, err error) - GetMetaData(ctx context.Context, accountName, queueName string) (result GetMetaDataResult, err error) - SetMetaData(ctx context.Context, accountName, queueName string, metaData map[string]string) (result autorest.Response, err error) - Create(ctx context.Context, accountName, queueName string, metaData map[string]string) (result autorest.Response, err error) - GetResourceID(accountName, queueName string) string - SetServiceProperties(ctx context.Context, accountName string, properties StorageServiceProperties) (result autorest.Response, err error) - GetServiceProperties(ctx context.Context, accountName string) (result StorageServicePropertiesResponse, err error) + Delete(ctx context.Context, queueName string) (result autorest.Response, err error) + GetMetaData(ctx context.Context, queueName string) (result GetMetaDataResult, err error) + SetMetaData(ctx context.Context, queueName string, metaData map[string]string) (result autorest.Response, err error) + Create(ctx context.Context, queueName string, metaData map[string]string) (result autorest.Response, err error) + GetResourceID(queueName string) string + SetServiceProperties(ctx context.Context, properties StorageServiceProperties) (result autorest.Response, err error) + GetServiceProperties(ctx context.Context) (result StorageServicePropertiesResponse, err error) } diff --git a/storage/2020-08-04/queue/queues/client.go b/storage/2020-08-04/queue/queues/client.go index 2f80085..0107807 100644 --- a/storage/2020-08-04/queue/queues/client.go +++ b/storage/2020-08-04/queue/queues/client.go @@ -3,23 +3,32 @@ package queues 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 Queue Storage Shares. 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) } // NewWithEnvironment 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.BuildQueueEndpoint(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, } } diff --git a/storage/2020-08-04/queue/queues/create.go b/storage/2020-08-04/queue/queues/create.go index f18910a..e6e331c 100644 --- a/storage/2020-08-04/queue/queues/create.go +++ b/storage/2020-08-04/queue/queues/create.go @@ -9,15 +9,11 @@ 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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) // Create creates the specified Queue within the specified Storage Account -func (client Client) Create(ctx context.Context, accountName, queueName string, metaData map[string]string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("queues.Client", "Create", "`accountName` cannot be an empty string.") - } +func (client Client) Create(ctx context.Context, queueName string, metaData map[string]string) (result autorest.Response, err error) { if queueName == "" { return result, validation.NewError("queues.Client", "Create", "`queueName` cannot be an empty string.") } @@ -28,7 +24,7 @@ func (client Client) Create(ctx context.Context, accountName, queueName string, return result, validation.NewError("queues.Client", "Create", fmt.Sprintf("`metadata` is not valid: %s.", err)) } - req, err := client.CreatePreparer(ctx, accountName, queueName, metaData) + req, err := client.CreatePreparer(ctx, queueName, metaData) if err != nil { err = autorest.NewErrorWithError(err, "queues.Client", "Create", nil, "Failure preparing request") return @@ -51,7 +47,7 @@ func (client Client) Create(ctx context.Context, accountName, queueName string, } // CreatePreparer prepares the Create request. -func (client Client) CreatePreparer(ctx context.Context, accountName string, queueName string, metaData map[string]string) (*http.Request, error) { +func (client Client) CreatePreparer(ctx context.Context, queueName string, metaData map[string]string) (*http.Request, error) { pathParameters := map[string]interface{}{ "queueName": autorest.Encode("path", queueName), } @@ -65,7 +61,7 @@ func (client Client) CreatePreparer(ctx context.Context, accountName string, que preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{queueName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/queue/queues/delete.go b/storage/2020-08-04/queue/queues/delete.go index 5f70595..4e47104 100644 --- a/storage/2020-08-04/queue/queues/delete.go +++ b/storage/2020-08-04/queue/queues/delete.go @@ -8,14 +8,10 @@ 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" ) // Delete deletes the specified Queue within the specified Storage Account -func (client Client) Delete(ctx context.Context, accountName, queueName string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("queues.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, queueName string) (result autorest.Response, err error) { if queueName == "" { return result, validation.NewError("queues.Client", "Delete", "`queueName` cannot be an empty string.") } @@ -23,7 +19,7 @@ func (client Client) Delete(ctx context.Context, accountName, queueName string) return result, validation.NewError("queues.Client", "Delete", "`queueName` must be a lower-cased string.") } - req, err := client.DeletePreparer(ctx, accountName, queueName) + req, err := client.DeletePreparer(ctx, queueName) if err != nil { err = autorest.NewErrorWithError(err, "queues.Client", "Delete", nil, "Failure preparing request") return @@ -46,7 +42,7 @@ func (client Client) Delete(ctx context.Context, accountName, queueName string) } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName string, queueName string) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, queueName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "queueName": autorest.Encode("path", queueName), } @@ -58,7 +54,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName string, que preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{queueName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/queue/queues/lifecycle_test.go b/storage/2020-08-04/queue/queues/lifecycle_test.go index 63a54cd..6686f1b 100644 --- a/storage/2020-08-04/queue/queues/lifecycle_test.go +++ b/storage/2020-08-04/queue/queues/lifecycle_test.go @@ -32,17 +32,17 @@ func TestQueuesLifecycle(t *testing.T) { } defer client.DestroyTestResources(ctx, resourceGroup, accountName) - queuesClient := NewWithEnvironment(client.AutoRestEnvironment) + queuesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) queuesClient.Client = client.PrepareWithStorageResourceManagerAuth(queuesClient.Client) // first let's test an empty container - _, err = queuesClient.Create(ctx, accountName, queueName, map[string]string{}) + _, err = queuesClient.Create(ctx, queueName, map[string]string{}) if err != nil { t.Fatal(fmt.Errorf("Error creating: %s", err)) } // then let's retrieve it to ensure there's no metadata.. - resp, err := queuesClient.GetMetaData(ctx, accountName, queueName) + resp, err := queuesClient.GetMetaData(ctx, queueName) if err != nil { t.Fatalf("Error retrieving MetaData: %s", err) } @@ -55,12 +55,12 @@ func TestQueuesLifecycle(t *testing.T) { "band": "panic", "boots": "the-overpass", } - _, err = queuesClient.SetMetaData(ctx, accountName, queueName, updatedMetaData) + _, err = queuesClient.SetMetaData(ctx, queueName, updatedMetaData) if err != nil { t.Fatalf("Error setting MetaData: %s", err) } - resp, err = queuesClient.GetMetaData(ctx, accountName, queueName) + resp, err = queuesClient.GetMetaData(ctx, queueName) if err != nil { t.Fatalf("Error re-retrieving MetaData: %s", err) } @@ -76,12 +76,12 @@ func TestQueuesLifecycle(t *testing.T) { } // and woo let's remove it again - _, err = queuesClient.SetMetaData(ctx, accountName, queueName, map[string]string{}) + _, err = queuesClient.SetMetaData(ctx, queueName, map[string]string{}) if err != nil { t.Fatalf("Error setting MetaData: %s", err) } - resp, err = queuesClient.GetMetaData(ctx, accountName, queueName) + resp, err = queuesClient.GetMetaData(ctx, queueName) if err != nil { t.Fatalf("Error retrieving MetaData: %s", err) } @@ -136,12 +136,12 @@ func TestQueuesLifecycle(t *testing.T) { }, }, } - _, err = queuesClient.SetServiceProperties(ctx, accountName, props) + _, err = queuesClient.SetServiceProperties(ctx, props) if err != nil { t.Fatalf("SetServiceProperties failed: %s", err) } - properties, err := queuesClient.GetServiceProperties(ctx, accountName) + properties, err := queuesClient.GetServiceProperties(ctx) if err != nil { t.Fatalf("GetServiceProperties failed: %s", err) } @@ -212,12 +212,12 @@ func TestQueuesLifecycle(t *testing.T) { }, } - _, err = queuesClient.SetServiceProperties(ctx, accountName, props2) + _, err = queuesClient.SetServiceProperties(ctx, props2) if err != nil { t.Fatalf("SetServiceProperties failed: %s", err) } - properties, err = queuesClient.GetServiceProperties(ctx, accountName) + properties, err = queuesClient.GetServiceProperties(ctx) if err != nil { t.Fatalf("GetServiceProperties failed: %s", err) } @@ -243,7 +243,7 @@ func TestQueuesLifecycle(t *testing.T) { } log.Printf("[DEBUG] Deleting..") - _, err = queuesClient.Delete(ctx, accountName, queueName) + _, err = queuesClient.Delete(ctx, queueName) if err != nil { t.Fatal(fmt.Errorf("Error deleting: %s", err)) } diff --git a/storage/2020-08-04/queue/queues/metadata_get.go b/storage/2020-08-04/queue/queues/metadata_get.go index 9c230b6..aa0e19a 100644 --- a/storage/2020-08-04/queue/queues/metadata_get.go +++ b/storage/2020-08-04/queue/queues/metadata_get.go @@ -8,7 +8,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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) @@ -19,10 +18,7 @@ type GetMetaDataResult struct { } // GetMetaData returns the metadata for this Queue -func (client Client) GetMetaData(ctx context.Context, accountName, queueName string) (result GetMetaDataResult, err error) { - if accountName == "" { - return result, validation.NewError("queues.Client", "GetMetaData", "`accountName` cannot be an empty string.") - } +func (client Client) GetMetaData(ctx context.Context, queueName string) (result GetMetaDataResult, err error) { if queueName == "" { return result, validation.NewError("queues.Client", "GetMetaData", "`queueName` cannot be an empty string.") } @@ -30,7 +26,7 @@ func (client Client) GetMetaData(ctx context.Context, accountName, queueName str return result, validation.NewError("queues.Client", "GetMetaData", "`queueName` must be a lower-cased string.") } - req, err := client.GetMetaDataPreparer(ctx, accountName, queueName) + req, err := client.GetMetaDataPreparer(ctx, queueName) if err != nil { err = autorest.NewErrorWithError(err, "queues.Client", "GetMetaData", nil, "Failure preparing request") return @@ -53,7 +49,7 @@ func (client Client) GetMetaData(ctx context.Context, accountName, queueName str } // GetMetaDataPreparer prepares the GetMetaData request. -func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, queueName string) (*http.Request, error) { +func (client Client) GetMetaDataPreparer(ctx context.Context, queueName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "queueName": autorest.Encode("path", queueName), } @@ -69,7 +65,7 @@ func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, queue preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{queueName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/queue/queues/metadata_set.go b/storage/2020-08-04/queue/queues/metadata_set.go index 51154a5..08ed6f2 100644 --- a/storage/2020-08-04/queue/queues/metadata_set.go +++ b/storage/2020-08-04/queue/queues/metadata_set.go @@ -9,15 +9,11 @@ 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" "github.com/tombuildsstuff/giovanni/storage/internal/metadata" ) // SetMetaData returns the metadata for this Queue -func (client Client) SetMetaData(ctx context.Context, accountName, queueName string, metaData map[string]string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("queues.Client", "SetMetaData", "`accountName` cannot be an empty string.") - } +func (client Client) SetMetaData(ctx context.Context, queueName string, metaData map[string]string) (result autorest.Response, err error) { if queueName == "" { return result, validation.NewError("queues.Client", "SetMetaData", "`queueName` cannot be an empty string.") } @@ -28,7 +24,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, queueName str return result, validation.NewError("queues.Client", "SetMetaData", fmt.Sprintf("`metadata` is not valid: %s.", err)) } - req, err := client.SetMetaDataPreparer(ctx, accountName, queueName, metaData) + req, err := client.SetMetaDataPreparer(ctx, queueName, metaData) if err != nil { err = autorest.NewErrorWithError(err, "queues.Client", "SetMetaData", nil, "Failure preparing request") return @@ -51,7 +47,7 @@ func (client Client) SetMetaData(ctx context.Context, accountName, queueName str } // SetMetaDataPreparer prepares the SetMetaData request. -func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, queueName string, metaData map[string]string) (*http.Request, error) { +func (client Client) SetMetaDataPreparer(ctx context.Context, queueName string, metaData map[string]string) (*http.Request, error) { pathParameters := map[string]interface{}{ "queueName": autorest.Encode("path", queueName), } @@ -69,7 +65,7 @@ func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, queue preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{queueName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/queue/queues/properties_get.go b/storage/2020-08-04/queue/queues/properties_get.go index a0e51ad..be29c0a 100644 --- a/storage/2020-08-04/queue/queues/properties_get.go +++ b/storage/2020-08-04/queue/queues/properties_get.go @@ -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 StorageServicePropertiesResponse struct { @@ -16,12 +14,9 @@ type StorageServicePropertiesResponse struct { } // SetServiceProperties gets the properties for this queue -func (client Client) GetServiceProperties(ctx context.Context, accountName string) (result StorageServicePropertiesResponse, err error) { - if accountName == "" { - return result, validation.NewError("queues.Client", "GetServiceProperties", "`accountName` cannot be an empty string.") - } +func (client Client) GetServiceProperties(ctx context.Context) (result StorageServicePropertiesResponse, err error) { - req, err := client.GetServicePropertiesPreparer(ctx, accountName) + req, err := client.GetServicePropertiesPreparer(ctx) if err != nil { err = autorest.NewErrorWithError(err, "queues.Client", "GetServiceProperties", nil, "Failure preparing request") return @@ -44,7 +39,7 @@ func (client Client) GetServiceProperties(ctx context.Context, accountName strin } // 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{}{ "comp": autorest.Encode("path", "properties"), "restype": autorest.Encode("path", "service"), @@ -57,7 +52,7 @@ func (client Client) GetServicePropertiesPreparer(ctx context.Context, accountNa preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPath("/"), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/queue/queues/properties_set.go b/storage/2020-08-04/queue/queues/properties_set.go index 33dd40b..cd5a8af 100644 --- a/storage/2020-08-04/queue/queues/properties_set.go +++ b/storage/2020-08-04/queue/queues/properties_set.go @@ -6,17 +6,11 @@ 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" ) // SetServiceProperties sets the properties for this queue -func (client Client) SetServiceProperties(ctx context.Context, accountName string, properties StorageServiceProperties) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("queues.Client", "SetServiceProperties", "`accountName` cannot be an empty string.") - } - - req, err := client.SetServicePropertiesPreparer(ctx, accountName, properties) +func (client Client) SetServiceProperties(ctx context.Context, properties StorageServiceProperties) (result autorest.Response, err error) { + req, err := client.SetServicePropertiesPreparer(ctx, properties) if err != nil { err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", nil, "Failure preparing request") return @@ -39,7 +33,7 @@ func (client Client) SetServiceProperties(ctx context.Context, accountName strin } // SetServicePropertiesPreparer prepares the SetServiceProperties request. -func (client Client) SetServicePropertiesPreparer(ctx context.Context, accountName string, properties StorageServiceProperties) (*http.Request, error) { +func (client Client) SetServicePropertiesPreparer(ctx context.Context, properties StorageServiceProperties) (*http.Request, error) { queryParameters := map[string]interface{}{ "comp": autorest.Encode("path", "properties"), "restype": autorest.Encode("path", "service"), @@ -52,7 +46,7 @@ func (client Client) SetServicePropertiesPreparer(ctx context.Context, accountNa preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPath("/"), autorest.WithQueryParameters(queryParameters), autorest.WithXML(properties), diff --git a/storage/2020-08-04/queue/queues/resource_id.go b/storage/2020-08-04/queue/queues/resource_id.go index 912923a..7918e43 100644 --- a/storage/2020-08-04/queue/queues/resource_id.go +++ b/storage/2020-08-04/queue/queues/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given Queue // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, queueName string) string { - domain := endpoints.GetQueueEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s", domain, queueName) +func (client Client) GetResourceID(queueName string) string { + return fmt.Sprintf("%s/%s", client.endpoint, queueName) } type ResourceID struct { diff --git a/storage/2020-08-04/queue/queues/resource_id_test.go b/storage/2020-08-04/queue/queues/resource_id_test.go index ba63ab4..10c2cf2 100644 --- a/storage/2020-08-04/queue/queues/resource_id_test.go +++ b/storage/2020-08-04/queue/queues/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "queue1") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("queue1") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } diff --git a/storage/2020-08-04/table/entities/README.md b/storage/2020-08-04/table/entities/README.md index e59b5a2..d35e92d 100644 --- a/storage/2020-08-04/table/entities/README.md +++ b/storage/2020-08-04/table/entities/README.md @@ -39,10 +39,10 @@ func Example() error { "artist": "Sigrid", }, } - if _, err := entitiesClient.Insert(ctx, accountName, tableName, input); err != nil { + if _, err := entitiesClient.Insert(ctx, tableName, input); err != nil { return fmt.Errorf("Error creating Entity: %s", err) } return nil } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/table/entities/api.go b/storage/2020-08-04/table/entities/api.go index d4d20a7..1ef7b47 100644 --- a/storage/2020-08-04/table/entities/api.go +++ b/storage/2020-08-04/table/entities/api.go @@ -7,11 +7,11 @@ import ( ) type StorageTableEntity interface { - Delete(ctx context.Context, accountName, tableName string, input DeleteEntityInput) (result autorest.Response, err error) - Insert(ctx context.Context, accountName, tableName string, input InsertEntityInput) (result autorest.Response, err error) - InsertOrReplace(ctx context.Context, accountName, tableName string, input InsertOrReplaceEntityInput) (result autorest.Response, err error) - InsertOrMerge(ctx context.Context, accountName, tableName string, input InsertOrMergeEntityInput) (result autorest.Response, err error) - Query(ctx context.Context, accountName, tableName string, input QueryEntitiesInput) (result QueryEntitiesResult, err error) - Get(ctx context.Context, accountName, tableName string, input GetEntityInput) (result GetEntityResult, err error) - GetResourceID(accountName, tableName, partitionKey, rowKey string) string + Delete(ctx context.Context, tableName string, input DeleteEntityInput) (result autorest.Response, err error) + Insert(ctx context.Context, tableName string, input InsertEntityInput) (result autorest.Response, err error) + InsertOrReplace(ctx context.Context, tableName string, input InsertOrReplaceEntityInput) (result autorest.Response, err error) + InsertOrMerge(ctx context.Context, tableName string, input InsertOrMergeEntityInput) (result autorest.Response, err error) + Query(ctx context.Context, tableName string, input QueryEntitiesInput) (result QueryEntitiesResult, err error) + Get(ctx context.Context, tableName string, input GetEntityInput) (result GetEntityResult, err error) + GetResourceID(tableName, partitionKey, rowKey string) string } diff --git a/storage/2020-08-04/table/entities/client.go b/storage/2020-08-04/table/entities/client.go index 17e9d75..d96d02f 100644 --- a/storage/2020-08-04/table/entities/client.go +++ b/storage/2020-08-04/table/entities/client.go @@ -3,23 +3,32 @@ package entities 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 Table Storage Shares. 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) } // NewWithEnvironment 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.BuildTableEndpoint(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, } } diff --git a/storage/2020-08-04/table/entities/delete.go b/storage/2020-08-04/table/entities/delete.go index 83e9188..88c8b02 100644 --- a/storage/2020-08-04/table/entities/delete.go +++ b/storage/2020-08-04/table/entities/delete.go @@ -7,7 +7,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 DeleteEntityInput struct { @@ -21,10 +20,7 @@ type DeleteEntityInput struct { } // Delete deletes an existing entity in a table. -func (client Client) Delete(ctx context.Context, accountName, tableName string, input DeleteEntityInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("entities.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, tableName string, input DeleteEntityInput) (result autorest.Response, err error) { if tableName == "" { return result, validation.NewError("entities.Client", "Delete", "`tableName` cannot be an empty string.") } @@ -35,7 +31,7 @@ func (client Client) Delete(ctx context.Context, accountName, tableName string, return result, validation.NewError("entities.Client", "Delete", "`input.RowKey` cannot be an empty string.") } - req, err := client.DeletePreparer(ctx, accountName, tableName, input) + req, err := client.DeletePreparer(ctx, tableName, input) if err != nil { err = autorest.NewErrorWithError(err, "entities.Client", "Delete", nil, "Failure preparing request") return @@ -58,7 +54,7 @@ func (client Client) Delete(ctx context.Context, accountName, tableName string, } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName, tableName string, input DeleteEntityInput) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, tableName string, input DeleteEntityInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), "partitionKey": autorest.Encode("path", input.PartitionKey), @@ -72,7 +68,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName, tableName preparer := autorest.CreatePreparer( autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{tableName}(PartitionKey='{partitionKey}', RowKey='{rowKey}')", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/table/entities/get.go b/storage/2020-08-04/table/entities/get.go index bdb4018..d21f203 100644 --- a/storage/2020-08-04/table/entities/get.go +++ b/storage/2020-08-04/table/entities/get.go @@ -8,7 +8,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 GetEntityInput struct { @@ -26,10 +25,7 @@ type GetEntityResult struct { } // Get queries entities in a table and includes the $filter and $select options. -func (client Client) Get(ctx context.Context, accountName, tableName string, input GetEntityInput) (result GetEntityResult, err error) { - if accountName == "" { - return result, validation.NewError("entities.Client", "Get", "`accountName` cannot be an empty string.") - } +func (client Client) Get(ctx context.Context, tableName string, input GetEntityInput) (result GetEntityResult, err error) { if tableName == "" { return result, validation.NewError("entities.Client", "Get", "`tableName` cannot be an empty string.") } @@ -40,7 +36,7 @@ func (client Client) Get(ctx context.Context, accountName, tableName string, inp return result, validation.NewError("entities.Client", "Get", "`input.RowKey` cannot be an empty string.") } - req, err := client.GetPreparer(ctx, accountName, tableName, input) + req, err := client.GetPreparer(ctx, tableName, input) if err != nil { err = autorest.NewErrorWithError(err, "entities.Client", "Get", nil, "Failure preparing request") return @@ -63,7 +59,7 @@ func (client Client) Get(ctx context.Context, accountName, tableName string, inp } // GetPreparer prepares the Get request. -func (client Client) GetPreparer(ctx context.Context, accountName, tableName string, input GetEntityInput) (*http.Request, error) { +func (client Client) GetPreparer(ctx context.Context, tableName string, input GetEntityInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), @@ -80,7 +76,7 @@ func (client Client) GetPreparer(ctx context.Context, accountName, tableName str preparer := autorest.CreatePreparer( autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{tableName}(PartitionKey='{partitionKey}',RowKey='{rowKey}')", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/table/entities/insert.go b/storage/2020-08-04/table/entities/insert.go index 92b05ce..e71483f 100644 --- a/storage/2020-08-04/table/entities/insert.go +++ b/storage/2020-08-04/table/entities/insert.go @@ -8,7 +8,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 InsertEntityInput struct { @@ -30,10 +29,7 @@ type InsertEntityInput struct { } // Insert inserts a new entity into a table. -func (client Client) Insert(ctx context.Context, accountName, tableName string, input InsertEntityInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("entities.Client", "Insert", "`accountName` cannot be an empty string.") - } +func (client Client) Insert(ctx context.Context, tableName string, input InsertEntityInput) (result autorest.Response, err error) { if tableName == "" { return result, validation.NewError("entities.Client", "Insert", "`tableName` cannot be an empty string.") } @@ -44,7 +40,7 @@ func (client Client) Insert(ctx context.Context, accountName, tableName string, return result, validation.NewError("entities.Client", "Insert", "`input.RowKey` cannot be an empty string.") } - req, err := client.InsertPreparer(ctx, accountName, tableName, input) + req, err := client.InsertPreparer(ctx, tableName, input) if err != nil { err = autorest.NewErrorWithError(err, "entities.Client", "Insert", nil, "Failure preparing request") return @@ -67,7 +63,7 @@ func (client Client) Insert(ctx context.Context, accountName, tableName string, } // InsertPreparer prepares the Insert request. -func (client Client) InsertPreparer(ctx context.Context, accountName, tableName string, input InsertEntityInput) (*http.Request, error) { +func (client Client) InsertPreparer(ctx context.Context, tableName string, input InsertEntityInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), } @@ -84,7 +80,7 @@ func (client Client) InsertPreparer(ctx context.Context, accountName, tableName preparer := autorest.CreatePreparer( autorest.AsContentType("application/json"), autorest.AsPost(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{tableName}", pathParameters), autorest.WithJSON(input.Entity), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/table/entities/insert_or_merge.go b/storage/2020-08-04/table/entities/insert_or_merge.go index 1fb4ed3..909732c 100644 --- a/storage/2020-08-04/table/entities/insert_or_merge.go +++ b/storage/2020-08-04/table/entities/insert_or_merge.go @@ -7,7 +7,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 InsertOrMergeEntityInput struct { @@ -27,10 +26,7 @@ type InsertOrMergeEntityInput struct { // InsertOrMerge updates an existing entity or inserts a new entity if it does not exist in the table. // Because this operation can insert or update an entity, it is also known as an upsert operation. -func (client Client) InsertOrMerge(ctx context.Context, accountName, tableName string, input InsertOrMergeEntityInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("entities.Client", "InsertOrMerge", "`accountName` cannot be an empty string.") - } +func (client Client) InsertOrMerge(ctx context.Context, tableName string, input InsertOrMergeEntityInput) (result autorest.Response, err error) { if tableName == "" { return result, validation.NewError("entities.Client", "InsertOrMerge", "`tableName` cannot be an empty string.") } @@ -41,7 +37,7 @@ func (client Client) InsertOrMerge(ctx context.Context, accountName, tableName s return result, validation.NewError("entities.Client", "InsertOrMerge", "`input.RowKey` cannot be an empty string.") } - req, err := client.InsertOrMergePreparer(ctx, accountName, tableName, input) + req, err := client.InsertOrMergePreparer(ctx, tableName, input) if err != nil { err = autorest.NewErrorWithError(err, "entities.Client", "InsertOrMerge", nil, "Failure preparing request") return @@ -64,7 +60,7 @@ func (client Client) InsertOrMerge(ctx context.Context, accountName, tableName s } // InsertOrMergePreparer prepares the InsertOrMerge request. -func (client Client) InsertOrMergePreparer(ctx context.Context, accountName, tableName string, input InsertOrMergeEntityInput) (*http.Request, error) { +func (client Client) InsertOrMergePreparer(ctx context.Context, tableName string, input InsertOrMergeEntityInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), "partitionKey": autorest.Encode("path", input.PartitionKey), @@ -80,7 +76,7 @@ func (client Client) InsertOrMergePreparer(ctx context.Context, accountName, tab preparer := autorest.CreatePreparer( autorest.AsContentType("application/json"), autorest.AsMerge(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{tableName}(PartitionKey='{partitionKey}', RowKey='{rowKey}')", pathParameters), autorest.WithJSON(input.Entity), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/table/entities/insert_or_replace.go b/storage/2020-08-04/table/entities/insert_or_replace.go index 036ba5d..42d3e03 100644 --- a/storage/2020-08-04/table/entities/insert_or_replace.go +++ b/storage/2020-08-04/table/entities/insert_or_replace.go @@ -7,7 +7,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 InsertOrReplaceEntityInput struct { @@ -27,10 +26,7 @@ type InsertOrReplaceEntityInput struct { // InsertOrReplace replaces an existing entity or inserts a new entity if it does not exist in the table. // Because this operation can insert or update an entity, it is also known as an upsert operation. -func (client Client) InsertOrReplace(ctx context.Context, accountName, tableName string, input InsertOrReplaceEntityInput) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("entities.Client", "InsertOrReplace", "`accountName` cannot be an empty string.") - } +func (client Client) InsertOrReplace(ctx context.Context, tableName string, input InsertOrReplaceEntityInput) (result autorest.Response, err error) { if tableName == "" { return result, validation.NewError("entities.Client", "InsertOrReplace", "`tableName` cannot be an empty string.") } @@ -41,7 +37,7 @@ func (client Client) InsertOrReplace(ctx context.Context, accountName, tableName return result, validation.NewError("entities.Client", "InsertOrReplace", "`input.RowKey` cannot be an empty string.") } - req, err := client.InsertOrReplacePreparer(ctx, accountName, tableName, input) + req, err := client.InsertOrReplacePreparer(ctx, tableName, input) if err != nil { err = autorest.NewErrorWithError(err, "entities.Client", "InsertOrReplace", nil, "Failure preparing request") return @@ -64,7 +60,7 @@ func (client Client) InsertOrReplace(ctx context.Context, accountName, tableName } // InsertOrReplacePreparer prepares the InsertOrReplace request. -func (client Client) InsertOrReplacePreparer(ctx context.Context, accountName, tableName string, input InsertOrReplaceEntityInput) (*http.Request, error) { +func (client Client) InsertOrReplacePreparer(ctx context.Context, tableName string, input InsertOrReplaceEntityInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), "partitionKey": autorest.Encode("path", input.PartitionKey), @@ -80,7 +76,7 @@ func (client Client) InsertOrReplacePreparer(ctx context.Context, accountName, t preparer := autorest.CreatePreparer( autorest.AsContentType("application/json"), autorest.AsMerge(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{tableName}(PartitionKey='{partitionKey}', RowKey='{rowKey}')", pathParameters), autorest.WithJSON(input.Entity), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/table/entities/lifecycle_test.go b/storage/2020-08-04/table/entities/lifecycle_test.go index a72f63a..5aed864 100644 --- a/storage/2020-08-04/table/entities/lifecycle_test.go +++ b/storage/2020-08-04/table/entities/lifecycle_test.go @@ -37,16 +37,16 @@ func TestEntitiesLifecycle(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - tablesClient := tables.NewWithEnvironment(client.AutoRestEnvironment) + tablesClient := tables.NewWithEnvironment(accountName, client.AutoRestEnvironment) tablesClient.Client = client.PrepareWithAuthorizer(tablesClient.Client, storageAuth) t.Logf("[DEBUG] Creating Table..") - if _, err := tablesClient.Create(ctx, accountName, tableName); err != nil { + if _, err := tablesClient.Create(ctx, tableName); err != nil { t.Fatalf("Error creating Table %q: %s", tableName, err) } - defer tablesClient.Delete(ctx, accountName, tableName) + defer tablesClient.Delete(ctx, tableName) - entitiesClient := NewWithEnvironment(client.AutoRestEnvironment) + entitiesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) entitiesClient.Client = client.PrepareWithAuthorizer(entitiesClient.Client, storageAuth) partitionKey := "hello" @@ -61,7 +61,7 @@ func TestEntitiesLifecycle(t *testing.T) { "hello": "world", }, } - if _, err := entitiesClient.Insert(ctx, accountName, tableName, insertInput); err != nil { + if _, err := entitiesClient.Insert(ctx, tableName, insertInput); err != nil { t.Logf("Error retrieving: %s", err) } @@ -73,7 +73,7 @@ func TestEntitiesLifecycle(t *testing.T) { "hello": "ther88e", }, } - if _, err := entitiesClient.InsertOrMerge(ctx, accountName, tableName, insertOrMergeInput); err != nil { + if _, err := entitiesClient.InsertOrMerge(ctx, tableName, insertOrMergeInput); err != nil { t.Logf("Error insert/merging: %s", err) } @@ -85,7 +85,7 @@ func TestEntitiesLifecycle(t *testing.T) { "hello": "pandas", }, } - if _, err := entitiesClient.InsertOrReplace(ctx, accountName, tableName, insertOrReplaceInput); err != nil { + if _, err := entitiesClient.InsertOrReplace(ctx, tableName, insertOrReplaceInput); err != nil { t.Logf("Error inserting/replacing: %s", err) } @@ -93,7 +93,7 @@ func TestEntitiesLifecycle(t *testing.T) { queryInput := QueryEntitiesInput{ MetaDataLevel: NoMetaData, } - results, err := entitiesClient.Query(ctx, accountName, tableName, queryInput) + results, err := entitiesClient.Query(ctx, tableName, queryInput) if err != nil { t.Logf("Error querying: %s", err) } @@ -119,7 +119,7 @@ func TestEntitiesLifecycle(t *testing.T) { PartitionKey: partitionKey, RowKey: rowKey, } - getResults, err := entitiesClient.Get(ctx, accountName, tableName, getInput) + getResults, err := entitiesClient.Get(ctx, tableName, getInput) if err != nil { t.Logf("Error querying: %s", err) } @@ -138,7 +138,7 @@ func TestEntitiesLifecycle(t *testing.T) { PartitionKey: partitionKey, RowKey: rowKey, } - if _, err := entitiesClient.Delete(ctx, accountName, tableName, deleteInput); err != nil { + if _, err := entitiesClient.Delete(ctx, tableName, deleteInput); err != nil { t.Logf("Error deleting: %s", err) } } diff --git a/storage/2020-08-04/table/entities/query.go b/storage/2020-08-04/table/entities/query.go index c1ba370..735d60a 100644 --- a/storage/2020-08-04/table/entities/query.go +++ b/storage/2020-08-04/table/entities/query.go @@ -9,7 +9,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 QueryEntitiesInput struct { @@ -46,15 +45,12 @@ type QueryEntitiesResult struct { } // Query queries entities in a table and includes the $filter and $select options. -func (client Client) Query(ctx context.Context, accountName, tableName string, input QueryEntitiesInput) (result QueryEntitiesResult, err error) { - if accountName == "" { - return result, validation.NewError("entities.Client", "Query", "`accountName` cannot be an empty string.") - } +func (client Client) Query(ctx context.Context, tableName string, input QueryEntitiesInput) (result QueryEntitiesResult, err error) { if tableName == "" { return result, validation.NewError("entities.Client", "Query", "`tableName` cannot be an empty string.") } - req, err := client.QueryPreparer(ctx, accountName, tableName, input) + req, err := client.QueryPreparer(ctx, tableName, input) if err != nil { err = autorest.NewErrorWithError(err, "entities.Client", "Query", nil, "Failure preparing request") return @@ -77,7 +73,7 @@ func (client Client) Query(ctx context.Context, accountName, tableName string, i } // QueryPreparer prepares the Query request. -func (client Client) QueryPreparer(ctx context.Context, accountName, tableName string, input QueryEntitiesInput) (*http.Request, error) { +func (client Client) QueryPreparer(ctx context.Context, tableName string, input QueryEntitiesInput) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), @@ -128,7 +124,7 @@ func (client Client) QueryPreparer(ctx context.Context, accountName, tableName s // GET /myaccount/Customers()?$filter=(Rating%20ge%203)%20and%20(Rating%20le%206)&$select=PartitionKey,RowKey,Address,CustomerSince preparer := autorest.CreatePreparer( autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{tableName}({additionalParameters})", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/table/entities/resource_id.go b/storage/2020-08-04/table/entities/resource_id.go index 249671d..1e9eb0d 100644 --- a/storage/2020-08-04/table/entities/resource_id.go +++ b/storage/2020-08-04/table/entities/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given Entity // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, tableName, partitionKey, rowKey string) string { - domain := endpoints.GetTableEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s(PartitionKey='%s',RowKey='%s')", domain, tableName, partitionKey, rowKey) +func (client Client) GetResourceID(tableName, partitionKey, rowKey string) string { + return fmt.Sprintf("%s/%s(PartitionKey='%s',RowKey='%s')", client.endpoint, tableName, partitionKey, rowKey) } type ResourceID struct { diff --git a/storage/2020-08-04/table/entities/resource_id_test.go b/storage/2020-08-04/table/entities/resource_id_test.go index ccc4201..801e595 100644 --- a/storage/2020-08-04/table/entities/resource_id_test.go +++ b/storage/2020-08-04/table/entities/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "table1", "partition1", "row1") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("table1", "partition1", "row1") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } diff --git a/storage/2020-08-04/table/tables/README.md b/storage/2020-08-04/table/tables/README.md index 40ec349..673950f 100644 --- a/storage/2020-08-04/table/tables/README.md +++ b/storage/2020-08-04/table/tables/README.md @@ -30,10 +30,10 @@ func Example() error { tablesClient.Client.Authorizer = storageAuth ctx := context.TODO() - if _, err := tablesClient.Insert(ctx, accountName, tableName); err != nil { + if _, err := tablesClient.Insert(ctx, tableName); err != nil { return fmt.Errorf("Error creating Table: %s", err) } return nil } -``` \ No newline at end of file +``` diff --git a/storage/2020-08-04/table/tables/acl_get.go b/storage/2020-08-04/table/tables/acl_get.go index 0ef0000..3fc2ecc 100644 --- a/storage/2020-08-04/table/tables/acl_get.go +++ b/storage/2020-08-04/table/tables/acl_get.go @@ -7,7 +7,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 GetACLResult struct { @@ -17,15 +16,12 @@ type GetACLResult struct { } // GetACL returns the Access Control List for the specified Table -func (client Client) GetACL(ctx context.Context, accountName, tableName string) (result GetACLResult, err error) { - if accountName == "" { - return result, validation.NewError("tables.Client", "GetACL", "`accountName` cannot be an empty string.") - } +func (client Client) GetACL(ctx context.Context, tableName string) (result GetACLResult, err error) { if tableName == "" { return result, validation.NewError("tables.Client", "GetACL", "`tableName` cannot be an empty string.") } - req, err := client.GetACLPreparer(ctx, accountName, tableName) + req, err := client.GetACLPreparer(ctx, tableName) if err != nil { err = autorest.NewErrorWithError(err, "tables.Client", "GetACL", nil, "Failure preparing request") return @@ -48,7 +44,7 @@ func (client Client) GetACL(ctx context.Context, accountName, tableName string) } // GetACLPreparer prepares the GetACL request. -func (client Client) GetACLPreparer(ctx context.Context, accountName, tableName string) (*http.Request, error) { +func (client Client) GetACLPreparer(ctx context.Context, tableName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), } @@ -64,7 +60,7 @@ func (client Client) GetACLPreparer(ctx context.Context, accountName, tableName preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{tableName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/table/tables/acl_set.go b/storage/2020-08-04/table/tables/acl_set.go index c26bffc..56b6b7d 100644 --- a/storage/2020-08-04/table/tables/acl_set.go +++ b/storage/2020-08-04/table/tables/acl_set.go @@ -8,7 +8,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 setAcl struct { @@ -18,15 +17,12 @@ type setAcl struct { } // SetACL sets the specified Access Control List for the specified Table -func (client Client) SetACL(ctx context.Context, accountName, tableName string, acls []SignedIdentifier) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("tables.Client", "SetACL", "`accountName` cannot be an empty string.") - } +func (client Client) SetACL(ctx context.Context, tableName string, acls []SignedIdentifier) (result autorest.Response, err error) { if tableName == "" { return result, validation.NewError("tables.Client", "SetACL", "`tableName` cannot be an empty string.") } - req, err := client.SetACLPreparer(ctx, accountName, tableName, acls) + req, err := client.SetACLPreparer(ctx, tableName, acls) if err != nil { err = autorest.NewErrorWithError(err, "tables.Client", "SetACL", nil, "Failure preparing request") return @@ -49,7 +45,7 @@ func (client Client) SetACL(ctx context.Context, accountName, tableName string, } // SetACLPreparer prepares the SetACL request. -func (client Client) SetACLPreparer(ctx context.Context, accountName, tableName string, acls []SignedIdentifier) (*http.Request, error) { +func (client Client) SetACLPreparer(ctx context.Context, tableName string, acls []SignedIdentifier) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), } @@ -69,7 +65,7 @@ func (client Client) SetACLPreparer(ctx context.Context, accountName, tableName preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/{tableName}", pathParameters), autorest.WithQueryParameters(queryParameters), autorest.WithHeaders(headers), diff --git a/storage/2020-08-04/table/tables/api.go b/storage/2020-08-04/table/tables/api.go index d869819..ef871df 100644 --- a/storage/2020-08-04/table/tables/api.go +++ b/storage/2020-08-04/table/tables/api.go @@ -7,11 +7,11 @@ import ( ) type StorageTable interface { - Delete(ctx context.Context, accountName, tableName string) (result autorest.Response, err error) - Exists(ctx context.Context, accountName, tableName string) (result autorest.Response, err error) - GetACL(ctx context.Context, accountName, tableName string) (result GetACLResult, err error) - Create(ctx context.Context, accountName, tableName string) (result autorest.Response, err error) - GetResourceID(accountName, tableName string) string - Query(ctx context.Context, accountName string, metaDataLevel MetaDataLevel) (result GetResult, err error) - SetACL(ctx context.Context, accountName, tableName string, acls []SignedIdentifier) (result autorest.Response, err error) + Delete(ctx context.Context, tableName string) (result autorest.Response, err error) + Exists(ctx context.Context, tableName string) (result autorest.Response, err error) + GetACL(ctx context.Context, tableName string) (result GetACLResult, err error) + Create(ctx context.Context, tableName string) (result autorest.Response, err error) + GetResourceID(tableName string) string + Query(ctx context.Context, metaDataLevel MetaDataLevel) (result GetResult, err error) + SetACL(ctx context.Context, tableName string, acls []SignedIdentifier) (result autorest.Response, err error) } diff --git a/storage/2020-08-04/table/tables/client.go b/storage/2020-08-04/table/tables/client.go index 56724b9..267a7e3 100644 --- a/storage/2020-08-04/table/tables/client.go +++ b/storage/2020-08-04/table/tables/client.go @@ -3,23 +3,32 @@ package tables 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 Table Storage Shares. 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) } // NewWithEnvironment 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.BuildTableEndpoint(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, } } diff --git a/storage/2020-08-04/table/tables/create.go b/storage/2020-08-04/table/tables/create.go index 561f574..e8d8ca4 100644 --- a/storage/2020-08-04/table/tables/create.go +++ b/storage/2020-08-04/table/tables/create.go @@ -7,7 +7,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 createTableRequest struct { @@ -15,15 +14,12 @@ type createTableRequest struct { } // Create creates a new table in the storage account. -func (client Client) Create(ctx context.Context, accountName, tableName string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("tables.Client", "Create", "`accountName` cannot be an empty string.") - } +func (client Client) Create(ctx context.Context, tableName string) (result autorest.Response, err error) { if tableName == "" { return result, validation.NewError("tables.Client", "Create", "`tableName` cannot be an empty string.") } - req, err := client.CreatePreparer(ctx, accountName, tableName) + req, err := client.CreatePreparer(ctx, tableName) if err != nil { err = autorest.NewErrorWithError(err, "tables.Client", "Create", nil, "Failure preparing request") return @@ -46,7 +42,7 @@ func (client Client) Create(ctx context.Context, accountName, tableName string) } // CreatePreparer prepares the Create request. -func (client Client) CreatePreparer(ctx context.Context, accountName, tableName string) (*http.Request, error) { +func (client Client) CreatePreparer(ctx context.Context, tableName string) (*http.Request, error) { headers := map[string]interface{}{ "x-ms-version": APIVersion, // NOTE: we could support returning metadata here, but it doesn't appear to be directly useful @@ -62,7 +58,7 @@ func (client Client) CreatePreparer(ctx context.Context, accountName, tableName preparer := autorest.CreatePreparer( autorest.AsContentType("application/json"), autorest.AsPost(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPath("/Tables"), autorest.WithJSON(body), autorest.WithHeaders(headers)) diff --git a/storage/2020-08-04/table/tables/delete.go b/storage/2020-08-04/table/tables/delete.go index 5b5ec86..1774928 100644 --- a/storage/2020-08-04/table/tables/delete.go +++ b/storage/2020-08-04/table/tables/delete.go @@ -7,19 +7,15 @@ 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" ) // Delete deletes the specified table and any data it contains. -func (client Client) Delete(ctx context.Context, accountName, tableName string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("tables.Client", "Delete", "`accountName` cannot be an empty string.") - } +func (client Client) Delete(ctx context.Context, tableName string) (result autorest.Response, err error) { if tableName == "" { return result, validation.NewError("tables.Client", "Delete", "`tableName` cannot be an empty string.") } - req, err := client.DeletePreparer(ctx, accountName, tableName) + req, err := client.DeletePreparer(ctx, tableName) if err != nil { err = autorest.NewErrorWithError(err, "tables.Client", "Delete", nil, "Failure preparing request") return @@ -42,7 +38,7 @@ func (client Client) Delete(ctx context.Context, accountName, tableName string) } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName, tableName string) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, tableName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), } @@ -53,7 +49,7 @@ func (client Client) DeletePreparer(ctx context.Context, accountName, tableName preparer := autorest.CreatePreparer( autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/Tables('{tableName}')", pathParameters)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) } diff --git a/storage/2020-08-04/table/tables/exists.go b/storage/2020-08-04/table/tables/exists.go index 6abe4f0..ade8ac6 100644 --- a/storage/2020-08-04/table/tables/exists.go +++ b/storage/2020-08-04/table/tables/exists.go @@ -7,19 +7,15 @@ 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" ) // Exists checks that the specified table exists -func (client Client) Exists(ctx context.Context, accountName, tableName string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("tables.Client", "Exists", "`accountName` cannot be an empty string.") - } +func (client Client) Exists(ctx context.Context, tableName string) (result autorest.Response, err error) { if tableName == "" { return result, validation.NewError("tables.Client", "Exists", "`tableName` cannot be an empty string.") } - req, err := client.ExistsPreparer(ctx, accountName, tableName) + req, err := client.ExistsPreparer(ctx, tableName) if err != nil { err = autorest.NewErrorWithError(err, "tables.Client", "Exists", nil, "Failure preparing request") return @@ -42,7 +38,7 @@ func (client Client) Exists(ctx context.Context, accountName, tableName string) } // ExistsPreparer prepares the Exists request. -func (client Client) ExistsPreparer(ctx context.Context, accountName, tableName string) (*http.Request, error) { +func (client Client) ExistsPreparer(ctx context.Context, tableName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "tableName": autorest.Encode("path", tableName), } @@ -59,7 +55,7 @@ func (client Client) ExistsPreparer(ctx context.Context, accountName, tableName preparer := autorest.CreatePreparer( autorest.AsGet(), autorest.AsContentType("application/json"), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPathParameters("/Tables('{tableName}')", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/table/tables/lifecycle_test.go b/storage/2020-08-04/table/tables/lifecycle_test.go index 21ae26a..b390b0e 100644 --- a/storage/2020-08-04/table/tables/lifecycle_test.go +++ b/storage/2020-08-04/table/tables/lifecycle_test.go @@ -3,11 +3,12 @@ package tables import ( "context" "fmt" - "github.com/Azure/go-autorest/autorest" "log" "testing" "time" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage" "github.com/tombuildsstuff/giovanni/storage/internal/testhelpers" ) @@ -22,7 +23,7 @@ func TestTablesLifecycle(t *testing.T) { if err != nil { t.Fatal(err) } - + resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt()) accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString()) tableName := fmt.Sprintf("table%d", testhelpers.RandomInt()) @@ -37,23 +38,23 @@ func TestTablesLifecycle(t *testing.T) { if err != nil { t.Fatalf("building SharedKeyAuthorizer: %+v", err) } - tablesClient := NewWithEnvironment(client.AutoRestEnvironment) + tablesClient := NewWithEnvironment(accountName, client.AutoRestEnvironment) tablesClient.Client = client.PrepareWithAuthorizer(tablesClient.Client, storageAuth) t.Logf("[DEBUG] Creating Table..") - if _, err := tablesClient.Create(ctx, accountName, tableName); err != nil { + if _, err := tablesClient.Create(ctx, tableName); err != nil { t.Fatalf("Error creating Table %q: %s", tableName, err) } // first look it up directly and confirm it's there t.Logf("[DEBUG] Checking if Table exists..") - if _, err := tablesClient.Exists(ctx, accountName, tableName); err != nil { + if _, err := tablesClient.Exists(ctx, tableName); err != nil { t.Fatalf("Error checking if Table %q exists: %s", tableName, err) } // then confirm it exists in the Query too t.Logf("[DEBUG] Querying for Tables..") - result, err := tablesClient.Query(ctx, accountName, NoMetaData) + result, err := tablesClient.Query(ctx, NoMetaData) if err != nil { t.Fatalf("Error retrieving Tables: %s", err) } @@ -80,12 +81,12 @@ func TestTablesLifecycle(t *testing.T) { }, }, } - if _, err := tablesClient.SetACL(ctx, accountName, tableName, acls); err != nil { + if _, err := tablesClient.SetACL(ctx, tableName, acls); err != nil { t.Fatalf("Error setting ACLs: %s", err) } t.Logf("[DEBUG] Retrieving ACL's for Table %q..", tableName) - retrievedACLs, err := tablesClient.GetACL(ctx, accountName, tableName) + retrievedACLs, err := tablesClient.GetACL(ctx, tableName) if err != nil { t.Fatalf("Error retrieving ACLs: %s", err) } @@ -115,7 +116,7 @@ func TestTablesLifecycle(t *testing.T) { } t.Logf("[DEBUG] Deleting Table %q..", tableName) - if _, err := tablesClient.Delete(ctx, accountName, tableName); err != nil { + if _, err := tablesClient.Delete(ctx, tableName); err != nil { t.Fatalf("Error deleting %q: %s", tableName, err) } } diff --git a/storage/2020-08-04/table/tables/query.go b/storage/2020-08-04/table/tables/query.go index 475370f..b3b7efd 100644 --- a/storage/2020-08-04/table/tables/query.go +++ b/storage/2020-08-04/table/tables/query.go @@ -7,8 +7,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 GetResult struct { @@ -19,12 +17,8 @@ type GetResult struct { } // Query returns a list of tables under the specified account. -func (client Client) Query(ctx context.Context, accountName string, metaDataLevel MetaDataLevel) (result GetResult, err error) { - if accountName == "" { - return result, validation.NewError("tables.Client", "Query", "`accountName` cannot be an empty string.") - } - - req, err := client.QueryPreparer(ctx, accountName, metaDataLevel) +func (client Client) Query(ctx context.Context, metaDataLevel MetaDataLevel) (result GetResult, err error) { + req, err := client.QueryPreparer(ctx, metaDataLevel) if err != nil { err = autorest.NewErrorWithError(err, "tables.Client", "Query", nil, "Failure preparing request") return @@ -47,7 +41,7 @@ func (client Client) Query(ctx context.Context, accountName string, metaDataLeve } // QueryPreparer prepares the Query request. -func (client Client) QueryPreparer(ctx context.Context, accountName string, metaDataLevel MetaDataLevel) (*http.Request, error) { +func (client Client) QueryPreparer(ctx context.Context, metaDataLevel MetaDataLevel) (*http.Request, error) { // NOTE: whilst this supports ContinuationTokens and 'Top' // it appears that 'Skip' returns a '501 Not Implemented' // as such, we intentionally don't support those right now @@ -59,7 +53,7 @@ func (client Client) QueryPreparer(ctx context.Context, accountName string, meta preparer := autorest.CreatePreparer( autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), + autorest.WithBaseURL(client.endpoint), autorest.WithPath("/Tables"), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) diff --git a/storage/2020-08-04/table/tables/resource_id.go b/storage/2020-08-04/table/tables/resource_id.go index 4ceae10..24aaa57 100644 --- a/storage/2020-08-04/table/tables/resource_id.go +++ b/storage/2020-08-04/table/tables/resource_id.go @@ -10,9 +10,8 @@ import ( // GetResourceID returns the Resource ID for the given Table // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, tableName string) string { - domain := endpoints.GetTableEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/Tables('%s')", domain, tableName) +func (client Client) GetResourceID(tableName string) string { + return fmt.Sprintf("%s/Tables('%s')", client.endpoint, tableName) } type ResourceID struct { diff --git a/storage/2020-08-04/table/tables/resource_id_test.go b/storage/2020-08-04/table/tables/resource_id_test.go index f87cbcb..a61b601 100644 --- a/storage/2020-08-04/table/tables/resource_id_test.go +++ b/storage/2020-08-04/table/tables/resource_id_test.go @@ -30,8 +30,8 @@ func TestGetResourceID(t *testing.T) { } for _, v := range testData { t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name) - c := NewWithEnvironment(v.Environment) - actual := c.GetResourceID("account1", "table1") + c := NewWithEnvironment("account1", v.Environment) + actual := c.GetResourceID("table1") if actual != v.Expected { t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) } diff --git a/storage/internal/endpoints/endpoints.go b/storage/internal/endpoints/endpoints.go index 2c58e8f..fb0ec58 100644 --- a/storage/internal/endpoints/endpoints.go +++ b/storage/internal/endpoints/endpoints.go @@ -13,27 +13,27 @@ func GetAccountNameFromEndpoint(endpoint string) (*string, error) { return &segments[0], nil } -// GetBlobEndpoint returns the endpoint for Blob API Operations on this storage account -func GetBlobEndpoint(baseUri string, accountName string) string { +// BuildBlobEndpoint returns the endpoint for Blob API Operations on this storage account +func BuildBlobEndpoint(baseUri string, accountName string) string { return fmt.Sprintf("https://%s.blob.%s", accountName, baseUri) } -// GetDataLakeStoreEndpoint returns the endpoint for Data Lake Store API Operations on this storage account -func GetDataLakeStoreEndpoint(baseUri string, accountName string) string { +// BuildDataLakeStoreEndpoint returns the endpoint for Data Lake Store API Operations on this storage account +func BuildDataLakeStoreEndpoint(baseUri string, accountName string) string { return fmt.Sprintf("https://%s.dfs.%s", accountName, baseUri) } -// GetFileEndpoint returns the endpoint for File Share API Operations on this storage account -func GetFileEndpoint(baseUri string, accountName string) string { +// BuildFileEndpoint returns the endpoint for File Share API Operations on this storage account +func BuildFileEndpoint(baseUri string, accountName string) string { return fmt.Sprintf("https://%s.file.%s", accountName, baseUri) } -// GetQueueEndpoint returns the endpoint for Queue API Operations on this storage account -func GetQueueEndpoint(baseUri string, accountName string) string { +// BuildQueueEndpoint returns the endpoint for Queue API Operations on this storage account +func BuildQueueEndpoint(baseUri string, accountName string) string { return fmt.Sprintf("https://%s.queue.%s", accountName, baseUri) } -// GetTableEndpoint returns the endpoint for Table API Operations on this storage account -func GetTableEndpoint(baseUri string, accountName string) string { +// BuildTableEndpoint returns the endpoint for Table API Operations on this storage account +func BuildTableEndpoint(baseUri string, accountName string) string { return fmt.Sprintf("https://%s.table.%s", accountName, baseUri) }