文档中心 对象存储(KS3) SDK Java 向量存储空间 管理向量空间策略

管理向量空间策略

最近更新时间:2026-11-06 11:32:55

设置向量空间策略

/**
 * 设置向量桶 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();
    }
}
上一篇:管理向量
下一篇:视频处理(Java)
以上内容是否对您有帮助?
有帮助
没帮助