github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/meeting/v1/assignments/requests.go (about) 1 package assignments 2 3 import ( 4 "fmt" 5 6 "github.com/chnsz/golangsdk" 7 ) 8 9 // CreateOpts is the structure required by the Create method to assign the administrator role for an account. 10 type CreateOpts struct { 11 // Account type. 12 // 0: HUAWEI CLOUD conference account. Used for account/password authentication. 13 // 1: Third-party User ID, used for App ID authentication. 14 // default 0 15 AccountType int `json:"-"` 16 // account account. 17 // If it is an account/password authentication method, it refers to the HUAWEI CLOUD conference account. 18 // If it is the App ID authentication method, it refers to the third-party User ID. 19 Account string `json:"account" required:"true"` 20 // Authorization token. 21 Token string `json:"-" required:"true"` 22 } 23 24 // QueryOpts is the structure used to build the query path. 25 type QueryOpts struct { 26 // Account type. 27 // 0: HUAWEI CLOUD conference account. Used for account/password authentication. 28 // 1: Third-party User ID, used for App ID authentication. 29 // default 0 30 AccountType int `q:"accountType"` 31 } 32 33 var requestOpts = golangsdk.RequestOpts{ 34 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 35 } 36 37 // Create is a method to assign the administrator role for an account. 38 func Create(c *golangsdk.ServiceClient, opts CreateOpts) error { 39 url := rootURL(c) 40 query, err := golangsdk.BuildQueryString(QueryOpts{ 41 AccountType: opts.AccountType, 42 }) 43 if err != nil { 44 return err 45 } 46 url += query.String() 47 48 b, err := golangsdk.BuildRequestBody(opts, "") 49 if err != nil { 50 return err 51 } 52 _, err = c.Post(url, b, nil, &golangsdk.RequestOpts{ 53 MoreHeaders: map[string]string{ 54 "Content-Type": "application/json;charset=UTF-8", 55 "X-Access-Token": opts.Token, 56 }, 57 }) 58 return err 59 } 60 61 // GetOpts is the structure used to build the query path and authorization. 62 type GetOpts struct { 63 // Account type. 64 // 0: HUAWEI CLOUD conference account. Used for account/password authentication. 65 // 1: Third-party User ID, used for App ID authentication. 66 // default 0 67 AccountType int `q:"accountType"` 68 // account account. 69 // If it is an account/password authentication method, it refers to the HUAWEI CLOUD conference account. 70 // If it is the App ID authentication method, it refers to the third-party User ID. 71 Account string `json:"-" required:"true"` 72 // Authorization token. 73 Token string `json:"-" required:"true"` 74 } 75 76 // Get is a method to query the details of the role assignment. 77 func Get(c *golangsdk.ServiceClient, opts GetOpts) (*Administrator, error) { 78 url := resourceURL(c, opts.Account) 79 query, err := golangsdk.BuildQueryString(opts) 80 if err != nil { 81 return nil, err 82 } 83 url += query.String() 84 85 var r Administrator 86 _, err = c.Get(url, &r, &golangsdk.RequestOpts{ 87 MoreHeaders: map[string]string{ 88 "Content-Type": "application/json;charset=UTF-8", 89 "X-Access-Token": opts.Token, 90 }, 91 }) 92 return &r, err 93 } 94 95 // DeleteOpts is the structure used to build the query path and authorization. 96 type DeleteOpts struct { 97 // Account type. 98 // 0: HUAWEI CLOUD conference account. Used for account/password authentication. 99 // 1: Third-party User ID, used for App ID authentication. 100 // default 0 101 AccountType int `q:"accountType"` 102 // Authorization token. 103 Token string `json:"-"` 104 // List of user account. 105 Accounts []string `json:"-"` 106 } 107 108 // BatchDelete is a method to revoke administrator roles for all accounts. 109 func BatchDelete(c *golangsdk.ServiceClient, opts DeleteOpts) error { 110 url := deleteURL(c) 111 query, err := golangsdk.BuildQueryString(opts) 112 if err != nil { 113 return err 114 } 115 url += query.String() 116 117 if opts.Token == "" { 118 return fmt.Errorf("The authorization token must be supported.") 119 } 120 121 _, err = c.Post(url, opts.Accounts, nil, &golangsdk.RequestOpts{ 122 MoreHeaders: map[string]string{ 123 "Content-Type": "application/json;charset=UTF-8", 124 "X-Access-Token": opts.Token, 125 }, 126 }) 127 return err 128 }