Skip to content

Commit 1eee2a5

Browse files
authored
fix(specs): add ACL to missing endpoints (#5529)
1 parent e5cfde5 commit 1eee2a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+174
-5
lines changed

eslint/src/rules/validACL.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-ignore
22
import { createRule } from 'eslint-plugin-yml/lib/utils';
33

4-
import { isPairWithKey, isScalar } from '../utils.js';
4+
import { isPairWithKey, isPairWithValue, isScalar } from '../utils.js';
55

66
const ACLs = [
77
'search',
@@ -23,12 +23,13 @@ const ACLs = [
2323
export const validACL = createRule('validACL', {
2424
meta: {
2525
docs: {
26-
description: 'x-acl enum must contains valid Algolia ACLs',
26+
description: 'x-acl enum must be set and contain valid Algolia ACLs',
2727
categories: null,
2828
extensionRule: false,
2929
layout: false,
3030
},
3131
messages: {
32+
missingACL: 'x-acl is missing',
3233
validString: 'is not a string',
3334
validACL: `{{entry}} is not a valid Algolia ACL, must be one of: ${ACLs.join(', ')}.`,
3435
validArray: 'is not an array of string',
@@ -43,6 +44,41 @@ export const validACL = createRule('validACL', {
4344

4445
return {
4546
YAMLPair(node): void {
47+
const spec = context.getFilename().match(/specs\/([a-z-]+?)\//)?.[1];
48+
if (!spec) {
49+
return;
50+
}
51+
if (spec === 'monitoring') {
52+
// monitoring uses a special API key and doesn't need ACLs
53+
return;
54+
}
55+
56+
if (spec === 'crawler') {
57+
// no clients are generated for the crawler API
58+
return;
59+
}
60+
61+
// if we find then prop operationId, there must be x-acl on the same level
62+
if (isPairWithKey(node, 'operationId')) {
63+
const hasACL = node.parent.pairs.some((item: any) => isPairWithKey(item, 'x-acl'));
64+
65+
// ignore custom helpers
66+
if (isPairWithValue(node, 'customGet') || isPairWithValue(node, 'customPost') || isPairWithValue(node, 'customPut') || isPairWithValue(node, 'customDelete')) {
67+
return;
68+
}
69+
70+
71+
if (!hasACL) {
72+
context.report({
73+
node: node as any,
74+
messageId: 'missingACL',
75+
});
76+
}
77+
78+
return;
79+
}
80+
81+
// check the validity of x-acl
4682
if (!isPairWithKey(node, 'x-acl')) {
4783
return;
4884
}

eslint/tests/validACL.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ nested:
3030
],
3131
invalid: [
3232
{
33+
filename: 'api-client-automation/specs/search/path/test.yml',
34+
code: `
35+
post:
36+
operationId: test
37+
description: Test endpoint without ACL
38+
`,
39+
errors: [{ messageId: 'missingACL' }],
40+
},
41+
{
42+
filename: 'api-client-automation/specs/search/path/test.yml',
3343
code: `
3444
x-acl:
3545
- notACL
@@ -38,6 +48,7 @@ x-acl:
3848
errors: [{ messageId: 'validACL' }],
3949
},
4050
{
51+
filename: 'api-client-automation/specs/search/path/test.yml',
4152
code: `
4253
nested:
4354
inside:
@@ -48,12 +59,14 @@ nested:
4859
errors: [{ messageId: 'validACL' }],
4960
},
5061
{
62+
filename: 'api-client-automation/specs/search/path/test.yml',
5163
code: `
5264
x-acl: notList
5365
`,
5466
errors: [{ messageId: 'validArray' }],
5567
},
5668
{
69+
filename: 'api-client-automation/specs/search/path/test.yml',
5770
code: `
5871
x-acl:
5972
- ['search']

specs/common/helpers/setClientApiKey.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ method:
22
get:
33
x-helper: true
44
x-asynchronous-helper: false
5+
x-acl: []
56
tags:
67
- Api Key
78
operationId: setClientApiKey

specs/composition/helpers/waitForCompositionTask.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ method:
44
tags:
55
- Records
66
operationId: waitForCompositionTask
7+
x-acl:
8+
- editSettings
9+
- settings
10+
- addObject
11+
- deleteObject
12+
- deleteIndex
713
summary: Wait for operation to complete
814
description: |
915
Wait for a task to complete to ensure synchronized composition updates.

specs/crawler/paths/crawler.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ get:
55
Retrieves details about the specified crawler, optionally with its configuration.
66
tags:
77
- crawlers
8+
x-acl:
9+
- settings
810
parameters:
911
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
1012
- in: query
@@ -42,6 +44,8 @@ patch:
4244
description: Update configuration.
4345
tags:
4446
- crawlers
47+
x-acl:
48+
- editSettings
4549
parameters:
4650
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
4751
requestBody:
@@ -70,6 +74,8 @@ delete:
7074
description: Delete the specified crawler.
7175
tags:
7276
- crawlers
77+
x-acl:
78+
- editSettings
7379
parameters:
7480
- $ref: '#/components/parameters/CrawlerIdParameter'
7581
responses:

specs/crawler/paths/crawlerConfig.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ patch:
66
Every time you update the configuration, a new version is created.
77
tags:
88
- config
9+
x-acl:
10+
- editSettings
911
parameters:
1012
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
1113
requestBody:

specs/crawler/paths/crawlerConfigVersion.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ get:
77
You can use this to restore a previous version of the configuration.
88
tags:
99
- config
10+
x-acl:
11+
- settings
1012
parameters:
1113
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
1214
- $ref: '../common/parameters.yml#/CrawlerVersionParameter'

specs/crawler/paths/crawlerConfigVersions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ get:
66
Every time you update a crawler's configuration, a new version is added.
77
tags:
88
- config
9+
x-acl:
10+
- settings
911
parameters:
1012
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
1113
- $ref: '../common/parameters.yml#/ItemsPerPage'

specs/crawler/paths/crawlerCrawl.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ post:
99
This operation is rate-limited to 500 requests every 24 hours.
1010
tags:
1111
- actions
12+
x-acl: []
1213
parameters:
1314
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
1415
requestBody:

specs/crawler/paths/crawlerPause.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ post:
44
description: Pauses the specified crawler.
55
tags:
66
- actions
7+
x-acl: []
78
parameters:
89
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
910
responses:

0 commit comments

Comments
 (0)