Skip to content

Instantly share code, notes, and snippets.

@stuartleeks
Created July 3, 2019 09:05
Show Gist options
  • Save stuartleeks/19444b0e462062f1d4b4e14205ac5a66 to your computer and use it in GitHub Desktop.
Save stuartleeks/19444b0e462062f1d4b4e14205ac5a66 to your computer and use it in GitHub Desktop.
Storage Management Lifecycle Policy test - Go SDK
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage"
"github.com/Azure/go-autorest/autorest/azure/auth"
)
func main() {
fmt.Println("Hello")
authorizer, err := auth.NewAuthorizerFromCLI()
if err != nil{
fmt.Println(err.Error())
return
}
managementPoliciesClient := storage.NewManagementPoliciesClient("e96f24a6-ceee-43a3-8ad4-5e5dca55656b")
managementPoliciesClient.Authorizer = authorizer
tmpName := "foo"
parameters := storage.ManagementPolicy{
Name: &tmpName,
}
armRules := make([]storage.ManagementPolicyRule, 0)
tmpName2 := "test"
tmpEnabled := true
tmpType := "Lifecycle"
tmpDays := int32(10)
tempRule := storage.ManagementPolicyRule{
Name: &tmpName2,
Enabled: &tmpEnabled,
Type: &tmpType,
Definition: &storage.ManagementPolicyDefinition{
Actions: &storage.ManagementPolicyAction{
BaseBlob: &storage.ManagementPolicyBaseBlob{
TierToCool: &storage.DateAfterModification{
DaysAfterModificationGreaterThan: &tmpDays,
},
},
},
},
}
armRules = append(armRules, tempRule)
parameters.ManagementPolicyProperties = &storage.ManagementPolicyProperties{
Policy: &storage.ManagementPolicySchema{
Rules: &armRules,
},
}
b, err := json.Marshal(parameters)
fmt.Println(string(b))
ctx := context.Background()
result, err := managementPoliciesClient.CreateOrUpdate(ctx, "sdktest", "sltestsa124", parameters)
if err != nil {
fmt.Printf("Error creating Azure Storage Management Policy : %+v", err)
return
}
_ = result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment