全部文档
当前文档

暂无内容

如果没有找到您期望的内容,请尝试其他搜索词

文档中心

管理向量空间策略

最近更新时间: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();
    }
}
文档导读
纯净模式常规模式

纯净模式

点击可全屏预览文档内容
文档反馈