-
Notifications
You must be signed in to change notification settings - Fork 2
/
sdk.ts
55 lines (43 loc) · 1.6 KB
/
sdk.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
import { IHttp, IHttpRequest, IRead } from '@rocket.chat/apps-engine/definition/accessors';
export interface IVerificationinfo {
record_name: string;
record_target: string;
}
export interface IVerirication {
certificate_status: string;
signature: string;
brand_check: boolean;
verification_info: IVerificationinfo;
verification_status?: any;
verification_type: string;
}
export interface ICloudflareResponse<T> {
result: Array<T>;
success: boolean;
errors: Array<any>;
messages: Array<any>;
}
class SDK {
public async getSslVerification(http: IHttp, read: IRead) {
const url = 'https://api.cloudflare.com/client/v4/zones/447cd9422744a695c8386a1d97d2bc10/ssl/verification?retry=true';
const options: IHttpRequest = {
headers: await this.getHeaders(read),
};
const response = await http.get(url, options);
return response.data as ICloudflareResponse<IVerirication>;
}
public async hasAuthInfo(read: IRead): Promise<boolean> {
const headers = await this.getHeaders(read);
return !!headers['X-Auth-Key'] && !!headers['X-Auth-Email'];
}
private async getHeaders(read: IRead): Promise<{[key: string]: string}> {
const settingsReader = read.getEnvironmentReader().getSettings();
const authKeySetting = await settingsReader.getValueById('auth_key');
const authEmailSetting = await settingsReader.getValueById('auth_email');
return {
'X-Auth-Key': authKeySetting,
'X-Auth-Email': authEmailSetting,
};
}
}
export const sdk = new SDK();