package methods import ( "context" "log" "time" "gitlab.corp.mail.ru/cloud/go/jet/pkg/configured" "gitlab.corp.mail.ru/cloud/go/jet/pkg/jet" ) type Args struct { URL *string AuthUser *string AuthPassword *string PID *uint64 Name *string UID *uint64 Email *string TreeID *string Operation *uint64 Quota *uint64 Mode *uint64 ToSet *string ToUnset *string } func Call(method *string, args Args) { ctx := context.Background() client := jet.New(configured.JetClientConfig{ URL: "http://" + *args.URL, Timeout: 10 * time.Second, BasicAuthCred: configured.BasicAuthConfig{ Username: *args.AuthUser, Password: *args.AuthPassword, }, }) switch *method { case "project_register": err := client.BizProjectRegister(ctx, "some_request_id", &jet.BizProjectRegisterRequest{ PID: *args.PID, Name: *args.Name, }) if err != nil { log.Fatal(err.Error()) } case "project_delete": err := client.BizProjectDelete(ctx, "some_request_id", &jet.BizProjectDeleteRequest{ PID: *args.PID, }) if err != nil { log.Fatal(err.Error()) } case "catalog_acl_ctl": err := client.BizCatalogACLCtl(ctx, "some_request_id", &jet.BizCatalogACLCtlRequest{ PID: *args.PID, TreeID: []byte(*args.TreeID), UID: *args.UID, Operation: uint8(*args.Operation), }) if err != nil { log.Fatal(err.Error()) } case "catalog_acl_list": resp, err := client.BizCatalogACLList(ctx, "some_request_id", &jet.BizCatalogACLListRequest{ PID: *args.PID, TreeID: []byte(*args.TreeID), }) if err != nil { log.Fatal(err.Error()) } log.Printf("Method response: %#v", resp) case "catalog_create": resp, err := client.BizCatalogCreate(ctx, "some_request_id", &jet.BizCatalogCreateRequest{ PID: *args.PID, Name: *args.Name, Quota: *args.Quota, }) if err != nil { log.Fatal(err.Error()) } log.Printf("Method response: %#v", resp) case "catalog_delete": err := client.BizCatalogDelete(ctx, "some_request_id", &jet.BizCatalogDeleteRequest{ PID: *args.PID, TreeID: []byte(*args.TreeID), }) if err != nil { log.Fatal(err.Error()) } case "catalog_mount": err := client.BizCatalogMount(ctx, "some_request_id", &jet.BizCatalogMountRequest{ PID: *args.PID, TreeID: []byte(*args.TreeID), UID: *args.UID, Mode: uint8(*args.Mode), }) if err != nil { log.Fatal(err.Error()) } case "catalog_umount": err := client.BizCatalogUMount(ctx, "some_request_id", &jet.BizCatalogUMountRequest{ PID: *args.PID, TreeID: []byte(*args.TreeID), UID: *args.UID, }) if err != nil { log.Fatal(err.Error()) } case "catalog_quota_set": err := client.BizCatalogQuotaSet(ctx, "some_request_id", &jet.BizCatalogQuotaSetRequest{ PID: *args.PID, TreeID: []byte(*args.TreeID), Quota: *args.Quota, }) if err != nil { log.Fatal(err.Error()) } case "user_register": err := client.BizUserRegister(ctx, "some_request_id", &jet.BizUserRegisterRequest{ PID: *args.PID, UID: *args.UID, Email: *args.Email, Quota: *args.Quota, }) if err != nil { log.Fatal(err.Error()) } case "user_delete": err := client.BizUserDelete(ctx, "some_request_id", &jet.BizUserRequest{ PID: *args.PID, UID: *args.UID, }) if err != nil { log.Fatal(err.Error()) } case "user_block": err := client.BizUserBlock(ctx, "some_request_id", &jet.BizUserRequest{ PID: *args.PID, UID: *args.UID, }) if err != nil { log.Fatal(err.Error()) } case "user_unblock": err := client.BizUserUnblock(ctx, "some_request_id", &jet.BizUserRequest{ PID: *args.PID, UID: *args.UID, }) if err != nil { log.Fatal(err.Error()) } case "user_flags_get": resp, err := client.BizUserFlagsGet(ctx, "some_request_id", &jet.BizUserRequest{ PID: *args.PID, UID: *args.UID, }) if err != nil { log.Fatal(err.Error()) } log.Printf("Method response: %#v", resp) case "user_flags_set": resp, err := client.BizUserFlagsSet(ctx, "some_request_id", &jet.BizUserSetFlagsRequest{ PID: *args.PID, UID: *args.UID, ToSet: []string{*args.ToSet}, ToUnset: []string{*args.ToUnset}, }) if err != nil { log.Fatal(err.Error()) } log.Printf("Method response: %#v", resp) case "user_quota_set": resp, err := client.BizUserQuotaSet(ctx, "some_request_id", &jet.BizUserSetQuotaRequest{ PID: *args.PID, UID: *args.UID, Operation: uint8(*args.Operation), Quota: *args.Quota, }) if err != nil { log.Fatal(err.Error()) } log.Printf("Method response: %#v", resp) case "user_du": resp, err := client.BizUserDU(ctx, "some_request_id", &jet.BizUserRequest{ PID: *args.PID, UID: *args.UID, }) if err != nil { log.Fatal(err.Error()) } log.Printf("Method response: %#v", resp) default: log.Fatalf("unknown method: %s", *method) } log.Print("command applied successfully") }