华为云用户手册

  • 代码示例 本示例用于获取名为examplebucket桶下example/objectname对象的ACL权限控制列表信息 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 package main import ( "fmt" "os" obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" ) func main() { //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。 //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html。 ak := os.Getenv("AccessKeyID") sk := os.Getenv("SecretAccessKey") // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。 // securityToken := os.Getenv("SecurityToken") // endpoint填写Bucket对应的Endpoint, 这里以华北-北京四为例,其他地区请按实际情况填写。 endPoint := "https://obs.cn-north-4.myhuaweicloud.com" // 创建obsClient实例 // 如果使用临时AKSK和SecurityToken访问OBS,需要在创建实例时通过obs.WithSecurityToken方法指定securityToken值。 obsClient, err := obs.New(ak, sk, endPoint/*, obs.WithSecurityToken(securityToken)*/) if err != nil { fmt.Printf("Create obsClient error, errMsg: %s", err.Error()) } input := &obs.GetObjectAclInput{} // 指定存储桶名称 input.Bucket = "examplebucket" // 指定对象,此处以 example/objectname 为例。 input.Key = "example/objectname" // 获取对象ACL output, err := obsClient.GetObjectAcl(input) if err == nil { fmt.Printf("Get object(%s)'s acl successful with bucket(%s)!\n", input.Key, input.Bucket) fmt.Printf("Owner.ID:%s\n", output.Owner.ID) for index, grant := range output.Grants { fmt.Printf("Grant[%d]-Type:%s, ID:%s, URI:%s, Permission:%s\n", index, grant.Grantee.Type, grant.Grantee.ID, grant.Grantee.URI, grant.Permission) } return } fmt.Printf("Get object(%s)'s acl fail with bucket(%s)!\n", input.Key, input.Bucket) if obsError, ok := err.(obs.ObsError); ok { fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.") fmt.Println(obsError.Error()) } else { fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.") fmt.Println(err) } } 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 package main import ( "fmt" "os" obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" ) func main() { //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。 //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html。 ak := os.Getenv("AccessKeyID") sk := os.Getenv("SecretAccessKey") // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。 // securityToken := os.Getenv("SecurityToken") // endpoint填写Bucket对应的Endpoint, 这里以华北-北京四为例,其他地区请按实际情况填写。 endPoint := "https://obs.cn-north-4.myhuaweicloud.com" // 创建obsClient实例 // 如果使用临时AKSK和SecurityToken访问OBS,需要在创建实例时通过obs.WithSecurityToken方法指定securityToken值。 obsClient, err := obs.New(ak, sk, endPoint/*, obs.WithSecurityToken(securityToken)*/) if err != nil { fmt.Printf("Create obsClient error, errMsg: %s", err.Error()) } input := &obs.GetObjectAclInput{} // 指定存储桶名称 input.Bucket = "examplebucket" // 指定对象,此处以 example/objectname 为例。 input.Key = "example/objectname" // 获取对象ACL output, err := obsClient.GetObjectAcl(input) if err == nil { fmt.Printf("Get object(%s)'s acl successful with bucket(%s)!\n", input.Key, input.Bucket) fmt.Printf("Owner.ID:%s\n", output.Owner.ID) for index, grant := range output.Grants { fmt.Printf("Grant[%d]-Type:%s, ID:%s, URI:%s, Permission:%s\n", index, grant.Grantee.Type, grant.Grantee.ID, grant.Grantee.URI, grant.Permission) } return } fmt.Printf("Get object(%s)'s acl fail with bucket(%s)!\n", input.Key, input.Bucket) if obsError, ok := err.(obs.ObsError); ok { fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.") fmt.Println(obsError.Error()) } else { fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.") fmt.Println(err) } }
  • 返回结果说明 表3 返回结果 参数名称 参数类型 描述 output *GetObjectAclOutput 参数解释: 接口返回信息,GetObjectAclOutput。 err error 参数解释: 接口返回错误信息。 表4 GetObjectAclOutput 参数名称 参数类型 描述 StatusCode int 参数解释: HTTP状态码。 取值范围: 状态码是一组从2xx(成功)到4xx或5xx(错误)的数字代码,状态码表示了请求响应的状态。完整的状态码列表请参见状态码。 默认取值: 无 RequestId string 参数解释: OBS服务端返回的请求ID。 默认取值: 无 ResponseHeaders map[string][]string 参数解释: HTTP响应头信息。 默认取值: 无 VersionId string 参数解释: 对象的版本号。例如:G001117FCE89978B0000401205D5DC9A。 取值范围: 长度为32的字符串。 默认取值: 无 Owner Owner 参数解释: 对象的所有者帐号户ID,详见Owner。 约束限制: Owner和Grants必须配套使用,且与ACL互斥。 Grants []Grant 参数解释: 被授权用户权限信息,详livered见Grant。 默认取值: 无 表5 Owner 参数名称 参数类型 是否必选 描述 ID string 作为请求参数时必选 参数解释: 所有者的帐号ID,即domain_id。 取值范围: 如何获取帐号ID请参见如何获取帐号ID和用户ID? 默认取值: 无 表6 Grant 参数名称 参数类型 是否必选 描述 Grantee Grantee 作为请求参数时必选 参数解释: 被授权用户相关信息,详见Grantee。 Permission PermissionType 作为请求参数时必选 参数解释: 被授予的权限。 取值范围: 权限取值范围详见PermissionType。 默认取值: 无 表7 Grantee 参数名称 参数类型 是否必选 描述 Type GranteeType 作为请求参数时必选 参数解释: 被授权用户的类型,详见GranteeType。 ID string 作为请求参数时,如果Type为用户类型则必选。 参数解释: 被授权用户的帐号ID,即domain_id。 取值范围: 如何获取帐号ID请参见如何获取帐号ID和用户ID? 默认取值: 无 DisplayName string 作为请求参数时可选 参数解释: 被授权用户的帐号名。 约束限制: 不支持中文。 只能以字母开头。 长度为6-32个字符。 只能包含英文字母、数字或特殊字符(-_)。 默认取值: 无 URI GroupUriType 作为请求参数时,如果Type为用户组类型则必选。 参数解释: 被授权的用户组。 取值范围: 授权用户组取值范围详见GroupUriType。 默认取值: 无 表8 PermissionType 常量名 原始值 说明 PermissionRead READ 读权限。 PermissionWrite WRITE 写权限。 PermissionReadAcp READ_ACP 读取ACL配置的权限。 PermissionWriteAcp WRITE_ACP 修改ACL配置的权限。 PermissionFullControl FULL_CONTROL 完全控制权限,包括对桶或对象的读写权限,以及对桶或对象ACL配置的读写权限。 表9 GranteeType 常量名 原始值 说明 GranteeGroup Group 用户组。 GranteeUser CanonicalUser 单个用户。 表10 GroupUriType 常量名 原始值 说明 GroupAllUsers AllUsers 所有用户。
  • 接口约束 您必须是桶拥有者或拥有获取对象ACL的权限,才能获取对象ACL。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:object:GetObjectAcl权限,如果使用桶策略则需授予GetObjectAcl权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、配置对象策略。 OBS支持的Region与Endpoint的对应关系,详细信息请参见地区与终端节点。 用户必须拥有对指定对象读ACP(access control policy)的权限,才能执行获取对象ACL的操作。
  • 请求参数说明 表1 请求参数列表 参数名称 参数类型 是否必选 描述 input *GetObjectAclInput 必选 参数解释: 获取对象ACL请求参数,详情参考GetObjectAclInput。 extensions extensionOptions 可选 参数解释: 拓展配置项。通过调用拓展配置项为对应请求配置额外的拓展请求头,详情参考extensionOptions。 表2 GetObjectAclInput 参数名称 参数类型 是否必选 描述 Bucket string 必选 桶名。 Key string 必选 参数解释: 对象名。对象名是对象在存储桶中的唯一标识。对象名是对象在桶中的完整路径,路径中不包含桶名。 例如,您对象的访问地址为examplebucket.obs.cn-north-4. myhuaweicloud.com/folder/test.txt 中,对象名为folder/test.txt。 取值范围: 长度大于0且不超过1024的字符串。 默认取值: 无 VersionId string 可选 对象的版本号。例如:G001117FCE89978B0000401205D5DC9A。 默认值:无
  • 代码示例 本示例用于配置名为examplebucket桶的网站信息。 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 package main import ( "fmt" "os" obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" ) func main() { //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。 //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html。 ak := os.Getenv("AccessKeyID") sk := os.Getenv("SecretAccessKey") // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。 securityToken := os.Getenv("SecurityToken") // endpoint填写Bucket对应的Endpoint, 这里以华北-北京四为例,其他地区请按实际情况填写。 endPoint := "https://obs.cn-north-4.myhuaweicloud.com" // 创建obsClient实例 // 如果使用临时AKSK和SecurityToken访问OBS,需要在创建实例时通过obs.WithSecurityToken方法指定securityToken值。 obsClient, err := obs.New(ak, sk, endPoint, obs.WithSecurityToken(securityToken)) if err != nil { fmt.Printf("Create obsClient error, errMsg: %s", err.Error()) } input := &obs.SetBucketWebsiteConfigurationInput{} // 指定存储桶名称 input.Bucket = "examplebucket" // 指定默认页面配置,此处以index.html为例,含义是请求examplebucket/images/时,返回的数据将是samplebucket桶内名为images/index.html的对象的内容 input.IndexDocument.Suffix = "index.html" // 指定错误页面配置,此处以error.html为例 input.ErrorDocument.Key = "error.html" // 指定请求重定向规则列表 input.RoutingRules = []obs.RoutingRule{ {Redirect: obs.Redirect{HostName: "www.a.com", Protocol: obs.ProtocolHttp, ReplaceKeyPrefixWith: "prefix", HttpRedirectCode: "304"}}, {Redirect: obs.Redirect{HostName: "www.b.com", Protocol: obs.ProtocolHttps, ReplaceKeyWith: "replaceKey", HttpRedirectCode: "304"}}, } // 设置桶的Website配置 output, err := obsClient.SetBucketWebsiteConfiguration(input) if err == nil { fmt.Printf("Set bucket(%s)'s website successful!\n", input.Bucket) fmt.Printf("RequestId:%s\n", output.RequestId) return } fmt.Printf("Set bucket(%s)'s website fail!\n", input.Bucket) if obsError, ok := err.(obs.ObsError); ok { fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.") fmt.Println(obsError.Error()) } else { fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.") fmt.Println(err) } }
  • 接口约束 尽量避免目标桶名中带有“.”,否则通过HTTPS访问时可能出现客户端校验证书出错。 设置桶的网站配置请求消息体的上限是10KB。 您必须是桶拥有者或拥有设置桶的网站配置的权限,才能设置桶的网站配置。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:bucket:PutBucketWebsite权限,如果使用桶策略则需授予PutBucketWebsite权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、自定义创建桶策略。 OBS支持的Region与Endpoint的对应关系,详细信息请参见地区与终端节点。
  • 请求参数说明 表1 请求参数列表 参数名称 参数类型 是否必选 描述 input *SetBucketWebsiteConfigurationInput 必选 参数解释: 设置桶的网站配置请求参数,详见SetBucketWebsiteConfigurationInput。 extensions extensionOptions 可选 参数解释: 桶相关扩展信息。通过调用拓展配置项为对应请求配置额外的拓展请求头,详情参考extensionOptions。
  • 返回结果说明 表10 返回结果列表 参数名称 参数类型 描述 output *BaseModel 参数解释: 接口返回信息,详见BaseModel。 err error 参数解释: 接口返回错误信息。 表11 BaseModel 参数名称 参数类型 描述 StatusCode int 参数解释: HTTP状态码。 取值范围: 状态码是一组从2xx(成功)到4xx或5xx(错误)的数字代码,状态码表示了请求响应的状态。完整的状态码列表请参见状态码。 默认取值: 无 RequestId string 参数解释: OBS服务端返回的请求ID。 默认取值: 无 ResponseHeaders map[string][]string 参数解释: HTTP响应头信息。 默认取值: 无
  • 接口约束 您必须是桶拥有者或拥有获取桶加密配置的权限,才能获取桶加密配置。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:bucket:GetEncryptionConfiguration权限,如果使用桶策略则需授予GetEncryptionConfiguration权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、自定义创建桶策略。 OBS支持的Region与Endpoint的对应关系,详细信息请参见地区与终端节点。
  • 请求参数说明 表1 请求参数列表 参数名称 参数类型 是否必选 描述 bucketName string 必选 参数解释: 桶名。 约束限制: 桶的名字需全局唯一,不能与已有的任何桶名称重复,包括其他用户创建的桶。 桶命名规则如下: 3~63个字符,数字或字母开头,支持小写字母、数字、“-”、“.”。 禁止使用IP地址。 禁止以“-”或“.”开头及结尾。 禁止两个“.”相邻(如:“my..bucket”)。 禁止“.”和“-”相邻(如:“my-.bucket”和“my.-bucket”)。 同一用户在同一个区域多次创建同名桶不会报错,创建的桶属性以第一次请求为准。 取值范围: 长度为3~63个字符。 extensions extensionOptions 可选 参数解释: 桶相关扩展信息。通过调用拓展配置项为对应请求配置额外的拓展请求头,详情参考extensionOptions。
  • 代码示例 本示例用于获取名为examplebucket桶的加密配置 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 package main import ( "fmt" "os" obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" ) func main() { //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。 //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html。 ak := os.Getenv("AccessKeyID") sk := os.Getenv("SecretAccessKey") // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。 // securityToken := os.Getenv("SecurityToken") // endpoint填写Bucket对应的Endpoint, 这里以华北-北京四为例,其他地区请按实际情况填写。 endPoint := "https://obs.cn-north-4.myhuaweicloud.com" // 创建obsClient实例 // 如果使用临时AKSK和SecurityToken访问OBS,需要在创建实例时通过obs.WithSecurityToken方法指定securityToken值。 obsClient, err := obs.New(ak, sk, endPoint/*, obs.WithSecurityToken(securityToken)*/) if err != nil { fmt.Printf("Create obsClient error, errMsg: %s", err.Error()) } // 指定存储桶名称 bucketname := "examplebucket" // 获取桶加密配置 output, err := obsClient.GetBucketEncryption(bucketname) if err == nil { fmt.Printf("Get bucket(%s)'s encryption configuration successful!\n", bucketname) fmt.Printf("RequestId:%s\n", output.RequestId) fmt.Printf("Encryption:%s\n", output.SSEAlgorithm) fmt.Printf("KeyID:%s\n", output.KMSMasterKeyID) return } fmt.Printf("Get bucket(%s)'s encryption configuration fail!\n", bucketname) if obsError, ok := err.(obs.ObsError); ok { fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.") fmt.Println(obsError.Error()) } else { fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.") fmt.Println(err) } }
  • 返回结果说明 表2 返回结果列表 参数名称 参数类型 描述 output *GetBucketEncryptionOutput 参数解释: 接口返回信息,详情参考GetBucketEncryptionOutput。 err error 参数解释: 接口返回错误信息。 表3 GetBucketEncryptionOutput 参数名称 参数类型 描述 StatusCode int 参数解释: HTTP状态码。 取值范围: 状态码是一组从2xx(成功)到4xx或5xx(错误)的数字代码,状态码表示了请求响应的状态。完整的状态码列表请参见状态码。 默认取值: 无 RequestId string 参数解释: OBS服务端返回的请求ID。 默认取值: 无 ResponseHeaders map[string][]string 参数解释: HTTP响应头信息。 默认取值: 无 SSEAlgorithm string 参数解释: 表示服务端加密是SSE-KMS方式。对象使用SSE-KMS方式加密。 取值范围: 可选值:kms,即选择SSE-KMS方式加密对象。 默认取值: 无 KMSMasterKeyID string 参数解释: SSE-KMS加密方式下使用的KMS主密钥ID。 取值范围: 有效值支持两种格式: regionID:domainID(帐号ID):key/key_id key_id 其中: regionID是使用密钥所属region的ID,可在地区和终端节点页面获取; domainID是使用密钥所属帐号的帐号ID,获取方法参见如何获取帐号ID和用户ID?; key_id是从数据加密服务创建的密钥ID,获取方法请参见查看密钥。 默认取值: 如果用户没有提供该头域,那么默认的主密钥将会被使用。 ProjectID string 参数解释: SSE-KMS加密方式下KMS主密钥所属的项目ID。 约束限制: 项目ID需要与KMSMasterKeyID相匹配。 在未设置KMSMasterKeyID的情况下,不可设置项目ID。 取值范围: 项目ID获取方式请参见如何获取项目ID。 默认取值: 无
  • 请求参数说明 表1 请求参数列表 参数名称 参数类型 是否必选 描述 input *GetBucketMetadataInput 必选 参数解释: 获取桶元数据请求参数,详情参考GetBucketMetadataInput。 extensions extensionOptions 可选 参数解释: 桶相关扩展信息。通过调用拓展配置项为对应请求配置额外的拓展请求头,详情参考extensionOptions。
  • 接口约束 您必须是桶拥有者或拥有获取桶元数据的权限,才能获取桶元数据。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:bucket:HeadBucket权限,如果使用桶策略则需授予HeadBucket权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、自定义创建桶策略。 OBS支持的Region与Endpoint的对应关系,详细信息请参见地区与终端节点。
  • 代码示例 本示例用于获取名为examplebucket桶的元数据信息 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 package main import ( "fmt" "os" obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" ) func main() { //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。 //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html。 ak := os.Getenv("AccessKeyID") sk := os.Getenv("SecretAccessKey") // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。 // securityToken := os.Getenv("SecurityToken") // endpoint填写Bucket对应的Endpoint, 这里以华北-北京四为例,其他地区请按实际情况填写。 endPoint := "https://obs.cn-north-4.myhuaweicloud.com" // 创建obsClient实例 // 如果使用临时AKSK和SecurityToken访问OBS,需要在创建实例时通过obs.WithSecurityToken方法指定securityToken值。 obsClient, err := obs.New(ak, sk, endPoint/*, obs.WithSecurityToken(securityToken)*/) if err != nil { fmt.Printf("Create obsClient error, errMsg: %s", err.Error()) } input := &obs.GetBucketMetadataInput{} // 指定存储桶名称 input.Bucket = "examplebucket" // 获取桶元数据信息 output, err := obsClient.GetBucketMetadata(input) if err == nil { fmt.Printf("Get bucket(%s)'s metadata successful!\n", input.Bucket) fmt.Printf("RequestId:%s\n", output.RequestId) fmt.Printf("StorageClass:%s\n", output.StorageClass) fmt.Printf("Location:%s\n", output.Location) fmt.Printf("AZRedundancy:%s\n", output.AZRedundancy) fmt.Printf("Epid:%s\n", output.Epid) return } fmt.Printf("Get bucket(%s)'s metadata fail!\n", input.Bucket) if obsError, ok := err.(obs.ObsError); ok { fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.") fmt.Println(obsError.Error()) } else { fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.") fmt.Println(err) } }
  • 请求参数说明 表1 请求参数列表 参数名称 参数类型 是否必选 描述 bucketName string 必选 参数解释: 桶名。 约束限制: 桶的名字需全局唯一,不能与已有的任何桶名称重复,包括其他用户创建的桶。 桶命名规则如下: 3~63个字符,数字或字母开头,支持小写字母、数字、“-”、“.”。 禁止使用IP地址。 禁止以“-”或“.”开头及结尾。 禁止两个“.”相邻(如:“my..bucket”)。 禁止“.”和“-”相邻(如:“my-.bucket”和“my.-bucket”)。 同一用户在同一个区域多次创建同名桶不会报错,创建的桶属性以第一次请求为准。 默认取值: 无 extensions extensionOptions 可选 参数解释: 桶相关扩展信息。通过调用拓展配置项为对应请求配置额外的拓展请求头,详情参考extensionOptions。
  • 代码示例 本示例用于获取名为examplebucket桶的网站配置信息 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 package main import ( "fmt" "os" obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" ) func main() { //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。 //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html。 ak := os.Getenv("AccessKeyID") sk := os.Getenv("SecretAccessKey") // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。 // securityToken := os.Getenv("SecurityToken") // endpoint填写Bucket对应的Endpoint, 这里以华北-北京四为例,其他地区请按实际情况填写。 endPoint := "https://obs.cn-north-4.myhuaweicloud.com" // 创建obsClient实例 // 如果使用临时AKSK和SecurityToken访问OBS,需要在创建实例时通过obs.WithSecurityToken方法指定securityToken值。 obsClient, err := obs.New(ak, sk, endPoint/*, obs.WithSecurityToken(securityToken)*/) if err != nil { fmt.Printf("Create obsClient error, errMsg: %s", err.Error()) } // 指定存储桶名称 bucketname := "examplebucket" // 获取桶的网站配置 output, err := obsClient.GetBucketWebsiteConfiguration(bucketname) if err == nil { fmt.Printf("Get bucket(%s)'s website configuration successful!\n", bucketname) fmt.Printf("Get bucket metadata successful!\n") fmt.Printf("RequestId:%s\n", output.RequestId) fmt.Printf("Suffix:%s\n", output.IndexDocument.Suffix) fmt.Printf("Key:%s\n", output.ErrorDocument.Key) for index, routingRule := range output.RoutingRules { fmt.Printf("Condition[%d]-KeyPrefixEquals:%s, HttpErrorCodeReturnedEquals:%s\n", index, routingRule.Condition.KeyPrefixEquals, routingRule.Condition.HttpErrorCodeReturnedEquals) fmt.Printf("Redirect[%d]-Protocol:%s, HostName:%s, ReplaceKeyPrefixWith:%s, HttpRedirectCode:%s\n", index, routingRule.Redirect.Protocol, routingRule.Redirect.HostName, routingRule.Redirect.ReplaceKeyPrefixWith, routingRule.Redirect.HttpRedirectCode) } return } fmt.Printf("Get bucket(%s)'s website configuration fail!\n", bucketname) if obsError, ok := err.(obs.ObsError); ok { fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.") fmt.Println(obsError.Error()) } else { fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.") fmt.Println(err) } }
  • 接口约束 您必须是桶拥有者或拥有获取桶的网站配置的权限,才能获取桶的网站配置。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:bucket:GetBucketWebsite权限,如果使用桶策略则需授予GetBucketWebsite权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、自定义创建桶策略。 OBS支持的Region与Endpoint的对应关系,详细信息请参见地区与终端节点。
  • 参数描述 字段名 类型 约束 说明 option 请求桶的上下文,配置option 必选 桶参数。 key char * 必选 对象名。 upload_file_config obs_upload_file_configuration * 必选 上传文件的配置说明,请参看下表。 encryption_params server_side_encryption_params * 可选 上传对象加密设置。 handler obs_upload_file_response_handler * 必选 回调结构体,所有成员都是回调函数的指针。 callback_data void * 可选 回调数据。
  • 概述 欢迎使用云审计服务(Cloud Trace Service,以下简称CTS),CTS是云安全解决方案中专业的日志审计服务,提供对各种云资源操作记录的收集、存储和查询功能,可用于支撑安全分析、合规审计、资源跟踪和问题定位等常见应用场景。 您可以使用本文档提供API对云审计服务进行相关操作,如创建、删除追踪器等。在调用云审计服务的API之前,请确保已经充分了解云审计服务的相关概念与功能。 父主题: 使用前必读
  • URI DELETE /v1.0/{project_id}/tracker 表1 路径参数 参数 是否必选 参数类型 描述 project_id 是 String 项目ID,获取方法请参见获取项目ID。 表2 Query参数 参数 是否必选 参数类型 描述 tracker_name 是 String 标识追踪器名称。 在不传入该字段的情况下,将删除当前租户所有的追踪器。 当前版本单租户仅支持一个追踪器,名称默认为“system”。
  • 基本概念 追踪器 使用云审计服务前需要开通云审计服务,开通云审计服务时系统会自动创建一个追踪器。该追踪器会自动识别并关联当前租户所使用的所有云服务,并将当前租户的所有操作记录在该追踪器中。 目前,一个租户仅支持创建1个管理追踪器和100个数据追踪器。 事件 事件即云审计服务追踪并保存的云服务资源的操作日志。您可以通过“事件”了解到谁在什么时间对系统哪些资源做了什么操作。 事件分为以下两类:管理类事件和数据类事件,管理类事件指云服务上报的事件,数据类事件指OBS服务上报的读写操作事件。 账号 用户注册时的账号,账号对其所拥有的资源及云服务具有完全的访问权限,可以重置用户密码、分配用户权限等。由于账号是付费主体,为了确保账号安全,建议您不要直接使用账号进行日常管理工作,而是创建用户并使用该用户进行日常管理工作。 用户 由账号在IAM中创建的用户,是云服务的使用人员,具有身份凭证(密码和访问密钥)。 在我的凭证下,您可以查看账号ID和IAM用户ID。通常在调用API的鉴权过程中,您需要用到账号、用户和密码等信息。 区域(Region) 从地理位置和网络时延维度划分,同一个Region内共享弹性计算、块存储、对象存储、VPC网络、弹性公网IP、镜像等公共服务。Region分为通用Region和专属Region,通用Region指面向公共租户提供通用云服务的Region;专属Region指只承载同一类业务或只面向特定租户提供业务服务的专用Region。 详情请参见区域和可用区。 可用区(AZ,Availability Zone) 一个可用区是一个或多个物理数据中心的集合,有独立的风火水电,AZ内逻辑上再将计算、网络、存储等资源划分成多个集群。一个Region中的多个AZ间通过高速光纤相连,以满足用户跨AZ构建高可用性系统的需求。 项目 区域默认对应一个项目,这个项目由系统预置,用来隔离物理区域间的资源(计算资源、存储资源和网络资源),以默认项目为单位进行授权,用户可以访问您账号中该区域的所有资源。如果您希望进行更加精细的权限控制,可以在区域默认的项目中创建子项目,并在子项目中创建资源,然后以子项目为单位进行授权,使得用户仅能访问特定子项目中资源,使得资源的权限控制更加精确。 图1 项目隔离模型 同样在我的凭证下,您可以查看项目ID。 企业项目 企业项目是项目的升级版,针对企业不同项目间资源的分组和管理,是逻辑隔离。企业项目中可以包含多个区域的资源,且项目中的资源可以迁入迁出。 关于企业项目ID的获取及企业项目特性的详细信息,请参见《企业管理用户指南》。 父主题: 使用前必读
  • 响应参数 状态码: 200 表3 响应Body参数 参数 参数类型 描述 trackers Array of TrackerResponseBody objects 本次查询追踪器列表返回的追踪器数组。 表4 TrackerResponseBody 参数 参数类型 描述 id String 追踪器唯一标识。 create_time Long 追踪器创建时间戳。 kms_id String 事件文件转储加密所采用的秘钥id(从KMS获取)。当"tracker_type"参数值为"system"和"is_support_trace_files_encryption"参数值为“是”时,此参数为必选项。 is_support_validate Boolean 是否打开事件文件校验。 lts Lts object 事件分析 tracker_type String 标识追踪器类型。 目前支持系统追踪器类型有管理类追踪器(system)和数据类追踪器(data)。 枚举值: system data domain_id String 账号ID,参见《云审计服务API参考》“获取账号ID和项目ID”章节。 project_id String 项目ID。 tracker_name String 标识追踪器名称,当前版本默认为“system”。 status String 标识追踪器状态,包括正常(enabled),停止(disabled)和异常(error)三种状态,状态为异常时需通过明细(detail)字段说明错误来源。 枚举值: enabled disabled detail String 该参数仅在追踪器状态异常时返回,用于标识追踪器异常的原因,包括桶策略异常(bucketPolicyError),桶不存在(noBucket)和欠费或冻结(arrears)三种原因。 is_support_trace_files_encryption Boolean 事件文件转储加密功能开关。 该参数必须与kms_id参数同时使用。 当前环境仅"tracker_type"参数值为"system"时支持该功能。 obs_info ObsInfo object 事件转储桶信息。 data_bucket DataBucketQuery object 数据类事件追踪桶信息。 当"tracker_type"参数值为"data"时有效。 group_id String LTS服务日志组的ID。 stream_id String LTS服务日志流的ID。 is_organization_tracker Boolean 是否应用到我的组织。 只针对管理类追踪器。设置为true时,ORG组织下所有成员当前区域的审计日志会转储到该追踪器配置的OBS桶或者LTS日志流,但是事件列表界面不支持查看其它组织成员的审计日志。 management_event_selector ManagementEventSelector object 管理类事件选择器。 表5 Lts 参数 参数类型 描述 is_lts_enabled Boolean 是否启用日志服务检索功能。 log_group_name String 云审计服务在日志服务中创建的日志组名称。 log_topic_name String 云审计服务在日志服务中创建的日志主题名称。 表6 ObsInfo 参数 参数类型 描述 bucket_name String 标识OBS桶名称。由数字或字母开头,支持小写字母、数字、“-”、“.”,长度为3~63个字符。 file_prefix_name String 标识需要存储于OBS的日志文件前缀,0-9,a-z,A-Z,'-','.','_'长度为0~64字符。 is_obs_created Boolean 标识配置桶是否由追踪器自动创建。 is_authorized_bucket Boolean 标识配置桶是否已经授权给CTS服务账号。 bucket_lifecycle Long 标识配置桶内对象存储周期。 当"tracker_type"参数值为"data"时该参数值有效。 compress_type String 压缩类型。包括不压缩(json),压缩(gzip)两种状态。默认为gzip格式。 枚举值: gzip json is_sort_by_service Boolean 路径按云服务划分,打开后转储文件路径中将增加云服务名。默认为true。 表7 DataBucketQuery 参数 参数类型 描述 data_bucket_name String 标识OBS桶名称。由数字或字母开头,支持小写字母、数字、“-”、“.”,长度为3~63个字符。 search_enabled Boolean 追踪桶日志是否支持搜索。 data_event Array of strings 数据类追踪器追踪对象的桶名。 当启用或者停用数据类追踪器时,该参数为必选。 管理类追踪器无此参数。 追踪器一旦创建追踪桶无法修改。 READ OBS对象读取操作;WRITE OBS对象写操作。 枚举值: WRITE READ 表8 ManagementEventSelector 参数 参数类型 描述 exclude_service Array of strings 标识不转储的云服务名称。 目前只支持设置为KMS,表示屏蔽KMS服务的createDatakey事件。 状态码: 400 表9 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。 状态码: 401 表10 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。 状态码: 403 表11 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。 状态码: 500 表12 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。 状态码: 503 表13 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。
  • 响应示例 状态码: 200 请求成功。 { "trackers" : [ { "is_support_trace_files_encryption" : true, "create_time" : 1589886034121, "stream_id" : "4a1ef2b6-d79a-4dc6-90f0-48151cd5491b", "kms_id" : "7dbbb3fa-93e4-4528-bc7b-9beb794b0229", "group_id" : "26fa12ac-75f7-42ed-8118-ab9f2263042f", "is_support_validate" : false, "obs_info" : { "is_obs_created" : false, "bucket_name" : "", "is_authorized_bucket" : false, "file_prefix_name" : "", "bucket_lifecycle" : 0 }, "lts" : { "log_group_name" : "CTS", "is_lts_enabled" : true, "log_topic_name" : "system-trace" }, "tracker_type" : "system", "domain_id" : "2306579dc99f4c8690b14b68e734fcd9", "project_id" : "24edf66e79d04187acb99a463e610764", "tracker_name" : "system", "id" : "ebf8d1c3-762b-4ce3-b316-6b1aa32f8be3", "status" : "enabled" }, { "domain_id" : "2306579dc99f4c8690b14b68e734fcd9", "is_support_trace_files_encryption" : false, "obs_info" : { "is_obs_created" : false, "bucket_name" : "", "is_authorized_bucket" : false, "file_prefix_name" : "", "bucket_lifecycle" : 0 }, "create_time" : 1589276171198, "project_id" : "24edf66e79d04187acb99a463e610764", "data_bucket" : { "data_event" : [ "READ", "WRITE" ], "search_enabled" : false, "data_bucket_name" : "cstest0423" }, "tracker_name" : "sdsa", "is_support_validate" : false, "lts" : { "log_group_name" : "CTS", "is_lts_enabled" : false, "log_topic_name" : "sdsa" }, "id" : "c9a3961d-3aa0-4e60-8e63-dd4ce7f1a88a", "status" : "enabled", "tracker_type" : "data" } ] }
  • URI GET /v3/{project_id}/trackers 表1 路径参数 参数 是否必选 参数类型 描述 project_id 是 String 项目ID,参见获取账号ID和项目ID章节。 表2 Query参数 参数 是否必选 参数类型 描述 tracker_name 否 String 标示追踪器名称。 在不传入该字段的情况下,将查询租户所有的追踪器。 tracker_type 否 String 标识追踪器类型。 目前支持系统追踪器有管理类追踪器(system)和数据类追踪器(data)。 枚举值: system data
  • 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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcts.v3.region.cts_region import CtsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcts.v3 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.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = CtsClient.new_builder() \ .with_credentials(credentials) \ .with_region(CtsRegion.value_of("cn-north-4")) \ .build() try: request = ListQuotasRequest() response = client.list_quotas(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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/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 := cts.NewCtsClient( cts.CtsClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.ListQuotasRequest{} response, err := client.ListQuotas(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • 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 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.cts.v3.region.CtsRegion; import com.huaweicloud.sdk.cts.v3.*; import com.huaweicloud.sdk.cts.v3.model.*; public class ListQuotasSolution { 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); CtsClient client = CtsClient.newBuilder() .withCredential(auth) .withRegion(CtsRegion.valueOf("cn-north-4")) .build(); ListQuotasRequest request = new ListQuotasRequest(); try { ListQuotasResponse response = client.listQuotas(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()); } } }
  • 响应参数 状态码: 200 表2 响应Body参数 参数 参数类型 描述 resources Array of Quota objects 本次查询追踪器列表返回的追踪器数组。 表3 Quota 参数 参数类型 描述 type String quota资源类型。 used Long 已使用的资源个数。 quota Long 总资源个数。 状态码: 400 表4 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。 状态码: 401 表5 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。 状态码: 403 表6 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。 状态码: 404 表7 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。 状态码: 500 表8 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。 状态码: 503 表9 响应Body参数 参数 参数类型 描述 error_code String 错误码标识,CTS.XXX。 error_msg String 错误描述。
  • 响应示例 状态码: 200 请求成功。 { "resources" : [ { "service_type" : "CTS", "resource" : [ "trace", "notification", "tracker" ] }, { "service_type" : "AOM", "resource" : [ "xxxx1", "xxxx2" ] } ] }
共100000条