This repository has been archived by the owner on Oct 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
161 lines (148 loc) · 4.86 KB
/
index.js
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
/**
* Copyright 2016 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
module.exports = {
container: container,
containerAdd: containerAdd,
containerDelete: containerDelete,
containers: containers,
executeCommand: executeCommand,
info: info,
release: release,
releaseUpdate: releaseUpdate,
scanner: scanner,
scannerUpdate: scannerUpdate
};
const roi = require('roi');
const INFO = '/services/rest/server/';
const CONTAINERS = '/services/rest/server/containers/';
/**
* Returns the Execution Server information.
*
* @instance
* @function info
* @returns {Promise} A promise that will resolve with server information.
*/
function info (options) {
options.endpoint = options.baseUrl + INFO;
return roi.get(options);
}
/**
* This function is used to create a new Container.
*
* @instance
* @param {object} containerRepresentation - An object representing the container.
* @function containerAdd
* @returns {Promise} A promise that will resolve with the new container created.
*/
function containerAdd (options, containerRepresentation) {
options.endpoint = options.baseUrl + CONTAINERS + containerRepresentation['container-id'];
return roi.put(options, containerRepresentation);
}
/**
* This function is used to remove a Conainer.
*
* @instance
* @param {string} id - The ID of the Conainer.
* @function containerDelete
* @returns {Promise} A promise that will resolve with 204 No Content if the delete is successful.
*/
function containerDelete (options, id) {
options.endpoint = options.baseUrl + CONTAINERS + id;
return roi.del(options);
}
/**
* Returns information about the Container.
*
* @instance
* @param {string} id - The ID of the Container.
* @function container
* @returns {Promise} A promise that will resolve with container information.
*/
function container (options, id) {
options.endpoint = options.baseUrl + CONTAINERS + id;
return roi.get(options);
}
/**
* Returns containers.
*
* @instance
* @function containers
* @returns {Promise} A promise that will resolve with containers.
*/
function containers (options) {
options.endpoint = options.baseUrl + CONTAINERS;
return roi.get(options);
}
/**
* Returns the full release id for the Container specified by the id.
*
* @instance
* @param {string} id - The ID of the Container.
* @function release
* @returns {Promise} A promise that will resolve with release information.
*/
function release (options, id) {
options.endpoint = `${options.baseUrl}${CONTAINERS}${id}/release-id`;
return roi.get(options);
}
/**
* Executes operations and commands against the specified Container.
* @instance
* @function releaseUpdate
* @param {string} id - The ID of the Container.
* @param {object} releaseRepresentation - An object representing release.
* @returns {Promise} A promise that will resolve with release information.
*/
function releaseUpdate (options, id, releaseRepresentation) {
options.endpoint = `${options.baseUrl}${CONTAINERS}${id}/release-id`;
return roi.post(options, releaseRepresentation);
}
/**
* Allows you to start or stop a scanner that controls polling for updated Container deployments.
* @instance
* @function scannerUpdate
* @param {string} id - The ID of the Container.
* @param {object} scannerRepresentation - An object representing scanner.
* @returns {Promise} A promise that will resolve with scanner information.
*/
function scannerUpdate (options, id, scannerRepresentation) {
options.endpoint = `${options.baseUrl}${CONTAINERS}${id}/scanner`;
return roi.post(options, scannerRepresentation);
}
/**
* Returns information about the scanner for this Container's automatic updates.
* @instance
* @param {string} id - The ID of the Container.
* @function scanner
* @returns {Promise} A promise that will resolve with release information.
*/
function scanner (options, id) {
options.endpoint = `${options.baseUrl}${CONTAINERS}${id}/scanner`;
return roi.get(options);
}
/**
* Executes operations and commands against the specified Container.
* @instance
* @function executeCommand
* @param {string} id - The ID of the Container.
* @param {object} commandRepresentation - An object representing command(s).
* @returns {Promise} A promise that will resolve with information about executed command(s).
*/
function executeCommand (options, id, commandRepresentation) {
options.endpoint = `${options.baseUrl}${CONTAINERS}instances/${id}`;
return roi.post(options, commandRepresentation);
}