批量更新仓库文件推送权限 - BatchUpdateRepositoryFilePushPermissions
功能介绍
批量更新仓库文件推送权限
调试
您可以在API Explorer中调试该接口,支持自动认证鉴权。API Explorer可以自动生成SDK代码示例,并提供SDK代码示例调试功能。
授权信息
账号根用户具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备如下身份策略权限,更多的权限说明请参见权限和授权项。
|
授权项 |
访问级别 |
资源类型(*为必须) |
条件键 |
别名 |
依赖的授权项 |
|---|---|---|---|---|---|
|
codeartsrepo:repository:setRepository |
Write |
- |
- |
- |
- |
URI
PUT /v4/repositories/{repository_id}/file-push-permissions
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
repository_id |
是 |
Integer |
参数解释: 仓库的ID,通过查询用户所有仓库接口查询项目列表获取。 约束限制: 不涉及。 默认取值: 不涉及。 取值范围: 1~2147483647 |
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
X-Auth-Token |
是 |
String |
参数解释: 用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 约束限制: 不涉及。 取值范围: 字符串长度不少于1,不超过10万。 默认取值: 不涉及。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
permissions |
否 |
Array of FilePushPermissionUpdateDto objects |
参数解释: 文件推送权限更新列表。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
id |
否 |
Integer |
参数解释: 仓库文件推送权限ID 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 取值范围: 1~2147483647 |
|
path |
否 |
String |
参数解释: 目录路径或通配符 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
|
actions |
否 |
Array of FilePushPermissionActionBodyDto objects |
参数解释: 事件设置列表。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
enable |
否 |
Boolean |
参数解释: 是否启用。 约束限制: 不涉及。 取值范围:
默认取值: 不涉及。 默认取值: true |
|
user_ids |
否 |
Array of objects |
参数解释: 用户ID列表。 约束限制: 不涉及。 取值范围: Integer 默认取值: 不涉及。 取值范围: 1~2147483647 |
|
user_team_ids |
否 |
Array of integers |
参数解释: 成员组ID列表。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 取值范围: 1~2147483647 |
|
related_role_ids |
否 |
Array of strings |
参数解释: 关联角色ID列表。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
|
action |
否 |
String |
参数解释: 事件名称。 约束限制: 不涉及。 取值范围:
默认取值: 不涉及。 |
响应参数
状态码:200
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
[数组元素] |
Array of RepositoryFilePushPermissionDto objects |
仓库文件推送权限列表 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
id |
Integer |
参数解释: 仓库文件推送权限ID。 取值范围: 1-2147483647 取值范围: 1~2147483647 |
|
path |
String |
参数解释: 目录路径或通配符。 取值范围: 不涉及。 |
|
actions |
Array of RepositoryProtectedActionDto objects |
参数解释: 事件列表。 取值范围: 不涉及。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
action |
String |
参数解释: 事件名称。 取值范围: 不涉及。 |
|
enable |
Boolean |
参数解释: 是否启用。 取值范围:
|
|
users |
Array of RepositoryUserDto objects |
参数解释: 白名单用户列表。 取值范围: 不涉及。 |
|
user_teams |
Array of UserTeamBasicDto objects |
参数解释: 白名单用户组列表。 取值范围: 不涉及。 |
|
roles |
Array of BasicRoleDto objects |
参数解释: 白名单角色列表。 取值范围: 不涉及。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
id |
Integer |
参数解释: 用户id。 取值范围: 1~2147483647 |
|
name |
String |
参数解释: 用户名称。 |
|
username |
String |
参数解释: 用户名。 |
|
state |
String |
参数解释: 用户状态。 取值范围:
|
|
avatar_url |
String |
参数解释: 头像地址。 取值范围: 不涉及。 |
|
nick_name |
String |
参数解释: 用户昵称。 取值范围: 不涉及。 |
|
tenant_name |
String |
参数解释: 所属租户名称。 取值范围: 不涉及。 |
请求示例
批量更新仓库文件推送权限
PUT /v4/repositories/123/file-push-permissions
{
"permissions" : [ {
"id" : 5,
"path" : "/config/*",
"actions" : [ {
"action" : "push",
"enable" : true,
"user_ids" : [ 9124 ],
"user_team_ids" : [ 247 ],
"related_role_ids" : [ "24f72d0b611746c3a43da596ea5065f5" ]
} ]
} ]
}
响应示例
状态码:200
仓库文件推送权限列表
[ {
"id" : 44,
"path" : "33",
"actions" : [ {
"action" : "push",
"enable" : true,
"users" : [ {
"id" : 7574,
"name" : "user",
"username" : "a618e34bd5704be3ae3395dfede06041",
"state" : "active",
"avatar_url" : "",
"nick_name" : "user",
"tenant_name" : "tenant"
} ],
"user_teams" : [ {
"id" : 247,
"name" : "team-1"
} ],
"roles" : [ {
"id" : 23836594,
"name" : "Project manager",
"related_role_id" : "6115a3ddd9044e288c558d1ae827a732",
"chinese_name" : "项目经理"
} ]
} ]
} ]
SDK代码示例
SDK代码示例如下。
Java
批量更新仓库文件推送权限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.codeartsrepo.v4.region.CodeArtsRepoRegion; import com.huaweicloud.sdk.codeartsrepo.v4.*; import com.huaweicloud.sdk.codeartsrepo.v4.model.*; import java.util.List; import java.util.ArrayList; public class BatchUpdateRepositoryFilePushPermissionsSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); CodeArtsRepoClient client = CodeArtsRepoClient.newBuilder() .withCredential(auth) .withRegion(CodeArtsRepoRegion.valueOf("<YOUR REGION>")) .build(); BatchUpdateRepositoryFilePushPermissionsRequest request = new BatchUpdateRepositoryFilePushPermissionsRequest(); request.withRepositoryId({repository_id}); BatchUpdateFilePushPermissionBodyDto body = new BatchUpdateFilePushPermissionBodyDto(); List<String> listActionsRelatedRoleIds = new ArrayList<>(); listActionsRelatedRoleIds.add("24f72d0b611746c3a43da596ea5065f5"); List<Integer> listActionsUserIds = new ArrayList<>(); listActionsUserIds.add(9124); List<Integer> listActionsUserTeamIds = new ArrayList<>(); listActionsUserTeamIds.add(247); List<FilePushPermissionActionBodyDto> listPermissionsActions = new ArrayList<>(); listPermissionsActions.add( new FilePushPermissionActionBodyDto() .withUserTeamIds(listActionsUserTeamIds) .withAction(FilePushPermissionActionBodyDto.ActionEnum.fromValue("push")) .withEnable(true) .withUserIds(listActionsUserIds) .withRelatedRoleIds(listActionsRelatedRoleIds) ); List<FilePushPermissionUpdateDto> listbodyPermissions = new ArrayList<>(); listbodyPermissions.add( new FilePushPermissionUpdateDto() .withId(5) .withPath("/config/*") .withActions(listPermissionsActions) ); body.withPermissions(listbodyPermissions); request.withBody(body); try { BatchUpdateRepositoryFilePushPermissionsResponse response = client.batchUpdateRepositoryFilePushPermissions(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Python
批量更新仓库文件推送权限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcodeartsrepo.v4.region.codeartsrepo_region import CodeArtsRepoRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcodeartsrepo.v4 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] credentials = BasicCredentials(ak, sk) client = CodeArtsRepoClient.new_builder() \ .with_credentials(credentials) \ .with_region(CodeArtsRepoRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchUpdateRepositoryFilePushPermissionsRequest() request.repository_id = {repository_id} listRelatedRoleIdsActions = [ "24f72d0b611746c3a43da596ea5065f5" ] listUserIdsActions = [ 9124 ] listUserTeamIdsActions = [ 247 ] listActionsPermissions = [ FilePushPermissionActionBodyDto( user_team_ids=listUserTeamIdsActions, action="push", enable=True, user_ids=listUserIdsActions, related_role_ids=listRelatedRoleIdsActions ) ] listPermissionsbody = [ FilePushPermissionUpdateDto( id=5, path="/config/*", actions=listActionsPermissions ) ] request.body = BatchUpdateFilePushPermissionBodyDto( permissions=listPermissionsbody ) response = client.batch_update_repository_file_push_permissions(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
批量更新仓库文件推送权限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" codeartsrepo "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartsrepo/v4" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartsrepo/v4/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartsrepo/v4/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := codeartsrepo.NewCodeArtsRepoClient( codeartsrepo.CodeArtsRepoClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchUpdateRepositoryFilePushPermissionsRequest{} request.RepositoryId = int32({repository_id}) var listRelatedRoleIdsActions = []string{ "24f72d0b611746c3a43da596ea5065f5", } var listUserIdsActions = []int32{ int32(9124), } var listUserTeamIdsActions = []int32{ int32(247), } actionActions:= model.GetFilePushPermissionActionBodyDtoActionEnum().PUSH enableActions:= true var listActionsPermissions = []model.FilePushPermissionActionBodyDto{ { UserTeamIds: &listUserTeamIdsActions, Action: &actionActions, Enable: &enableActions, UserIds: &listUserIdsActions, RelatedRoleIds: &listRelatedRoleIdsActions, }, } idPermissions:= int32(5) pathPermissions:= "/config/*" var listPermissionsbody = []model.FilePushPermissionUpdateDto{ { Id: &idPermissions, Path: &pathPermissions, Actions: &listActionsPermissions, }, } request.Body = &model.BatchUpdateFilePushPermissionBodyDto{ Permissions: &listPermissionsbody, } response, err := client.BatchUpdateRepositoryFilePushPermissions(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
|
状态码 |
描述 |
|---|---|
|
200 |
仓库文件推送权限列表 |
错误码
请参见错误码。