Rename schema to paramsSchema

Signed-off-by: Harry Hogg <hhogg@spotify.com>
This commit is contained in:
Harry Hogg
2022-10-06 09:36:54 +01:00
parent 26e5513c32
commit db63ce8b07
17 changed files with 28 additions and 28 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ The API has now changed to expect the parameters as a single object
```ts
createPermissionRule({
schema: z.object({
paramSchema: z.object({
foo: z.string().describe('Foo value to match'),
bar: z.string().describe('Bar value to match'),
}),
@@ -24,7 +24,7 @@ export const createPropertyRule = (propertyType: 'metadata' | 'spec') =>
name: `HAS_${propertyType.toUpperCase()}`,
description: `Allow entities which have the specified ${propertyType} subfield.`,
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
schema: z.object({
paramsSchema: z.object({
key: z
.string()
.describe(`Property within the entities ${propertyType} to match on`),
@@ -31,7 +31,7 @@ export const hasAnnotation = createCatalogPermissionRule({
description:
'Allow entities which are annotated with the specified annotation',
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
schema: z.object({
paramsSchema: z.object({
annotation: z.string().describe('Name of the annotation to match on'),
value: z
.string()
@@ -27,7 +27,7 @@ export const hasLabel = createCatalogPermissionRule({
name: 'HAS_LABEL',
description: 'Allow entities which have the specified label metadata.',
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
schema: z.object({
paramsSchema: z.object({
label: z.string().describe('Name of the label to match one'),
}),
apply: (resource, { label }) =>
@@ -27,7 +27,7 @@ export const isEntityKind = createCatalogPermissionRule({
name: 'IS_ENTITY_KIND',
description: 'Allow entities with the specified kind',
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
schema: z.object({
paramsSchema: z.object({
kinds: z
.array(z.string())
.describe('List of kinds to match at least one of'),
@@ -29,7 +29,7 @@ export const isEntityOwner = createCatalogPermissionRule({
name: 'IS_ENTITY_OWNER',
description: 'Allow entities owned by the current user',
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
schema: z.object({
paramsSchema: z.object({
claims: z
.array(z.string())
.describe(
@@ -696,7 +696,7 @@ describe('NextRouter permissioning', () => {
name: 'FAKE_RULE',
description: 'fake rule',
resourceType: RESOURCE_TYPE_CATALOG_ENTITY,
schema: z.object({
paramsSchema: z.object({
foo: z.string(),
}),
apply: () => true,
@@ -284,7 +284,7 @@ describe('PermissionIntegrationClient', () => {
name: 'RULE_1',
description: 'Test rule 1',
resourceType: 'test-resource',
schema: z.object({
paramsSchema: z.object({
input: z.enum(['yes', 'no']),
}),
apply: (_resource, { input }) => input === 'yes',
@@ -297,7 +297,7 @@ describe('PermissionIntegrationClient', () => {
description: 'Test rule 2',
resourceType: 'test-resource',
schema: z.object({
paramsSchema: z.object({
input: z.enum(['yes', 'no']),
}),
apply: (_resource, { input }) => input === 'yes',
@@ -31,7 +31,7 @@ const testIntegration = () =>
name: 'testRule1',
description: 'Test rule 1',
resourceType: 'test-resource',
schema: z.object({
paramsSchema: z.object({
foo: z.string(),
bar: z.number(),
}),
@@ -45,7 +45,7 @@ const testIntegration = () =>
name: 'testRule2',
description: 'Test rule 2',
resourceType: 'test-resource',
schema: z.object({
paramsSchema: z.object({
foo: z.string(),
}),
apply: (_resource: any) => false,
@@ -23,7 +23,7 @@ describe('createConditionFactory', () => {
name: 'test-rule',
description: 'test-description',
resourceType: 'test-resource',
schema: z.object({
paramsSchema: z.object({
foo: z.string(),
}),
apply: (_resource, _params) => true,
@@ -27,7 +27,7 @@ const transformConditions = createConditionTransformer([
name: 'test-rule-1',
description: 'Test rule 1',
resourceType: 'test-resource',
schema: z.object({
paramsSchema: z.object({
foo: z.string(),
bar: z.number(),
}),
@@ -38,7 +38,7 @@ const transformConditions = createConditionTransformer([
name: 'test-rule-2',
description: 'Test rule 2',
resourceType: 'test-resource',
schema: z.object({
paramsSchema: z.object({
foo: z.string(),
}),
apply: jest.fn(),
@@ -47,9 +47,9 @@ const mapConditions = <TQuery>(
}
const rule = getRule(criteria.rule);
const result = rule.schema.safeParse(criteria.params);
const result = rule.paramsSchema.safeParse(criteria.params);
if (rule.schema && !result.success) {
if (rule.paramsSchema && !result.success) {
throw new InputError(`Parameters to rule are invalid`, result.error);
}
@@ -40,7 +40,7 @@ const testRule1 = createPermissionRule({
name: 'test-rule-1',
description: 'Test rule 1',
resourceType: 'test-resource',
schema: z.object({
paramsSchema: z.object({
foo: z.string(),
bar: z.number().describe('bar'),
}),
@@ -52,7 +52,7 @@ const testRule2 = createPermissionRule({
name: 'test-rule-2',
description: 'Test rule 2',
resourceType: 'test-resource',
schema: z.object({
paramsSchema: z.object({
foo: z.string().describe('foo'),
}),
apply: (_resource: any, _foo) => false,
@@ -603,7 +603,7 @@ describe('createPermissionIntegrationRouter', () => {
name: testRule1.name,
description: testRule1.description,
resourceType: testRule1.resourceType,
schema: {
paramsSchema: {
$schema: 'http://json-schema.org/draft-07/schema#',
additionalProperties: false,
properties: {
@@ -623,7 +623,7 @@ describe('createPermissionIntegrationRouter', () => {
name: testRule2.name,
description: testRule2.description,
resourceType: testRule2.resourceType,
schema: {
paramsSchema: {
$schema: 'http://json-schema.org/draft-07/schema#',
additionalProperties: false,
properties: {
@@ -127,9 +127,9 @@ const applyConditions = <TResourceType extends string, TResource>(
}
const rule = getRule(criteria.rule);
const result = rule.schema.safeParse(criteria.params);
const result = rule.paramsSchema.safeParse(criteria.params);
if (rule.schema && !result.success) {
if (rule.paramsSchema && !result.success) {
throw new InputError(`Parameters to rule are invalid`, result.error);
}
@@ -195,7 +195,7 @@ export const createPermissionIntegrationRouter = <
name: rule.name,
description: rule.description,
resourceType: rule.resourceType,
schema: zodToJsonSchema(rule.schema),
paramsSchema: zodToJsonSchema(rule.paramsSchema),
}));
return res.json({ permissions, rules: serializableRules });
@@ -31,7 +31,7 @@ describe('permission integration utils', () => {
name: 'test-rule-1',
description: 'Test rule 1',
resourceType: 'test-resource',
schema: z.object({}),
paramsSchema: z.object({}),
apply: jest.fn(),
toQuery: jest.fn(),
});
@@ -40,7 +40,7 @@ describe('permission integration utils', () => {
name: 'test-rule-2',
description: 'Test rule 2',
resourceType: 'test-resource',
schema: z.object({}),
paramsSchema: z.object({}),
apply: jest.fn(),
toQuery: jest.fn(),
});
+1 -1
View File
@@ -66,7 +66,7 @@ export type PermissionRule<
/**
* A ZodSchema that documents the parameters that this rule accepts.
*/
schema: PermissionRuleSchema<TParams>;
paramsSchema: PermissionRuleSchema<TParams>;
/**
* Apply this rule to a resource already loaded from a backing data source. The params are
@@ -33,7 +33,7 @@ const isOwner = createPlaylistPermissionRule({
name: 'IS_OWNER',
description: 'Should allow only if the playlist belongs to the user',
resourceType: PLAYLIST_LIST_RESOURCE_TYPE,
schema: z.object({
paramsSchema: z.object({
owners: z.array(z.string()).describe('List of owner entity refs'),
}),
apply: (list: PlaylistMetadata, { owners }) => owners.includes(list.owner),
@@ -47,7 +47,7 @@ const isPublic = createPlaylistPermissionRule({
name: 'IS_PUBLIC',
description: 'Should allow only if the playlist is public',
resourceType: PLAYLIST_LIST_RESOURCE_TYPE,
schema: z.object({}),
paramsSchema: z.object({}),
apply: (list: PlaylistMetadata) => list.public,
toQuery: () => ({ key: 'public', values: [true] }),
});