Feature Name | Description | Sample code |
PUT Bucket policy | Set the permission policy for the specified bucket. | |
GET Bucket policy | Query the permission policy for the specified bucket. | |
Deleting a Bucket Policy | Delete the permission policy for the specified bucket. |
public class AccessManageModel{private CosXml cosXml; //Set the service user as a data member// Initialize COS service instanceprivate void InitCosXml(){string region = Environment.GetEnvironmentVariable("COS_REGION");CosXmlConfig config = new CosXmlConfig.Builder().SetRegion(region) // Set default region. For abbreviations of COS regions, see https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1.Build();string secretId = Environment.GetEnvironmentVariable("SECRET_ID"); // Cloud API key SecretId, see https://console.tencentcloud.com/cam/capi to obtain API keystring secretKey = Environment.GetEnvironmentVariable("SECRET_KEY"); // cloud API key SecretKey, obtain API key see https://console.tencentcloud.com/cam/capilong durationSecond = 600; //Request signature valid duration for each request, in secondsQCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond);this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);}}
public void PutBucketPolicy(){string bucket = "examplebucket-1250000000";PutBucketPolicyRequest request = new PutBucketPolicyRequest(bucket);string policy = @"{""Statement"": [{""Action"": [""name/cos:PutBucketPolicy"",""name/cos:GetBucketPolicy"",""name/cos:DeleteBucketPolicy""],""Effect"": ""Allow"",""Principal"": {""qcs"": [""qcs::cam::uin/100000000001:uin/100000000002""]},""Resource"": [""qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*""]}],""Version"": ""2.0""}";request.SetBucketPolicy(policy);PutBucketPolicyResult result = cosXml.PutBucketPolicy(request);Console.WriteLine(result.GetResultInfo());}
Parameter Name | Description | Required |
Statement | Describe the detailed information of one or more permissions | Yes |
Version | Syntax version of a policy, which is 2.0 by default. | Yes |
Principal | Yes | |
Action | Here refers to the COS API. Specify a combination of one or a sequence of operations or all operations ( *) as required, for example, the action is name/cos:GetService. Please note that the case is case-sensitive. | Yes |
Effect | The options include allow (permission) and deny (explicit deny). | Yes |
Resource | Authorized data to be operated, which can be any resources, resources with a specified path prefix, resources with a specified absolute path, or resources with combinations of the above conditions. | Yes |
Condition | No |
public void GetBucketPolicy(){string bucket = "examplebucket-1250000000";GetBucketPolicyRequest request = new GetBucketPolicyRequest(bucket);GetBucketPolicyResult result = cosXml.GetBucketPolicy(request);Console.WriteLine(result.Data); //Return Data, in json formatConsole.WriteLine(result.GetResultInfo());}
public void DeleteBucketPolicy(){string bucket = "examplebucket-1250000000";DeleteBucketPolicyRequest request = new DeleteBucketPolicyRequest(bucket);DeleteBucketPolicyResult result = cosXml.DeleteBucketPolicy(request);Console.WriteLine(result.GetResultInfo());}
Feedback