Skip to content

Commit

Permalink
feat: Add Two Apis (#179)
Browse files Browse the repository at this point in the history
* feat: Add Two Apis

* Create mean-wombats-remain.md
  • Loading branch information
rrr523 authored Jul 24, 2023
1 parent 4d88665 commit dc87783
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/mean-wombats-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/greenfield-chain-sdk": patch
---

feat: Add `getObjectPolicy` and `isObjectPermissionAllowed`
42 changes: 41 additions & 1 deletion packages/chain-sdk/src/api/objectt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MsgUpdateObjectInfoSDKTypeEIP712 } from '@/messages/greenfield/storage/
import { getAuthorizationAuthTypeV2 } from '@/utils/auth';
import { fetchWithTimeout, METHOD_GET, METHOD_PUT, NORMAL_ERROR_CODE } from '@/utils/http';
import {
ActionType,
Principal,
PrincipalType,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/permission/common';
Expand All @@ -16,6 +17,8 @@ import {
QueryHeadObjectResponse,
QueryNFTRequest,
QueryObjectNFTResponse,
QueryPolicyForAccountResponse,
QueryVerifyPermissionResponse,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/query';
import {
MsgCancelCreateObject,
Expand Down Expand Up @@ -103,7 +106,18 @@ export interface IObject {
principalAddr: string,
): Promise<TxResponse>;

// TODO: IsObjectPermissionAllowed
isObjectPermissionAllowed(
bucketName: string,
objectName: string,
actionType: ActionType,
operator: string,
): Promise<QueryVerifyPermissionResponse>;

getObjectPolicy(
bucketName: string,
objectName: string,
principalAddr: string,
): Promise<QueryPolicyForAccountResponse>;
// TODO: GetObjectUploadProgress
// TODO: getObjectStatusFromSP
}
Expand Down Expand Up @@ -609,6 +623,32 @@ export class Objectt implements IObject {
return await this.storage.putPolicy(msg);
}

public async isObjectPermissionAllowed(
bucketName: string,
objectName: string,
actionType: ActionType,
operator: string,
) {
const rpc = await this.queryClient.getStorageQueryClient();
return await rpc.VerifyPermission({
bucketName,
objectName,
actionType,
operator,
});
}

public async getObjectPolicy(bucketName: string, objectName: string, principalAddr: string) {
const rpc = await this.queryClient.getStorageQueryClient();

const resource = GRNToString(newObjectGRN(bucketName, objectName));

return await rpc.QueryPolicyForAccount({
resource,
principalAddress: principalAddr,
});
}

public async deleteObjectPolicy(
operator: string,
bucketName: string,
Expand Down

0 comments on commit dc87783

Please sign in to comment.