最近更新时间:2026-11-05 15:15:23
/**
* 设置向量桶 Policy
*/
public void putVectorBucketPolicy() {
Ks3VectorsClient client = initVectorsClient();
String bucketName = "my-vector-bucket";
try {
// Policy JSON 字符串(SDK 只透传不解析):授权 uid 12345 的 user/bob 读写向量
String policy = "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Sid\":\"1\",\"Effect\":\"Allow\","
+ "\"Principal\":{\"KSC\":[\"krn:ksc:iam::12345:user/bob\"]},"
+ "\"Action\":[\"ks3:PutVectors\",\"ks3:GetVectors\"],"
+ "\"Resource\":[\"krn:ksc:ks3vectors:cn-beijing:11111:bucket/my-vector-bucket\"]}]}";
Ks3Result result = client.putVectorBucketPolicy(
new PutVectorBucketPolicyRequest(bucketName, policy));
System.out.println("设置 Policy 成功,requestId=" + result.getRequestId());
} catch (Ks3ServiceException e) {
System.out.println("Ks3ServiceException: " + e.getErrorMessage()
+ ", status=" + e.getStatusCode() + ", requestId=" + e.getRequestId());
} catch (Ks3ClientException e) {
System.out.println("Ks3ClientException: " + e.getMessage());
} finally {
client.shutdown();
}
}
/**
* 查询向量桶 Policy
*/
public void getVectorBucketPolicy() {
Ks3VectorsClient client = initVectorsClient();
String bucketName = "my-vector-bucket";
try {
GetVectorBucketPolicyResult result = client.getVectorBucketPolicy(
new GetVectorBucketPolicyRequest(bucketName));
System.out.println("Policy: " + result.getPolicy());
} catch (Ks3ServiceException e) {
System.out.println("Ks3ServiceException: " + e.getErrorMessage()
+ ", status=" + e.getStatusCode() + ", requestId=" + e.getRequestId());
} catch (Ks3ClientException e) {
System.out.println("Ks3ClientException: " + e.getMessage());
} finally {
client.shutdown();
}
}
/**
* 删除向量桶 Policy
*/
public void deleteVectorBucketPolicy() {
Ks3VectorsClient client = initVectorsClient();
String bucketName = "my-vector-bucket";
try {
Ks3Result result = client.deleteVectorBucketPolicy(
new DeleteVectorBucketPolicyRequest(bucketName));
System.out.println("删除 Policy 成功,requestId=" + result.getRequestId());
} catch (Ks3ServiceException e) {
System.out.println("Ks3ServiceException: " + e.getErrorMessage()
+ ", status=" + e.getStatusCode() + ", requestId=" + e.getRequestId());
} catch (Ks3ClientException e) {
System.out.println("Ks3ClientException: " + e.getMessage());
} finally {
client.shutdown();
}
}
纯净模式
