Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions eslint/src/rules/validACL.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore
import { createRule } from 'eslint-plugin-yml/lib/utils';

import { isPairWithKey, isScalar } from '../utils.js';
import { isPairWithKey, isPairWithValue, isScalar } from '../utils.js';

const ACLs = [
'search',
Expand All @@ -23,12 +23,13 @@ const ACLs = [
export const validACL = createRule('validACL', {
meta: {
docs: {
description: 'x-acl enum must contains valid Algolia ACLs',
description: 'x-acl enum must be set and contain valid Algolia ACLs',
categories: null,
extensionRule: false,
layout: false,
},
messages: {
missingACL: 'x-acl is missing',
validString: 'is not a string',
validACL: `{{entry}} is not a valid Algolia ACL, must be one of: ${ACLs.join(', ')}.`,
validArray: 'is not an array of string',
Expand All @@ -43,6 +44,41 @@ export const validACL = createRule('validACL', {

return {
YAMLPair(node): void {
const spec = context.getFilename().match(/specs\/([a-z-]+?)\//)?.[1];
if (!spec) {
return;
}
if (spec === 'monitoring') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be the case for the crawler as well? or is it the case because it' doesn't have a client?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added acl for all the crawler endpoints so that this linter doesn't get mad, but I could exclude it

// monitoring uses a special API key and doesn't need ACLs
return;
}

if (spec === 'crawler') {
// no clients are generated for the crawler API
return;
}

// if we find then prop operationId, there must be x-acl on the same level
if (isPairWithKey(node, 'operationId')) {
const hasACL = node.parent.pairs.some((item: any) => isPairWithKey(item, 'x-acl'));

// ignore custom helpers
if (isPairWithValue(node, 'customGet') || isPairWithValue(node, 'customPost') || isPairWithValue(node, 'customPut') || isPairWithValue(node, 'customDelete')) {
return;
}


if (!hasACL) {
context.report({
node: node as any,
messageId: 'missingACL',
});
}

return;
}

// check the validity of x-acl
if (!isPairWithKey(node, 'x-acl')) {
return;
}
Expand Down
13 changes: 13 additions & 0 deletions eslint/tests/validACL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ nested:
],
invalid: [
{
filename: 'api-client-automation/specs/search/path/test.yml',
code: `
post:
operationId: test
description: Test endpoint without ACL
`,
errors: [{ messageId: 'missingACL' }],
},
{
filename: 'api-client-automation/specs/search/path/test.yml',
code: `
x-acl:
- notACL
Expand All @@ -38,6 +48,7 @@ x-acl:
errors: [{ messageId: 'validACL' }],
},
{
filename: 'api-client-automation/specs/search/path/test.yml',
code: `
nested:
inside:
Expand All @@ -48,12 +59,14 @@ nested:
errors: [{ messageId: 'validACL' }],
},
{
filename: 'api-client-automation/specs/search/path/test.yml',
code: `
x-acl: notList
`,
errors: [{ messageId: 'validArray' }],
},
{
filename: 'api-client-automation/specs/search/path/test.yml',
code: `
x-acl:
- ['search']
Expand Down
1 change: 1 addition & 0 deletions specs/common/helpers/setClientApiKey.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ method:
get:
x-helper: true
x-asynchronous-helper: false
x-acl: []
tags:
- Api Key
operationId: setClientApiKey
Expand Down
6 changes: 6 additions & 0 deletions specs/composition/helpers/waitForCompositionTask.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ method:
tags:
- Records
operationId: waitForCompositionTask
x-acl:
- editSettings
- settings
- addObject
- deleteObject
- deleteIndex
summary: Wait for operation to complete
description: |
Wait for a task to complete to ensure synchronized composition updates.
Expand Down
6 changes: 6 additions & 0 deletions specs/crawler/paths/crawler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ get:
Retrieves details about the specified crawler, optionally with its configuration.
tags:
- crawlers
x-acl:
- settings
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
- in: query
Expand Down Expand Up @@ -42,6 +44,8 @@ patch:
description: Update configuration.
tags:
- crawlers
x-acl:
- editSettings
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
requestBody:
Expand Down Expand Up @@ -70,6 +74,8 @@ delete:
description: Delete the specified crawler.
tags:
- crawlers
x-acl:
- editSettings
parameters:
- $ref: '#/components/parameters/CrawlerIdParameter'
responses:
Expand Down
2 changes: 2 additions & 0 deletions specs/crawler/paths/crawlerConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ patch:
Every time you update the configuration, a new version is created.
tags:
- config
x-acl:
- editSettings
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
requestBody:
Expand Down
2 changes: 2 additions & 0 deletions specs/crawler/paths/crawlerConfigVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ get:
You can use this to restore a previous version of the configuration.
tags:
- config
x-acl:
- settings
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
- $ref: '../common/parameters.yml#/CrawlerVersionParameter'
Expand Down
2 changes: 2 additions & 0 deletions specs/crawler/paths/crawlerConfigVersions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ get:
Every time you update a crawler's configuration, a new version is added.
tags:
- config
x-acl:
- settings
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
- $ref: '../common/parameters.yml#/ItemsPerPage'
Expand Down
1 change: 1 addition & 0 deletions specs/crawler/paths/crawlerCrawl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ post:
This operation is rate-limited to 500 requests every 24 hours.
tags:
- actions
x-acl: []
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
requestBody:
Expand Down
1 change: 1 addition & 0 deletions specs/crawler/paths/crawlerPause.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ post:
description: Pauses the specified crawler.
tags:
- actions
x-acl: []
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
responses:
Expand Down
1 change: 1 addition & 0 deletions specs/crawler/paths/crawlerReindex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ post:
description: Starts or resumes a crawl.
tags:
- actions
x-acl: []
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
responses:
Expand Down
1 change: 1 addition & 0 deletions specs/crawler/paths/crawlerRun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ post:
Otherwise, the crawler waits for its next scheduled run.
tags:
- actions
x-acl: []
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
responses:
Expand Down
2 changes: 2 additions & 0 deletions specs/crawler/paths/crawlerStats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ get:
description: Retrieves information about the number of crawled, skipped, and failed URLs.
tags:
- crawlers
x-acl:
- settings
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
responses:
Expand Down
2 changes: 2 additions & 0 deletions specs/crawler/paths/crawlerTask.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ get:
description: Retrieves the status of the specified tasks, whether they're pending or completed.
tags:
- tasks
x-acl:
- settings
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
- $ref: '../common/parameters.yml#/TaskIdParameter'
Expand Down
1 change: 1 addition & 0 deletions specs/crawler/paths/crawlerTaskCancel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ post:
To unblock the crawler, cancel the blocking task.
tags:
- tasks
x-acl: []
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
- $ref: '../common/parameters.yml#/TaskIdParameter'
Expand Down
1 change: 1 addition & 0 deletions specs/crawler/paths/crawlerTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ post:
You can test configuration changes by overriding specific parts before updating the full configuration.
tags:
- actions
x-acl: []
parameters:
- $ref: '../common/parameters.yml#/CrawlerIdParameter'
requestBody:
Expand Down
4 changes: 4 additions & 0 deletions specs/crawler/paths/crawlers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ get:
description: Lists all your crawlers.
tags:
- crawlers
x-acl:
- settings
parameters:
- $ref: '../common/parameters.yml#/ItemsPerPage'
- $ref: '../common/parameters.yml#/Page'
Expand All @@ -30,6 +32,8 @@ post:
description: Creates a new crawler with the provided configuration.
tags:
- crawlers
x-acl:
- editSettings
requestBody:
content:
application/json:
Expand Down
1 change: 1 addition & 0 deletions specs/crawler/paths/docsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ post:
operationId: createDocSearchApp
summary: Create a new Algolia app with the DocSearch plan
description: Create a new Algolia app with the DocSearch plan.
x-acl: []
requestBody:
content:
application/json:
Expand Down
2 changes: 2 additions & 0 deletions specs/crawler/paths/domains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ get:
Crawlers will only run if the URLs match any of the registered domains.
tags:
- domains
x-acl:
- settings
parameters:
- $ref: '../common/parameters.yml#/ItemsPerPage'
- $ref: '../common/parameters.yml#/Page'
Expand Down
4 changes: 4 additions & 0 deletions specs/ingestion/helpers/chunkedPush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ method:
- javascript
- php
- python
x-acl:
- addObject
- deleteIndex
- editSettings
operationId: chunkedPush
summary: Replace all records in an index
description: |
Expand Down
8 changes: 8 additions & 0 deletions specs/ingestion/paths/tasks/v1/taskID.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ patch:
summary: Update a task V1
description: Updates a task by its ID using the v1 endpoint, please use `updateTask` instead.
operationId: updateTaskV1
x-acl:
- addObject
- deleteIndex
- editSettings
deprecated: true
parameters:
- $ref: '../../../common/parameters.yml#/pathTaskID'
Expand All @@ -53,6 +57,10 @@ delete:
summary: Delete a task
description: Deletes a task by its ID using the v1 endpoint, please use `deleteTask` instead.
operationId: deleteTaskV1
x-acl:
- addObject
- deleteIndex
- editSettings
deprecated: true
parameters:
- $ref: '../../../common/parameters.yml#/pathTaskID'
Expand Down
4 changes: 4 additions & 0 deletions specs/ingestion/paths/tasks/v1/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ post:
summary: Create a task V1
description: Creates a new task using the v1 endpoint, please use `createTask` instead.
operationId: createTaskV1
x-acl:
- addObject
- deleteIndex
- editSettings
deprecated: true
x-codegen-request-body-name: taskCreate
requestBody:
Expand Down
18 changes: 15 additions & 3 deletions specs/ingestion/paths/tasks/v2/taskID.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
get:
tags:
- tasks
summary: Retrieve a task
description: Retrieves a task by its ID.
operationId: getTask
x-acl:
- addObject
- deleteIndex
- editSettings
summary: Retrieve a task
description: Retrieves a task by its ID.
operationId: getTask
parameters:
- $ref: '../../../common/parameters.yml#/pathTaskID'
responses:
Expand All @@ -23,6 +23,10 @@ get:
put:
tags:
- tasks
x-acl:
- addObject
- deleteIndex
- editSettings
summary: Fully update a task
description: Fully updates a task by its ID, use partialUpdateTask if you only want to update a subset of fields.
operationId: replaceTask
Expand All @@ -48,6 +52,10 @@ put:
patch:
tags:
- tasks
x-acl:
- addObject
- deleteIndex
- editSettings
summary: Partially update a task
description: Partially updates a task by its ID.
operationId: updateTask
Expand All @@ -72,6 +80,10 @@ patch:
delete:
tags:
- tasks
x-acl:
- addObject
- deleteIndex
- editSettings
summary: Delete a task
description: Deletes a task by its ID.
operationId: deleteTask
Expand Down
4 changes: 4 additions & 0 deletions specs/ingestion/paths/tasks/v2/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ post:
summary: Create a task
description: Creates a new task.
operationId: createTask
x-acl:
- addObject
- deleteIndex
- editSettings
requestBody:
description: Request body for creating a task.
content:
Expand Down
Loading