github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dli/v1/auth/requests.go (about) 1 package auth 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 ) 6 7 type GrantDataPermissionOpts struct { 8 UserName string `json:"user_name" required:"true"` 9 // Grants or revokes the permission. The parameter value can be grant, revoke, or update. 10 // grant: Indicates to grant users with permissions. 11 // revoke: Indicates to revoke permissions. 12 // update: Indicates to clear all the original permissions and assign the permissions in the provided 13 // permission array. 14 // NOTE: 15 // Users can perform the update operation only when they have been granted with the grant and revoke permissions. 16 Action string `json:"action" required:"true"` 17 // Permission granting information. For details, see Table 3. 18 Privileges []DataPermission `json:"privileges" required:"true"` 19 } 20 21 type DataPermission struct { 22 // Data objects to be assigned. If they are named: 23 // databases.Database_name, data in the entire database will be shared. 24 // databases.Database_name.tables.Table_name, data in the specified table will be shared. 25 // databases.Database_name.tables.Table_name.columns.Column_name, data in the specified column will be shared. 26 // jobs.flink.Flink job ID, data the specified job will be shared. 27 // groups. Package group name, data in the specified package group will be shared. 28 // resources. Package name, data in the specified package will be shared. 29 Object string `json:"object" required:"true"` 30 // List of permissions to be granted, revoked, or updated. 31 // NOTE: 32 // If Action is Update and the update list is empty, all permissions of the user in the database or table 33 // are revoked. 34 Privileges []string `json:"privileges" required:"true"` 35 } 36 37 type ListDataPermissionOpts struct { 38 // Data object to be assigned, which corresponds to the object in API permission assignment. 39 // "jobs.flink.job_ID", data in the specified job will be queried. 40 // "groups.Package_group_name", data in the specified package group will be queried. 41 // "resources.Package_ame", data in the specified package will be queried. 42 // NOTE: 43 // When you view the packages in a group, the object format is resources.package group name/package name. 44 Object string `q:"object"` 45 Limit int `q:"limit"` 46 Offset int `q:"offset"` 47 } 48 49 type GrantQueuePermissionOpts struct { 50 QueueName string `json:"queue_name" required:"true"` 51 UserName string `json:"user_name" required:"true"` 52 // Grants or revokes the permission. The parameter value can be grant, revoke, or update. 53 // grant: Indicates to grant users with permissions. 54 // revoke: Indicates to revoke permissions. 55 // update: Indicates to clear all the original permissions and assign the permissions in the provided 56 // permission array. 57 Action string `json:"action" required:"true"` 58 // List of permissions to be granted, revoked, or updated. The following permissions are supported: 59 // SUBMIT_JOB: indicates to submit a job. 60 // CANCEL_JOB: indicates to cancel a job. 61 // DROP_QUEUE: indicates to a delete a queue. 62 // GRANT_PRIVILEGE: indicates to assign a permission. 63 // REVOKE_PRIVILEGE: indicates to revoke a permission. 64 // SHOW_PRIVILEGE: indicates to view other user's permissions. 65 // RESTART: indicates to restart the queue. 66 // SCALE_QUEUE: indicates to change the queue specifications. 67 // NOTE: 68 // If the update list is empty, all permissions of the queue granted to the user are revoked. 69 Privileges []string `json:"privileges" required:"true"` 70 } 71 72 var RequestOpts = golangsdk.RequestOpts{ 73 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 74 } 75 76 func GrantDataPermission(c *golangsdk.ServiceClient, opts GrantDataPermissionOpts) (*CommonResp, error) { 77 b, err := golangsdk.BuildRequestBody(opts, "") 78 if err != nil { 79 return nil, err 80 } 81 82 var rst CommonResp 83 _, err = c.Put(grantDataPermissionURL(c), b, &rst, &golangsdk.RequestOpts{ 84 MoreHeaders: RequestOpts.MoreHeaders, 85 }) 86 return &rst, err 87 } 88 89 func ListDataPermission(c *golangsdk.ServiceClient, opts ListDataPermissionOpts) (*DataPermissions, error) { 90 url := ListDataPermissionUrl(c) 91 query, err := golangsdk.BuildQueryString(opts) 92 if err != nil { 93 return nil, err 94 } 95 url += query.String() 96 97 var rst DataPermissions 98 _, err = c.Get(url, &rst, &golangsdk.RequestOpts{ 99 MoreHeaders: RequestOpts.MoreHeaders, 100 }) 101 return &rst, err 102 } 103 104 func GrantQueuePermission(c *golangsdk.ServiceClient, opts GrantQueuePermissionOpts) (*CommonResp, error) { 105 b, err := golangsdk.BuildRequestBody(opts, "") 106 if err != nil { 107 return nil, err 108 } 109 110 var rst CommonResp 111 _, err = c.Put(grantQueuePermissionURL(c), b, &rst, &golangsdk.RequestOpts{ 112 MoreHeaders: RequestOpts.MoreHeaders, 113 }) 114 return &rst, err 115 } 116 117 func ListQueuePermission(c *golangsdk.ServiceClient, queueName string) (*QueuePermissions, error) { 118 var rst QueuePermissions 119 _, err := c.Get(listQueuePermissionURL(c, queueName), &rst, &golangsdk.RequestOpts{ 120 MoreHeaders: RequestOpts.MoreHeaders, 121 }) 122 return &rst, err 123 } 124 125 func ListDatabasePermission(c *golangsdk.ServiceClient, databaseName string) (*DatabasePermissions, error) { 126 var rst DatabasePermissions 127 _, err := c.Get(listDatabasePermissionURL(c, databaseName), &rst, &golangsdk.RequestOpts{ 128 MoreHeaders: RequestOpts.MoreHeaders, 129 }) 130 return &rst, err 131 } 132 133 func ListTablePermission(c *golangsdk.ServiceClient, databaseName string, tableName string) (*TablePermissions, error) { 134 var rst TablePermissions 135 _, err := c.Get(listTablePermissionURL(c, databaseName, tableName), &rst, &golangsdk.RequestOpts{ 136 MoreHeaders: RequestOpts.MoreHeaders, 137 }) 138 return &rst, err 139 } 140 141 func GetTablePermissionOfUser(c *golangsdk.ServiceClient, dbName string, tableName string, userName string) ( 142 *TablePermissionsOfUser, error) { 143 var rst TablePermissionsOfUser 144 _, err := c.Get(getTablePermissionOfUserURL(c, dbName, tableName, userName), &rst, &golangsdk.RequestOpts{ 145 MoreHeaders: RequestOpts.MoreHeaders, 146 }) 147 return &rst, err 148 }