Skip to content

Commit

Permalink
Prettifier
Browse files Browse the repository at this point in the history
  • Loading branch information
gemanor committed Oct 28, 2024
1 parent 60f2f63 commit 2b51a74
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions source/commands/pdp/check.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ export const options = zod.object({
alias: 't',
}),
),
pdpurl: string().optional().describe(
option({
description: 'The URL of the PDP service. Default to the cloud PDP.',
}),
),
pdpurl: string()
.optional()
.describe(
option({
description: 'The URL of the PDP service. Default to the cloud PDP.',
}),
),
apiKey: zod
.string()
.optional()
Expand All @@ -63,25 +65,26 @@ export default function Check({ options }: Props) {
const [res, setRes] = React.useState<AllowedResult>({ allow: undefined });

const queryPDP = async (apiKey: string) => {
const response = await fetch(
`${options.pdpurl || CLOUD_PDP_URL}/allowed`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
},
body: JSON.stringify({
user: { key: options.user },
resource: {
type: options.resource.includes(':') ? options.resource.split(':')[0] : options.resource,
key: options.resource.includes(':') ? options.resource.split(':')[1] : '',
tenant: options.tenant
},
action: options.action,
}),
const response = await fetch(`${options.pdpurl || CLOUD_PDP_URL}/allowed`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
},
);
body: JSON.stringify({
user: { key: options.user },
resource: {
type: options.resource.includes(':')
? options.resource.split(':')[0]
: options.resource,
key: options.resource.includes(':')
? options.resource.split(':')[1]
: '',
tenant: options.tenant,
},
action: options.action,
}),
});

if (!response.ok) {
setError(await response.text());
Expand Down

0 comments on commit 2b51a74

Please sign in to comment.