2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2022-04-18 10:31:59 -07:00
|
|
|
ICredentialDataDecryptedObject,
|
|
|
|
ICredentialTestRequest,
|
2021-01-28 10:00:47 -08:00
|
|
|
ICredentialType,
|
2022-04-18 10:31:59 -07:00
|
|
|
IHttpRequestOptions,
|
2021-06-12 09:39:55 -07:00
|
|
|
INodeProperties,
|
2021-01-28 10:00:47 -08:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
export class DiscourseApi implements ICredentialType {
|
|
|
|
name = 'discourseApi';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-01-28 10:00:47 -08:00
|
|
|
displayName = 'Discourse API';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-01-28 10:00:47 -08:00
|
|
|
documentationUrl = 'discourse';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-06-12 09:39:55 -07:00
|
|
|
properties: INodeProperties[] = [
|
2021-01-28 10:00:47 -08:00
|
|
|
{
|
|
|
|
displayName: 'URL',
|
|
|
|
name: 'url',
|
|
|
|
required: true,
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2021-01-28 10:00:47 -08:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'API Key',
|
|
|
|
name: 'apiKey',
|
|
|
|
required: true,
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2022-11-01 09:41:45 -07:00
|
|
|
typeOptions: { password: true },
|
2021-01-28 10:00:47 -08:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Username',
|
|
|
|
name: 'username',
|
|
|
|
required: true,
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2021-01-28 10:00:47 -08:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
];
|
2022-04-18 10:31:59 -07:00
|
|
|
|
2022-07-24 08:36:17 -07:00
|
|
|
async authenticate(
|
|
|
|
credentials: ICredentialDataDecryptedObject,
|
|
|
|
requestOptions: IHttpRequestOptions,
|
|
|
|
): Promise<IHttpRequestOptions> {
|
2022-04-18 10:31:59 -07:00
|
|
|
requestOptions.headers = {
|
|
|
|
'Api-Key': credentials.apiKey,
|
|
|
|
'Api-Username': credentials.username,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (requestOptions.method === 'GET') {
|
|
|
|
delete requestOptions.body;
|
|
|
|
}
|
|
|
|
|
|
|
|
return requestOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
test: ICredentialTestRequest = {
|
|
|
|
request: {
|
|
|
|
baseURL: '={{$credentials.url}}',
|
|
|
|
url: '/admin/groups.json',
|
|
|
|
method: 'GET',
|
|
|
|
},
|
|
|
|
};
|
2021-06-12 09:39:55 -07:00
|
|
|
}
|