Reworded and added missing parameter descriptions
Signed-off-by: Harry Hogg <hhogg@spotify.com>
This commit is contained in:
@@ -28,11 +28,13 @@ export const createPropertyRule = (propertyType: 'metadata' | 'spec') =>
|
||||
description: `Allow entities which have the specified ${propertyType} subfield.`,
|
||||
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
|
||||
schema: z.object({
|
||||
key: z.string().describe(`The key of the ${propertyType} to match on`),
|
||||
key: z
|
||||
.string()
|
||||
.describe(`Property within the entities ${propertyType} to match on`),
|
||||
value: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(`Optional value of the ${propertyType} to match on`),
|
||||
.describe(`Value of the given property to match on`),
|
||||
}),
|
||||
apply: (resource, { key, value }) => {
|
||||
const foundValue = get(resource[propertyType], key);
|
||||
|
||||
@@ -35,11 +35,11 @@ export const hasAnnotation = createCatalogPermissionRule<{
|
||||
'Allow entities which are annotated with the specified annotation',
|
||||
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
|
||||
schema: z.object({
|
||||
annotation: z.string().describe('The name of the annotation to match on'),
|
||||
annotation: z.string().describe('Name of the annotation to match on'),
|
||||
value: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Optional value of the annotation to match on'),
|
||||
.describe('Value of the annotation to match on'),
|
||||
}),
|
||||
apply: (resource, { annotation, value }) =>
|
||||
!!resource.metadata.annotations?.hasOwnProperty(annotation) &&
|
||||
|
||||
@@ -28,7 +28,7 @@ export const hasLabel = createCatalogPermissionRule({
|
||||
description: 'Allow entities which have the specified label metadata.',
|
||||
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
|
||||
schema: z.object({
|
||||
label: z.string().describe('Name of the label'),
|
||||
label: z.string().describe('Name of the label to match one'),
|
||||
}),
|
||||
apply: (resource, { label }) =>
|
||||
!!resource.metadata.labels?.hasOwnProperty(label),
|
||||
|
||||
@@ -28,7 +28,9 @@ export const isEntityKind = createCatalogPermissionRule({
|
||||
description: 'Allow entities with the specified kind',
|
||||
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
|
||||
schema: z.object({
|
||||
kinds: z.array(z.string()),
|
||||
kinds: z
|
||||
.array(z.string())
|
||||
.describe('List of kinds to match at least one of'),
|
||||
}),
|
||||
apply(resource, { kinds }) {
|
||||
const resourceKind = resource.kind.toLocaleLowerCase('en-US');
|
||||
|
||||
@@ -30,7 +30,11 @@ export const isEntityOwner = createCatalogPermissionRule({
|
||||
description: 'Allow entities owned by the current user',
|
||||
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
|
||||
schema: z.object({
|
||||
claims: z.array(z.string()),
|
||||
claims: z
|
||||
.array(z.string())
|
||||
.describe(
|
||||
`List of claims to match at least one on within ${RELATION_OWNED_BY}`,
|
||||
),
|
||||
}),
|
||||
apply: (resource, { claims }) => {
|
||||
if (!resource.relations) {
|
||||
|
||||
@@ -61,7 +61,7 @@ export type PermissionRule<
|
||||
// with an optional zod type.
|
||||
[P in keyof TParams]-?: TParams[P] extends undefined
|
||||
? z.ZodOptionalType<z.ZodType<TParams[P]>>
|
||||
: z.ZodType<TParams[P], any, any>;
|
||||
: z.ZodType<TParams[P]>;
|
||||
}>;
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,7 +36,7 @@ const isOwner = createPlaylistPermissionRule<{
|
||||
description: 'Should allow only if the playlist belongs to the user',
|
||||
resourceType: PLAYLIST_LIST_RESOURCE_TYPE,
|
||||
schema: z.object({
|
||||
owners: z.array(z.string().describe('List of owner entity refs')),
|
||||
owners: z.array(z.string()).describe('List of owner entity refs'),
|
||||
}),
|
||||
apply: (list: PlaylistMetadata, { owners }) => owners.includes(list.owner),
|
||||
toQuery: ({ owners }) => ({
|
||||
|
||||
Reference in New Issue
Block a user