Skip to content

Commit d404d88

Browse files
author
Jake Ferrero
committed
IP-SPRINT update bocchi client template and add another example template
1 parent 687a36d commit d404d88

File tree

2 files changed

+135
-10
lines changed

2 files changed

+135
-10
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"instanceConfigFields": {
3+
"email": {
4+
"type": "string"
5+
},
6+
"token": {
7+
"type": "string",
8+
"mask": true
9+
},
10+
"tenant": {
11+
"type": "string"
12+
}
13+
},
14+
"authentication": {
15+
"strategy": "endpoint",
16+
"params": {
17+
"path": "/auth",
18+
"method": "POST",
19+
"headers": {
20+
"user-agent": "JupiterOne",
21+
"tenant": "%config.tenant%"
22+
},
23+
"body": {
24+
"exampleBody": "%config.exampleConfigValue%"
25+
}
26+
},
27+
"authHeaders": {
28+
"user-agent": "JupiterOne",
29+
"tenant": "%config.tenant%",
30+
"Authorization": "bearer %response.auth.token%"
31+
}
32+
},
33+
"baseUrl": "https://example.com",
34+
"steps": [
35+
{
36+
"id": "fetch-organizations",
37+
"name": "Fetch Organizations",
38+
"entity": {
39+
"name": "Organization",
40+
"_type": "example_organization",
41+
"_class": ["Organization"],
42+
"_keyPath": "name",
43+
"staticFields": {
44+
"a": false,
45+
"b": true
46+
},
47+
"fieldMappings": {
48+
"name": "title",
49+
"displayName": "title",
50+
"description": "advisory.description",
51+
"ruleId": "advisory.ruleId",
52+
"severity": "advisory.severity",
53+
"ecosystem": "advisory.ecosystem",
54+
"urls": "advisory.references.urls",
55+
"exposureType": "exposureType",
56+
"repositoryId": "repositoryId",
57+
"subdirectory": "subdirectory",
58+
"createdOn": "openedAt"
59+
}
60+
},
61+
"request": {
62+
"urlTemplate": "/organizations"
63+
},
64+
"response": {
65+
"dataPath": "data",
66+
"responseType": "LIST"
67+
},
68+
"directRelationships": [
69+
{
70+
"targetKey": "directory",
71+
"targetType": "example_directory",
72+
"_class": "HAS",
73+
"direction": "FORWARD"
74+
}
75+
]
76+
},
77+
{
78+
"id": "fetch-directory",
79+
"name": "Fetch Directory",
80+
"entity": {
81+
"name": "Directory",
82+
"_type": "example_directory",
83+
"_class": ["Directory"],
84+
"_keyPath": "id"
85+
},
86+
"fieldMappings": {
87+
"name": "title",
88+
"orgId": "organizationId"
89+
},
90+
"parentAssociation": {
91+
"parentEntityType": "example_organization",
92+
"relationshipClass": "HAS"
93+
},
94+
"request": {
95+
"urlTemplate": "/organizations/%parent._key%/directory"
96+
},
97+
"response": {
98+
"dataPath": "data",
99+
"responseType": "SINGLETON"
100+
},
101+
"dependsOn": ["fetch-organizations"]
102+
},
103+
{
104+
"id": "fetch-users",
105+
"name": "Fetch Users",
106+
"entity": {
107+
"name": "User",
108+
"_type": "example_user",
109+
"_class": ["User"],
110+
"_keyPath": "email"
111+
},
112+
"parentAssociation": {
113+
"parentEntityType": "example_directory",
114+
"relationshipClass": "HAS"
115+
},
116+
"request": {
117+
"urlTemplate": "/organizations/%parent._key%/directory/%parent.orgId%/users?nextPage=%nextToken%"
118+
},
119+
"response": {
120+
"dataPath": "data",
121+
"nextTokenPath": "next",
122+
"responseType": "LIST"
123+
},
124+
"dependsOn": ["fetch-directory"]
125+
}
126+
]
127+
}

packages/integration-sdk-cli/src/bocchi/templates/top-level/src/client.ts.hbs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class APIClient extends BaseAPIClient {
3131
}
3232
{{else}}
3333
protected async getAuthorizationHeaders(): Promise<Record<string, string>> {
34-
const response = await this.retryableRequest(
34+
const response = await (await this.retryableRequest(
3535
`${this.baseUrl}{{template.authentication.params.path}}`,
3636
{
3737
headers: { {{#each (sanitizeAuthObject template.authentication.params.headers)}}'{{@key}}': `{{this}}`,{{/each}} },
@@ -40,7 +40,7 @@ export class APIClient extends BaseAPIClient {
4040
body: { {{#each (sanitizeAuthObject template.authentication.params.body)}}{{@key}}: {{this}},{{/each}} }
4141
{{/if}}
4242
}
43-
);
43+
)).json();
4444
return { {{#each (sanitizeAuthObject template.authentication.authHeaders)}}'{{@key}}': `{{this}}`,{{/each}} }
4545
}
4646
{{/if}}
@@ -58,17 +58,16 @@ export class APIClient extends BaseAPIClient {
5858
{{#if (isSingletonRequest response.responseType)}}
5959
public async get{{pascalCase entity.name}}({{#if parentAssociation}}parentEntity: Entity{{/if}}): Promise<{{pascalCase entity.name}}> {
6060
const url = `${this.baseUrl}{{{sanitizeUrlPath request.urlTemplate}}}`;
61-
const response = await this.retryableRequest(
61+
const response = await (await this.retryableRequest(
6262
url,
6363
{
64-
headers: { ...this.authHeaders },
6564
method: '{{sanitizeHttpMethod request.method}}',
6665
{{#if request.params}}
6766
body: { {{#each (sanitizeHttpBody request.params)}}'{{@key}}': `{{this}}`,{{/each}} }
6867
{{/if}}
6968
}
70-
);
71-
return (await response.json() as any).{{response.dataPath}} as {{pascalCase entity.name}};
69+
)).json();
70+
return response.{{response.dataPath}} as {{pascalCase entity.name}};
7271
}
7372
{{else}}
7473
public async iterate{{pascalCase entity.name}}s(
@@ -82,17 +81,16 @@ export class APIClient extends BaseAPIClient {
8281
do {
8382
{{/if}}
8483
const url = `${this.baseUrl}{{{sanitizeUrlPath request.urlTemplate}}}`;
85-
const response = await this.retryableRequest(
84+
const response = await (await this.retryableRequest(
8685
url,
8786
{
88-
headers: { ...this.authHeaders },
8987
method: '{{sanitizeHttpMethod request.method}}',
9088
{{#if request.params}}
9189
body: { {{#each (sanitizeHttpBody request.params)}}'{{@key}}': `{{this}}`,{{/each}} }
9290
{{/if}}
9391
}
94-
);
95-
const resources = (await response.json() as any).{{response.dataPath}} as {{pascalCase entity.name}}[];
92+
)).json();
93+
const resources = response.{{response.dataPath}} as {{pascalCase entity.name}}[];
9694
for (const resource of resources) {
9795
await iteratee(resource);
9896
}

0 commit comments

Comments
 (0)