-
Notifications
You must be signed in to change notification settings - Fork 15
/
servers.ts
185 lines (176 loc) · 4.71 KB
/
servers.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { RequestContext, HttpMethod } from "./http/http";
/**
*
* Represents the configuration of a server
*
*/
export class BaseServerConfiguration {
public constructor(
private url: string,
private variableConfiguration: { [key: string]: string }
) {}
/**
* Sets the value of the variables of this server.
*
* @param variableConfiguration a partial variable configuration for the variables contained in the url
*/
public setVariables(variableConfiguration: { [key: string]: string }): void {
Object.assign(this.variableConfiguration, variableConfiguration);
}
public getConfiguration(): { [key: string]: string } {
return this.variableConfiguration;
}
public clone(): BaseServerConfiguration {
return new BaseServerConfiguration(this.url, {
...this.variableConfiguration,
});
}
private getUrl() {
let replacedUrl = this.url;
for (const key in this.variableConfiguration) {
const re = new RegExp("{" + key + "}", "g");
replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]);
}
return replacedUrl;
}
/**
* Creates a new request context for this server using the url with variables
* replaced with their respective values and the endpoint of the request appended.
*
* @param endpoint the endpoint to be queried on the server
* @param httpMethod httpMethod to be used
*
*/
public makeRequestContext(
endpoint: string,
httpMethod: HttpMethod
): RequestContext {
return new RequestContext(this.getUrl() + endpoint, httpMethod);
}
}
/**
*
* Represents the configuration of a server including its
* url template and variable configuration based on the url.
*
*/
export class ServerConfiguration<
T extends { [key: string]: string },
> extends BaseServerConfiguration {}
export const server1 = new ServerConfiguration<{
site:
| "datadoghq.com"
| "us3.datadoghq.com"
| "us5.datadoghq.com"
| "ap1.datadoghq.com"
| "datadoghq.eu"
| "ddog-gov.com";
subdomain: string;
}>("https://{subdomain}.{site}", {
site: "datadoghq.com",
subdomain: "api",
});
export const server2 = new ServerConfiguration<{
name: string;
protocol: string;
}>("{protocol}://{name}", {
name: "api.datadoghq.com",
protocol: "https",
});
export const server3 = new ServerConfiguration<{
site: string;
subdomain: string;
}>("https://{subdomain}.{site}", {
site: "datadoghq.com",
subdomain: "api",
});
export const servers = [server1, server2, server3];
export const operationServers: {
[endpoint: string]: BaseServerConfiguration[];
} = {
"v1.IPRangesApi.getIPRanges": [
new ServerConfiguration<{
site:
| "datadoghq.com"
| "us3.datadoghq.com"
| "us5.datadoghq.com"
| "ap1.datadoghq.com"
| "datadoghq.eu"
| "ddog-gov.com";
subdomain: string;
}>("https://{subdomain}.{site}", {
site: "datadoghq.com",
subdomain: "ip-ranges",
}),
new ServerConfiguration<{
name: string;
protocol: string;
}>("{protocol}://{name}", {
name: "ip-ranges.datadoghq.com",
protocol: "https",
}),
new ServerConfiguration<{
subdomain: string;
}>("https://{subdomain}.datadoghq.com", {
subdomain: "ip-ranges",
}),
],
"v1.LogsApi.submitLog": [
new ServerConfiguration<{
site:
| "datadoghq.com"
| "us3.datadoghq.com"
| "us5.datadoghq.com"
| "ap1.datadoghq.com"
| "datadoghq.eu"
| "ddog-gov.com";
subdomain: string;
}>("https://{subdomain}.{site}", {
site: "datadoghq.com",
subdomain: "http-intake.logs",
}),
new ServerConfiguration<{
name: string;
protocol: string;
}>("{protocol}://{name}", {
name: "http-intake.logs.datadoghq.com",
protocol: "https",
}),
new ServerConfiguration<{
site: string;
subdomain: string;
}>("https://{subdomain}.{site}", {
site: "datadoghq.com",
subdomain: "http-intake.logs",
}),
],
"v2.LogsApi.submitLog": [
new ServerConfiguration<{
site:
| "datadoghq.com"
| "us3.datadoghq.com"
| "us5.datadoghq.com"
| "ap1.datadoghq.com"
| "datadoghq.eu"
| "ddog-gov.com";
subdomain: string;
}>("https://{subdomain}.{site}", {
site: "datadoghq.com",
subdomain: "http-intake.logs",
}),
new ServerConfiguration<{
name: string;
protocol: string;
}>("{protocol}://{name}", {
name: "http-intake.logs.datadoghq.com",
protocol: "https",
}),
new ServerConfiguration<{
site: string;
subdomain: string;
}>("https://{subdomain}.{site}", {
site: "datadoghq.com",
subdomain: "http-intake.logs",
}),
],
};