UNPKG

18.2 kBJavaScriptView Raw
1"use strict";
2/*
3 * ---------------------------------------------------------
4 * Copyright(C) Microsoft Corporation. All rights reserved.
5 * ---------------------------------------------------------
6 *
7 * ---------------------------------------------------------
8 * Generated file, DO NOT EDIT
9 * ---------------------------------------------------------
10 */
11var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13 return new (P || (P = Promise))(function (resolve, reject) {
14 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17 step((generator = generator.apply(thisArg, _arguments || [])).next());
18 });
19};
20Object.defineProperty(exports, "__esModule", { value: true });
21exports.PolicyApi = void 0;
22const basem = require("./ClientApiBases");
23const PolicyInterfaces = require("./interfaces/PolicyInterfaces");
24class PolicyApi extends basem.ClientApiBase {
25 constructor(baseUrl, handlers, options) {
26 super(baseUrl, handlers, 'node-Policy-api', options);
27 }
28 /**
29 * Create a policy configuration of a given policy type.
30 *
31 * @param {PolicyInterfaces.PolicyConfiguration} configuration - The policy configuration to create.
32 * @param {string} project - Project ID or project name
33 */
34 createPolicyConfiguration(configuration, project) {
35 return __awaiter(this, void 0, void 0, function* () {
36 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
37 let routeValues = {
38 project: project
39 };
40 try {
41 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "dad91cbe-d183-45f8-9c6e-9c1164472121", routeValues);
42 let url = verData.requestUrl;
43 let options = this.createRequestOptions('application/json', verData.apiVersion);
44 let res;
45 res = yield this.rest.create(url, configuration, options);
46 let ret = this.formatResponse(res.result, PolicyInterfaces.TypeInfo.PolicyConfiguration, false);
47 resolve(ret);
48 }
49 catch (err) {
50 reject(err);
51 }
52 }));
53 });
54 }
55 /**
56 * Delete a policy configuration by its ID.
57 *
58 * @param {string} project - Project ID or project name
59 * @param {number} configurationId - ID of the policy configuration to delete.
60 */
61 deletePolicyConfiguration(project, configurationId) {
62 return __awaiter(this, void 0, void 0, function* () {
63 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
64 let routeValues = {
65 project: project,
66 configurationId: configurationId
67 };
68 try {
69 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "dad91cbe-d183-45f8-9c6e-9c1164472121", routeValues);
70 let url = verData.requestUrl;
71 let options = this.createRequestOptions('application/json', verData.apiVersion);
72 let res;
73 res = yield this.rest.del(url, options);
74 let ret = this.formatResponse(res.result, null, false);
75 resolve(ret);
76 }
77 catch (err) {
78 reject(err);
79 }
80 }));
81 });
82 }
83 /**
84 * Get a policy configuration by its ID.
85 *
86 * @param {string} project - Project ID or project name
87 * @param {number} configurationId - ID of the policy configuration
88 */
89 getPolicyConfiguration(project, configurationId) {
90 return __awaiter(this, void 0, void 0, function* () {
91 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
92 let routeValues = {
93 project: project,
94 configurationId: configurationId
95 };
96 try {
97 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "dad91cbe-d183-45f8-9c6e-9c1164472121", routeValues);
98 let url = verData.requestUrl;
99 let options = this.createRequestOptions('application/json', verData.apiVersion);
100 let res;
101 res = yield this.rest.get(url, options);
102 let ret = this.formatResponse(res.result, PolicyInterfaces.TypeInfo.PolicyConfiguration, false);
103 resolve(ret);
104 }
105 catch (err) {
106 reject(err);
107 }
108 }));
109 });
110 }
111 /**
112 * Get a list of policy configurations in a project.
113 *
114 * @param {string} project - Project ID or project name
115 * @param {string} scope - [Provided for legacy reasons] The scope on which a subset of policies is defined.
116 * @param {string} policyType - Filter returned policies to only this type
117 */
118 getPolicyConfigurations(project, scope, policyType) {
119 return __awaiter(this, void 0, void 0, function* () {
120 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
121 let routeValues = {
122 project: project
123 };
124 let queryValues = {
125 scope: scope,
126 policyType: policyType,
127 };
128 try {
129 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "dad91cbe-d183-45f8-9c6e-9c1164472121", routeValues, queryValues);
130 let url = verData.requestUrl;
131 let options = this.createRequestOptions('application/json', verData.apiVersion);
132 let res;
133 res = yield this.rest.get(url, options);
134 let ret = this.formatResponse(res.result, PolicyInterfaces.TypeInfo.PolicyConfiguration, true);
135 resolve(ret);
136 }
137 catch (err) {
138 reject(err);
139 }
140 }));
141 });
142 }
143 /**
144 * Update a policy configuration by its ID.
145 *
146 * @param {PolicyInterfaces.PolicyConfiguration} configuration - The policy configuration to update.
147 * @param {string} project - Project ID or project name
148 * @param {number} configurationId - ID of the existing policy configuration to be updated.
149 */
150 updatePolicyConfiguration(configuration, project, configurationId) {
151 return __awaiter(this, void 0, void 0, function* () {
152 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
153 let routeValues = {
154 project: project,
155 configurationId: configurationId
156 };
157 try {
158 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "dad91cbe-d183-45f8-9c6e-9c1164472121", routeValues);
159 let url = verData.requestUrl;
160 let options = this.createRequestOptions('application/json', verData.apiVersion);
161 let res;
162 res = yield this.rest.replace(url, configuration, options);
163 let ret = this.formatResponse(res.result, PolicyInterfaces.TypeInfo.PolicyConfiguration, false);
164 resolve(ret);
165 }
166 catch (err) {
167 reject(err);
168 }
169 }));
170 });
171 }
172 /**
173 * Gets the present evaluation state of a policy.
174 *
175 * @param {string} project - Project ID or project name
176 * @param {string} evaluationId - ID of the policy evaluation to be retrieved.
177 */
178 getPolicyEvaluation(project, evaluationId) {
179 return __awaiter(this, void 0, void 0, function* () {
180 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
181 let routeValues = {
182 project: project,
183 evaluationId: evaluationId
184 };
185 try {
186 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "46aecb7a-5d2c-4647-897b-0209505a9fe4", routeValues);
187 let url = verData.requestUrl;
188 let options = this.createRequestOptions('application/json', verData.apiVersion);
189 let res;
190 res = yield this.rest.get(url, options);
191 let ret = this.formatResponse(res.result, PolicyInterfaces.TypeInfo.PolicyEvaluationRecord, false);
192 resolve(ret);
193 }
194 catch (err) {
195 reject(err);
196 }
197 }));
198 });
199 }
200 /**
201 * Requeue the policy evaluation.
202 *
203 * @param {string} project - Project ID or project name
204 * @param {string} evaluationId - ID of the policy evaluation to be retrieved.
205 */
206 requeuePolicyEvaluation(project, evaluationId) {
207 return __awaiter(this, void 0, void 0, function* () {
208 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
209 let routeValues = {
210 project: project,
211 evaluationId: evaluationId
212 };
213 try {
214 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "46aecb7a-5d2c-4647-897b-0209505a9fe4", routeValues);
215 let url = verData.requestUrl;
216 let options = this.createRequestOptions('application/json', verData.apiVersion);
217 let res;
218 res = yield this.rest.update(url, null, options);
219 let ret = this.formatResponse(res.result, PolicyInterfaces.TypeInfo.PolicyEvaluationRecord, false);
220 resolve(ret);
221 }
222 catch (err) {
223 reject(err);
224 }
225 }));
226 });
227 }
228 /**
229 * Retrieves a list of all the policy evaluation statuses for a specific pull request.
230 *
231 * @param {string} project - Project ID or project name
232 * @param {string} artifactId - A string which uniquely identifies the target of a policy evaluation.
233 * @param {boolean} includeNotApplicable - Some policies might determine that they do not apply to a specific pull request. Setting this parameter to true will return evaluation records even for policies which don't apply to this pull request.
234 * @param {number} top - The number of policy evaluation records to retrieve.
235 * @param {number} skip - The number of policy evaluation records to ignore. For example, to retrieve results 101-150, set top to 50 and skip to 100.
236 */
237 getPolicyEvaluations(project, artifactId, includeNotApplicable, top, skip) {
238 return __awaiter(this, void 0, void 0, function* () {
239 if (artifactId == null) {
240 throw new TypeError('artifactId can not be null or undefined');
241 }
242 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
243 let routeValues = {
244 project: project
245 };
246 let queryValues = {
247 artifactId: artifactId,
248 includeNotApplicable: includeNotApplicable,
249 '$top': top,
250 '$skip': skip,
251 };
252 try {
253 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "c23ddff5-229c-4d04-a80b-0fdce9f360c8", routeValues, queryValues);
254 let url = verData.requestUrl;
255 let options = this.createRequestOptions('application/json', verData.apiVersion);
256 let res;
257 res = yield this.rest.get(url, options);
258 let ret = this.formatResponse(res.result, PolicyInterfaces.TypeInfo.PolicyEvaluationRecord, true);
259 resolve(ret);
260 }
261 catch (err) {
262 reject(err);
263 }
264 }));
265 });
266 }
267 /**
268 * Retrieve a specific revision of a given policy by ID.
269 *
270 * @param {string} project - Project ID or project name
271 * @param {number} configurationId - The policy configuration ID.
272 * @param {number} revisionId - The revision ID.
273 */
274 getPolicyConfigurationRevision(project, configurationId, revisionId) {
275 return __awaiter(this, void 0, void 0, function* () {
276 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
277 let routeValues = {
278 project: project,
279 configurationId: configurationId,
280 revisionId: revisionId
281 };
282 try {
283 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "fe1e68a2-60d3-43cb-855b-85e41ae97c95", routeValues);
284 let url = verData.requestUrl;
285 let options = this.createRequestOptions('application/json', verData.apiVersion);
286 let res;
287 res = yield this.rest.get(url, options);
288 let ret = this.formatResponse(res.result, PolicyInterfaces.TypeInfo.PolicyConfiguration, false);
289 resolve(ret);
290 }
291 catch (err) {
292 reject(err);
293 }
294 }));
295 });
296 }
297 /**
298 * Retrieve all revisions for a given policy.
299 *
300 * @param {string} project - Project ID or project name
301 * @param {number} configurationId - The policy configuration ID.
302 * @param {number} top - The number of revisions to retrieve.
303 * @param {number} skip - The number of revisions to ignore. For example, to retrieve results 101-150, set top to 50 and skip to 100.
304 */
305 getPolicyConfigurationRevisions(project, configurationId, top, skip) {
306 return __awaiter(this, void 0, void 0, function* () {
307 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
308 let routeValues = {
309 project: project,
310 configurationId: configurationId
311 };
312 let queryValues = {
313 '$top': top,
314 '$skip': skip,
315 };
316 try {
317 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "fe1e68a2-60d3-43cb-855b-85e41ae97c95", routeValues, queryValues);
318 let url = verData.requestUrl;
319 let options = this.createRequestOptions('application/json', verData.apiVersion);
320 let res;
321 res = yield this.rest.get(url, options);
322 let ret = this.formatResponse(res.result, PolicyInterfaces.TypeInfo.PolicyConfiguration, true);
323 resolve(ret);
324 }
325 catch (err) {
326 reject(err);
327 }
328 }));
329 });
330 }
331 /**
332 * Retrieve a specific policy type by ID.
333 *
334 * @param {string} project - Project ID or project name
335 * @param {string} typeId - The policy ID.
336 */
337 getPolicyType(project, typeId) {
338 return __awaiter(this, void 0, void 0, function* () {
339 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
340 let routeValues = {
341 project: project,
342 typeId: typeId
343 };
344 try {
345 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "44096322-2d3d-466a-bb30-d1b7de69f61f", routeValues);
346 let url = verData.requestUrl;
347 let options = this.createRequestOptions('application/json', verData.apiVersion);
348 let res;
349 res = yield this.rest.get(url, options);
350 let ret = this.formatResponse(res.result, null, false);
351 resolve(ret);
352 }
353 catch (err) {
354 reject(err);
355 }
356 }));
357 });
358 }
359 /**
360 * Retrieve all available policy types.
361 *
362 * @param {string} project - Project ID or project name
363 */
364 getPolicyTypes(project) {
365 return __awaiter(this, void 0, void 0, function* () {
366 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
367 let routeValues = {
368 project: project
369 };
370 try {
371 let verData = yield this.vsoClient.getVersioningData("7.2-preview.1", "policy", "44096322-2d3d-466a-bb30-d1b7de69f61f", routeValues);
372 let url = verData.requestUrl;
373 let options = this.createRequestOptions('application/json', verData.apiVersion);
374 let res;
375 res = yield this.rest.get(url, options);
376 let ret = this.formatResponse(res.result, null, true);
377 resolve(ret);
378 }
379 catch (err) {
380 reject(err);
381 }
382 }));
383 });
384 }
385}
386exports.PolicyApi = PolicyApi;
387PolicyApi.RESOURCE_AREA_ID = "fb13a388-40dd-4a04-b530-013a739c72ef";