improve golang example
This commit is contained in:
parent
9bdd615b33
commit
2c4a602172
1 changed files with 70 additions and 8 deletions
|
@ -21,6 +21,7 @@ func main() {
|
||||||
ctx := context.WithValue(context.Background(), garage.ContextAccessToken, "s3cr3t")
|
ctx := context.WithValue(context.Background(), garage.ContextAccessToken, "s3cr3t")
|
||||||
|
|
||||||
// Send a request
|
// Send a request
|
||||||
|
fmt.Println("--- nodes ---")
|
||||||
resp, r, err := client.NodesApi.GetNodes(ctx).Execute()
|
resp, r, err := client.NodesApi.GetNodes(ctx).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error when calling `NodesApi.GetNodes`\n")
|
fmt.Fprintf(os.Stderr, "Error when calling `NodesApi.GetNodes`\n")
|
||||||
|
@ -69,6 +70,7 @@ func main() {
|
||||||
|
|
||||||
|
|
||||||
// Key
|
// Key
|
||||||
|
fmt.Println("\n--- key ---")
|
||||||
// -- create
|
// -- create
|
||||||
key := "openapi-key"
|
key := "openapi-key"
|
||||||
keyInfo, r, err := client.KeyApi.AddKey(ctx).AddKeyRequest(garage.AddKeyRequest{Name: *garage.NewNullableString(&key) }).Execute()
|
keyInfo, r, err := client.KeyApi.AddKey(ctx).AddKeyRequest(garage.AddKeyRequest{Name: *garage.NewNullableString(&key) }).Execute()
|
||||||
|
@ -79,15 +81,41 @@ func main() {
|
||||||
}
|
}
|
||||||
fmt.Printf("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n", *keyInfo.AccessKeyId, *keyInfo.SecretAccessKey.Get())
|
fmt.Printf("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n", *keyInfo.AccessKeyId, *keyInfo.SecretAccessKey.Get())
|
||||||
|
|
||||||
// -- update
|
|
||||||
//update, r, err := apiClient.KeyApi.UpdateKey(context.Background()).Id(id).UpdateKeyRequest(updateKeyRequest).Execute()
|
|
||||||
|
|
||||||
// -- delete
|
// -- delete
|
||||||
defer func() {
|
defer func() {
|
||||||
// todo delete key
|
r, err := client.KeyApi.DeleteKey(ctx).Id(*keyInfo.AccessKeyId).Execute()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error when calling `KeyApi.DeleteKey`\n")
|
||||||
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// -- update
|
||||||
|
id := *keyInfo.AccessKeyId
|
||||||
|
canCreateBucket := true
|
||||||
|
updateKeyRequest := *garage.NewUpdateKeyRequest()
|
||||||
|
updateKeyRequest.SetName("openapi-key-updated")
|
||||||
|
updateKeyRequest.SetAllow(garage.UpdateKeyRequestAllow { CreateBucket: &canCreateBucket })
|
||||||
|
update, r, err := client.KeyApi.UpdateKey(ctx).Id(id).UpdateKeyRequest(updateKeyRequest).Execute()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error when calling `KeyApi.UpdateKey`\n")
|
||||||
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Updated %v with key name %v\n", *update.AccessKeyId, *update.Name)
|
||||||
|
|
||||||
|
// -- list
|
||||||
|
keyList, r, err := client.KeyApi.ListKeys(ctx).Execute()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error when calling `KeyApi.ListKeys`\n")
|
||||||
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Keys count: %v\n", len(keyList))
|
||||||
|
|
||||||
// Bucket
|
// Bucket
|
||||||
|
fmt.Println("\n--- bucket ---")
|
||||||
// -- create
|
// -- create
|
||||||
global_name := "global-ns-openapi-bucket"
|
global_name := "global-ns-openapi-bucket"
|
||||||
local_name := "local-ns-openapi-bucket"
|
local_name := "local-ns-openapi-bucket"
|
||||||
|
@ -105,10 +133,44 @@ func main() {
|
||||||
}
|
}
|
||||||
fmt.Printf("Bucket id: %s\n", *bucketInfo.Id)
|
fmt.Printf("Bucket id: %s\n", *bucketInfo.Id)
|
||||||
|
|
||||||
// update bucket
|
// -- delete
|
||||||
|
|
||||||
// delete bucket
|
|
||||||
defer func() {
|
defer func() {
|
||||||
// todo delete bucket
|
r, err := client.BucketApi.DeleteBucket(ctx).Id(*bucketInfo.Id).Execute()
|
||||||
}()
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error when calling `BucketApi.DeleteBucket`\n")
|
||||||
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// -- update
|
||||||
|
updateBucketRequest := *garage.NewUpdateBucketRequest()
|
||||||
|
|
||||||
|
website := garage.NewUpdateBucketRequestWebsiteAccess()
|
||||||
|
website.SetEnabled(true)
|
||||||
|
website.SetIndexDocument("index.html")
|
||||||
|
website.SetErrorDocument("errors/4xx.html")
|
||||||
|
updateBucketRequest.SetWebsiteAccess(*website)
|
||||||
|
|
||||||
|
quotas := garage.NewUpdateBucketRequestQuotas()
|
||||||
|
quotas.SetMaxSize(1000000000)
|
||||||
|
quotas.SetMaxObjects(999999999)
|
||||||
|
updateBucketRequest.SetQuotas(*quotas)
|
||||||
|
|
||||||
|
updatedBucket, r, err := client.BucketApi.UpdateBucket(ctx).Id(*bucketInfo.Id).UpdateBucketRequest(updateBucketRequest).Execute()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error when calling `BucketApi.UpdateBucket`\n")
|
||||||
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Bucket %v website activation: %v\n", *updatedBucket.Id, *updatedBucket.WebsiteAccess)
|
||||||
|
|
||||||
|
// -- list
|
||||||
|
bucketList, r, err := client.BucketApi.ListBuckets(ctx).Execute()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error when calling `BucketApi.ListBuckets`\n")
|
||||||
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Bucket count: %v\n", len(bucketList))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue