-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
174 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@bnb-chain/greenfield-js-sdk': patch | ||
--- | ||
|
||
feat: Add sp `ListObjectPolicies` API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/chain-sdk/src/clients/spclient/spApis/listObjectPolicies.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { convertStrToBool, formatObjectInfo } from '@/types/sp/Common'; | ||
import { | ||
GetListObjectPoliciesRequest, | ||
GetListObjectPoliciesResponse, | ||
} from '@/types/sp/ListObjectPolicies'; | ||
import { generateUrlByBucketName } from '@/utils'; | ||
import { actionTypeFromJSON } from '@bnb-chain/greenfield-cosmos-types/greenfield/permission/common'; | ||
import { XMLParser } from 'fast-xml-parser'; | ||
import { encodePath, getSortQueryParams } from '../auth'; | ||
|
||
export const getListObjectPoliciesMetaInfo = ( | ||
endpoint: string, | ||
params: GetListObjectPoliciesRequest, | ||
) => { | ||
const { actionType, bucketName, objectName, limit = '10', startAfter = '' } = params; | ||
const path = `/${encodePath(objectName)}`; | ||
const queryMap = { | ||
'object-policies': 'null', | ||
'start-after': startAfter, | ||
limit: String(limit), | ||
'action-type': String(actionTypeFromJSON(actionType)), | ||
}; | ||
|
||
let url = new URL(path, generateUrlByBucketName(endpoint, bucketName)); | ||
url = getSortQueryParams(url, queryMap); | ||
|
||
return { | ||
url: url.href, | ||
}; | ||
}; | ||
|
||
export const parseGetListObjectPoliciesResponse = (data: string) => { | ||
const xmlParser = new XMLParser({ | ||
parseTagValue: false, | ||
}); | ||
const res = xmlParser.parse(data) as GetListObjectPoliciesResponse; | ||
|
||
let Policies = res.GfSpListObjectPoliciesResponse.Policies || []; | ||
|
||
if (Policies) { | ||
if (!Array.isArray(Policies)) { | ||
Policies = [Policies]; | ||
} | ||
|
||
Policies = Policies.map((item) => { | ||
return { | ||
...item, | ||
PrincipalType: Number(item.ResourceType), | ||
ResourceType: Number(item.ResourceType), | ||
CreateTimestamp: Number(item.CreateTimestamp), | ||
UpdateTimestamp: Number(item.UpdateTimestamp), | ||
ExpirationTime: Number(item.ExpirationTime), | ||
}; | ||
}); | ||
} | ||
|
||
res.GfSpListObjectPoliciesResponse = { | ||
Policies, | ||
}; | ||
|
||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ActionType } from '@bnb-chain/greenfield-cosmos-types/greenfield/permission/common'; | ||
import { PolicyMeta } from './Common'; | ||
|
||
export type GetListObjectPoliciesRequest = { | ||
endpoint?: string; | ||
bucketName: string; | ||
objectName: string; | ||
actionType: keyof typeof ActionType; | ||
limit?: number; | ||
startAfter?: string; | ||
}; | ||
|
||
export type GetListObjectPoliciesResponse = { | ||
GfSpListObjectPoliciesResponse: GfSpListObjectPoliciesResponse; | ||
}; | ||
|
||
export interface GfSpListObjectPoliciesResponse { | ||
Policies: PolicyMeta[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters