Skip to content

Commit

Permalink
IP-SPRINT update bocchi client template and add another example template
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Ferrero committed May 13, 2024
1 parent 687a36d commit d404d88
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"instanceConfigFields": {
"email": {
"type": "string"
},
"token": {
"type": "string",
"mask": true
},
"tenant": {
"type": "string"
}
},
"authentication": {
"strategy": "endpoint",
"params": {
"path": "/auth",
"method": "POST",
"headers": {
"user-agent": "JupiterOne",
"tenant": "%config.tenant%"
},
"body": {
"exampleBody": "%config.exampleConfigValue%"
}
},
"authHeaders": {
"user-agent": "JupiterOne",
"tenant": "%config.tenant%",
"Authorization": "bearer %response.auth.token%"
}
},
"baseUrl": "https://example.com",
"steps": [
{
"id": "fetch-organizations",
"name": "Fetch Organizations",
"entity": {
"name": "Organization",
"_type": "example_organization",
"_class": ["Organization"],
"_keyPath": "name",
"staticFields": {
"a": false,
"b": true
},
"fieldMappings": {
"name": "title",
"displayName": "title",
"description": "advisory.description",
"ruleId": "advisory.ruleId",
"severity": "advisory.severity",
"ecosystem": "advisory.ecosystem",
"urls": "advisory.references.urls",
"exposureType": "exposureType",
"repositoryId": "repositoryId",
"subdirectory": "subdirectory",
"createdOn": "openedAt"
}
},
"request": {
"urlTemplate": "/organizations"
},
"response": {
"dataPath": "data",
"responseType": "LIST"
},
"directRelationships": [
{
"targetKey": "directory",
"targetType": "example_directory",
"_class": "HAS",
"direction": "FORWARD"
}
]
},
{
"id": "fetch-directory",
"name": "Fetch Directory",
"entity": {
"name": "Directory",
"_type": "example_directory",
"_class": ["Directory"],
"_keyPath": "id"
},
"fieldMappings": {
"name": "title",
"orgId": "organizationId"
},
"parentAssociation": {
"parentEntityType": "example_organization",
"relationshipClass": "HAS"
},
"request": {
"urlTemplate": "/organizations/%parent._key%/directory"
},
"response": {
"dataPath": "data",
"responseType": "SINGLETON"
},
"dependsOn": ["fetch-organizations"]
},
{
"id": "fetch-users",
"name": "Fetch Users",
"entity": {
"name": "User",
"_type": "example_user",
"_class": ["User"],
"_keyPath": "email"
},
"parentAssociation": {
"parentEntityType": "example_directory",
"relationshipClass": "HAS"
},
"request": {
"urlTemplate": "/organizations/%parent._key%/directory/%parent.orgId%/users?nextPage=%nextToken%"
},
"response": {
"dataPath": "data",
"nextTokenPath": "next",
"responseType": "LIST"
},
"dependsOn": ["fetch-directory"]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class APIClient extends BaseAPIClient {
}
{{else}}
protected async getAuthorizationHeaders(): Promise<Record<string, string>> {
const response = await this.retryableRequest(
const response = await (await this.retryableRequest(
`${this.baseUrl}{{template.authentication.params.path}}`,
{
headers: { {{#each (sanitizeAuthObject template.authentication.params.headers)}}'{{@key}}': `{{this}}`,{{/each}} },
Expand All @@ -40,7 +40,7 @@ export class APIClient extends BaseAPIClient {
body: { {{#each (sanitizeAuthObject template.authentication.params.body)}}{{@key}}: {{this}},{{/each}} }
{{/if}}
}
);
)).json();
return { {{#each (sanitizeAuthObject template.authentication.authHeaders)}}'{{@key}}': `{{this}}`,{{/each}} }
}
{{/if}}
Expand All @@ -58,17 +58,16 @@ export class APIClient extends BaseAPIClient {
{{#if (isSingletonRequest response.responseType)}}
public async get{{pascalCase entity.name}}({{#if parentAssociation}}parentEntity: Entity{{/if}}): Promise<{{pascalCase entity.name}}> {
const url = `${this.baseUrl}{{{sanitizeUrlPath request.urlTemplate}}}`;
const response = await this.retryableRequest(
const response = await (await this.retryableRequest(
url,
{
headers: { ...this.authHeaders },
method: '{{sanitizeHttpMethod request.method}}',
{{#if request.params}}
body: { {{#each (sanitizeHttpBody request.params)}}'{{@key}}': `{{this}}`,{{/each}} }
{{/if}}
}
);
return (await response.json() as any).{{response.dataPath}} as {{pascalCase entity.name}};
)).json();
return response.{{response.dataPath}} as {{pascalCase entity.name}};
}
{{else}}
public async iterate{{pascalCase entity.name}}s(
Expand All @@ -82,17 +81,16 @@ export class APIClient extends BaseAPIClient {
do {
{{/if}}
const url = `${this.baseUrl}{{{sanitizeUrlPath request.urlTemplate}}}`;
const response = await this.retryableRequest(
const response = await (await this.retryableRequest(
url,
{
headers: { ...this.authHeaders },
method: '{{sanitizeHttpMethod request.method}}',
{{#if request.params}}
body: { {{#each (sanitizeHttpBody request.params)}}'{{@key}}': `{{this}}`,{{/each}} }
{{/if}}
}
);
const resources = (await response.json() as any).{{response.dataPath}} as {{pascalCase entity.name}}[];
)).json();
const resources = response.{{response.dataPath}} as {{pascalCase entity.name}}[];
for (const resource of resources) {
await iteratee(resource);
}
Expand Down

0 comments on commit d404d88

Please sign in to comment.