1 | /**
|
2 | * The Fastly Healthcheck API.
|
3 | *
|
4 | * @see https://docs.fastly.com/api/config#healthcheck
|
5 | * @type {HealthcheckAPI}
|
6 | */
|
7 | class HealthcheckAPI {
|
8 | constructor(base) {
|
9 | Object.assign(this, {
|
10 | service_id: base.service_id,
|
11 | request: base.request,
|
12 | getVersion: base.getVersion,
|
13 | });
|
14 | }
|
15 |
|
16 | /**
|
17 | * List all healthchecks for a particular service and version.
|
18 | *
|
19 | * @see https://docs.fastly.com/api/config#healthcheck_126cb37382d68583269420ba772ded36
|
20 | * @param {string} version - The current version of a service.
|
21 | * @returns {Promise} The response object representing the completion or failure.
|
22 | */
|
23 | async readHealthchecks(version) {
|
24 | return this.request.get(`/service/${this.service_id}/version/${await this.getVersion(version, 'current')}/healthcheck`);
|
25 | }
|
26 |
|
27 | /**
|
28 | * Get details of a single named healthcheck.
|
29 | *
|
30 | * @see https://docs.fastly.com/api/config#healthcheck_b54ea357a2377e62ae7649e609b94966
|
31 | * @param {string} version - The current version of a service.
|
32 | * @param {string} name - The name of the healthcheck.
|
33 | * @returns {Promise} The response object representing the completion or failure.
|
34 | */
|
35 | async readHealthcheck(version, name) {
|
36 | return this.request.get(`/service/${this.service_id}/version/${await this.getVersion(version, 'current')}/healthcheck/${name}`);
|
37 | }
|
38 |
|
39 | /**
|
40 | * Create a healthcheck for a particular service and version.
|
41 | *
|
42 | * @see https://docs.fastly.com/api/config#healthcheck_8712be8923dd419c54393da3ac31f6d3
|
43 | * @param {string} version - The current version of a service.
|
44 | * @param {object} data - The healthcheck definition.
|
45 | * @returns {Promise} The response object representing the completion or failure.
|
46 | */
|
47 | async createHealthcheck(version, data) {
|
48 | return this.request.post(`/service/${this.service_id}/version/${await this.getVersion(version, 'current')}/healthcheck`, data);
|
49 | }
|
50 |
|
51 | /**
|
52 | * Update the healthcheck for a particular service and version.
|
53 | *
|
54 | * @see https://docs.fastly.com/api/config#healthcheck_9a60b6005125c4afeaa80111e69d7586
|
55 | * @param {string} version - The current version of a service.
|
56 | * @param {string} name - The name of the healthcheck to update.
|
57 | * @param {object} data - The healthcheck definition.
|
58 | * @returns {Promise} The response object representing the completion or failure.
|
59 | */
|
60 | async updateHealthcheck(version, name, data) {
|
61 | return this.request.put(`/service/${this.service_id}/version/${await this.getVersion(version, 'current')}/healthcheck/${name}`, data);
|
62 | }
|
63 |
|
64 | /**
|
65 | * Delete the healthcheck for a particular service and version.
|
66 | *
|
67 | * @see https://docs.fastly.com/api/config#healthcheck_a22900c40a2fd59db5028061dc5dfa36
|
68 | * @param {string} version - The current version of a service.
|
69 | * @param {string} name - The name of the healthcheck to delete.
|
70 | * @returns {Promise} The response object representing the completion or failure.
|
71 | */
|
72 | async deleteHealthcheck(version, name) {
|
73 | return this.request.delete(`/service/${this.service_id}/version/${await this.getVersion(version, 'current')}/healthcheck/${name}`);
|
74 | }
|
75 | }
|
76 |
|
77 | module.exports = HealthcheckAPI;
|