Skip to content

Commit

Permalink
Merge pull request #54 from magodo/share_support_enabled_protocol
Browse files Browse the repository at this point in the history
storage: file share add supports for `EnabledProtocol`
  • Loading branch information
tombuildsstuff authored Oct 27, 2021
2 parents e2b6cdb + ce9f6d4 commit 9dc34b1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
9 changes: 9 additions & 0 deletions storage/2020-08-04/file/shares/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type CreateInput struct {
// Must be greater than 0, and less than or equal to 5TB (5120).
QuotaInGB int

// Specifies the enabled protocols on the share. If not specified, the default is SMB.
EnabledProtocol ShareProtocol

MetaData map[string]string
}

Expand Down Expand Up @@ -76,6 +79,12 @@ func (client Client) CreatePreparer(ctx context.Context, accountName, shareName
"x-ms-share-quota": input.QuotaInGB,
}

protocol := SMB
if input.EnabledProtocol != "" {
protocol = input.EnabledProtocol
}
headers["x-ms-enabled-protocols"] = protocol

headers = metadata.SetIntoHeaders(headers, input.MetaData)

preparer := autorest.CreatePreparer(
Expand Down
46 changes: 46 additions & 0 deletions storage/2020-08-04/file/shares/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func TestSharesLifecycle(t *testing.T) {
if share.ShareQuota != 1 {
t.Fatalf("Expected Quota to be 1 but got: %d", share.ShareQuota)
}
if share.EnabledProtocol != SMB {
t.Fatalf("Expected EnabledProtocol to SMB but got: %s", share.EnabledProtocol)
}

_, err = sharesClient.SetProperties(ctx, accountName, shareName, 5)
if err != nil {
Expand Down Expand Up @@ -293,3 +296,46 @@ func TestSharesLifecycleLargeQuota(t *testing.T) {
t.Fatalf("Error deleting Share: %s", err)
}
}

func TestSharesLifecycleNFSProtocol(t *testing.T) {
client, err := testhelpers.Build(t)
if err != nil {
t.Fatal(err)
}
ctx := context.TODO()
resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt())
accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString())
shareName := fmt.Sprintf("share-%d", testhelpers.RandomInt())

testData, err := client.BuildTestResourcesWithSku(ctx, resourceGroup, accountName, storage.KindFileStorage, storage.SkuNamePremiumLRS)
if err != nil {
t.Fatal(err)
}
defer client.DestroyTestResources(ctx, resourceGroup, accountName)

storageAuth := auth.NewSharedKeyLiteAuthorizer(accountName, testData.StorageAccountKey)
sharesClient := NewWithEnvironment(client.Environment)
sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth)

input := CreateInput{
QuotaInGB: 1000,
EnabledProtocol: NFS,
}
_, err = sharesClient.Create(ctx, accountName, shareName, input)
if err != nil {
t.Fatalf("Error creating fileshare: %s", err)
}

share, err := sharesClient.GetProperties(ctx, accountName, shareName)
if err != nil {
t.Fatalf("Error retrieving share: %s", err)
}
if share.EnabledProtocol != NFS {
t.Fatalf(`Expected enabled protocol to be "NFS" but got: %q`, share.EnabledProtocol)
}

_, err = sharesClient.Delete(ctx, accountName, shareName, false)
if err != nil {
t.Fatalf("Error deleting Share: %s", err)
}
}
10 changes: 10 additions & 0 deletions storage/2020-08-04/file/shares/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ type AccessPolicy struct {
Expiry string `xml:"Expiry"`
Permission string `xml:"Permission"`
}

type ShareProtocol string

const (
// SMB indicates the share can be accessed by SMBv3.0, SMBv2.1 and REST.
SMB ShareProtocol = "SMB"

// NFS indicates the share can be accessed by NFSv4.1. A premium account is required for this option.
NFS ShareProtocol = "NFS"
)
11 changes: 9 additions & 2 deletions storage/2020-08-04/file/shares/properties_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
type GetPropertiesResult struct {
autorest.Response

MetaData map[string]string
ShareQuota int
MetaData map[string]string
ShareQuota int
EnabledProtocol ShareProtocol
}

// GetProperties returns the properties about the specified Storage Share
Expand Down Expand Up @@ -100,6 +101,12 @@ func (client Client) GetPropertiesResponder(resp *http.Response) (result GetProp
}
result.ShareQuota = quota
}

protocol := SMB
if protocolRaw := resp.Header.Get("x-ms-enabled-protocols"); protocolRaw != "" {
protocol = ShareProtocol(protocolRaw)
}
result.EnabledProtocol = protocol
}

err = autorest.Respond(
Expand Down

0 comments on commit 9dc34b1

Please sign in to comment.