forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCiscoSecureEndpointApi.credentials.ts
123 lines (110 loc) · 2.62 KB
/
CiscoSecureEndpointApi.credentials.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import type {
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';
import axios from 'axios';
export class CiscoSecureEndpointApi implements ICredentialType {
name = 'ciscoSecureEndpointApi';
displayName = 'Cisco Secure Endpoint (AMP) API';
documentationUrl = 'ciscosecureendpoint';
icon = 'file:icons/Cisco.svg';
httpRequestNode = {
name: 'Cisco Secure Endpoint',
docsUrl: 'https://developer.cisco.com/docs/secure-endpoint/',
apiBaseUrl: '',
};
properties: INodeProperties[] = [
{
displayName: 'Region',
name: 'region',
type: 'options',
options: [
{
name: 'Asia Pacific, Japan, and China',
value: 'apjc.amp',
},
{
name: 'Europe',
value: 'eu.amp',
},
{
name: 'North America',
value: 'amp',
},
],
default: 'amp',
},
{
displayName: 'Client ID',
name: 'clientId',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Client Secret',
name: 'clientSecret',
type: 'string',
typeOptions: {
password: true,
},
default: '',
required: true,
},
];
async authenticate(
credentials: ICredentialDataDecryptedObject,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const clientId = credentials.clientId as string;
const clientSecret = credentials.clientSecret as string;
const region = credentials.region as string;
const secureXToken = await axios({
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
},
auth: {
username: clientId,
password: clientSecret,
},
method: 'POST',
data: new URLSearchParams({
grant_type: 'client_credentials',
}).toString(),
url: `https://visibility.${region}.cisco.com/iroh/oauth2/token`,
});
const secureEndpointToken = await axios({
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
Authorization: `Bearer ${secureXToken.data.access_token}`,
},
method: 'POST',
data: new URLSearchParams({
grant_type: 'client_credentials',
}).toString(),
url: `https://api.${region}.cisco.com/v3/access_tokens`,
});
const requestOptionsWithAuth: IHttpRequestOptions = {
...requestOptions,
headers: {
...requestOptions.headers,
Authorization: `Bearer ${secureEndpointToken.data.access_token}`,
},
};
return requestOptionsWithAuth;
}
test: ICredentialTestRequest = {
request: {
baseURL: '=https://api.{{$credentials.region}}.cisco.com',
url: '/v3/organizations',
qs: {
size: 10,
},
},
};
}