1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | exports.TaskAgentApi = void 0;
|
13 | const taskagentbasem = require("./TaskAgentApiBase");
|
14 | const url = require("url");
|
15 | class TaskAgentApi extends taskagentbasem.TaskAgentApiBase {
|
16 | constructor(baseUrl, handlers, options) {
|
17 | super(baseUrl, handlers, options);
|
18 |
|
19 | this._handlers = handlers;
|
20 | this._options = options;
|
21 | }
|
22 | |
23 |
|
24 |
|
25 |
|
26 | deleteTaskDefinition(taskId) {
|
27 | let promise = this.vsoClient.beginGetLocation("distributedtask", "60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd")
|
28 | .then((location) => {
|
29 | if (location) {
|
30 |
|
31 | return super.deleteTaskDefinition(taskId);
|
32 | }
|
33 | else {
|
34 |
|
35 | var fallbackClient = this._getFallbackClient(this.baseUrl);
|
36 | if (!fallbackClient) {
|
37 |
|
38 | throw new Error("Failed to find api location for area: distributedtask id: 60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd");
|
39 | }
|
40 | else {
|
41 |
|
42 | return fallbackClient.deleteTaskDefinition(taskId);
|
43 | }
|
44 | }
|
45 | });
|
46 | return promise;
|
47 | }
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | getTaskContentZip(taskId, versionString, visibility, scopeLocal) {
|
56 | let promise = this.vsoClient.beginGetLocation("distributedtask", "60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd")
|
57 | .then((location) => {
|
58 | if (location) {
|
59 |
|
60 | return super.getTaskContentZip(taskId, versionString, visibility, scopeLocal);
|
61 | }
|
62 | else {
|
63 |
|
64 | var fallbackClient = this._getFallbackClient(this.baseUrl);
|
65 | if (!fallbackClient) {
|
66 |
|
67 | throw new Error("Failed to find api location for area: distributedtask id: 60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd");
|
68 | }
|
69 | else {
|
70 |
|
71 | return fallbackClient.getTaskContentZip(taskId, versionString, visibility, scopeLocal);
|
72 | }
|
73 | }
|
74 | });
|
75 | return promise;
|
76 | }
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | getTaskDefinition(taskId, versionString, visibility, scopeLocal) {
|
85 | let promise = this.vsoClient.beginGetLocation("distributedtask", "60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd")
|
86 | .then((location) => {
|
87 | if (location) {
|
88 |
|
89 | return super.getTaskDefinition(taskId, versionString, visibility, scopeLocal);
|
90 | }
|
91 | else {
|
92 |
|
93 | var fallbackClient = this._getFallbackClient(this.baseUrl);
|
94 | if (!fallbackClient) {
|
95 |
|
96 | throw new Error("Failed to find api location for area: distributedtask id: 60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd");
|
97 | }
|
98 | else {
|
99 |
|
100 | return fallbackClient.getTaskDefinition(taskId, versionString, visibility, scopeLocal);
|
101 | }
|
102 | }
|
103 | });
|
104 | return promise;
|
105 | }
|
106 | |
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | getTaskDefinitions(taskId, visibility, scopeLocal) {
|
113 | let promise = this.vsoClient.beginGetLocation("distributedtask", "60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd")
|
114 | .then((location) => {
|
115 | if (location) {
|
116 |
|
117 | return super.getTaskDefinitions(taskId, visibility, scopeLocal);
|
118 | }
|
119 | else {
|
120 |
|
121 | var fallbackClient = this._getFallbackClient(this.baseUrl);
|
122 | if (!fallbackClient) {
|
123 |
|
124 | throw new Error("Failed to find api location for area: distributedtask id: 60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd");
|
125 | }
|
126 | else {
|
127 |
|
128 | return fallbackClient.getTaskDefinitions(taskId, visibility, scopeLocal);
|
129 | }
|
130 | }
|
131 | });
|
132 | return promise;
|
133 | }
|
134 | |
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | uploadTaskDefinition(customHeaders, contentStream, taskId, overwrite) {
|
141 | return __awaiter(this, void 0, void 0, function* () {
|
142 | let routeValues = {
|
143 | taskId: taskId
|
144 | };
|
145 | let queryValues = {
|
146 | overwrite: overwrite,
|
147 | };
|
148 | return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
149 | customHeaders = customHeaders || {};
|
150 | customHeaders["Content-Type"] = "application/octet-stream";
|
151 | try {
|
152 | let verData = yield this.vsoClient.getVersioningData("3.0-preview.1", "distributedtask", "60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd", routeValues, queryValues);
|
153 | let url = verData.requestUrl;
|
154 | let options = this.createRequestOptions('application/json', verData.apiVersion);
|
155 | options.additionalHeaders = customHeaders;
|
156 | let res;
|
157 | res = yield this.rest.uploadStream("PUT", url, contentStream, options);
|
158 | resolve(res.result);
|
159 | }
|
160 | catch (err) {
|
161 | reject(err);
|
162 | }
|
163 | }));
|
164 | });
|
165 | }
|
166 | _getFallbackClient(baseUrl) {
|
167 | if (!this._fallbackClient) {
|
168 | var accountUrl = this._getAccountUrl(baseUrl);
|
169 | if (accountUrl) {
|
170 | this._fallbackClient = new TaskAgentApi(accountUrl, this._handlers, this._options);
|
171 | }
|
172 | }
|
173 | return this._fallbackClient;
|
174 | }
|
175 | _getAccountUrl(collectionUrl) {
|
176 |
|
177 |
|
178 | var purl = url.parse(collectionUrl);
|
179 | if (!purl.protocol || !purl.host) {
|
180 | return null;
|
181 | }
|
182 | var accountUrl = purl.protocol + '//' + purl.host;
|
183 |
|
184 | var splitPath = purl.path.split('/').slice(1);
|
185 | if (splitPath.length === 0 || (splitPath.length === 1 && splitPath[0] === '')) {
|
186 | return null;
|
187 | }
|
188 |
|
189 | if (splitPath[0] === 'tfs' && (splitPath.length === 2 || (splitPath.length === 3 && splitPath[2].length === 0))) {
|
190 |
|
191 | accountUrl += '/' + 'tfs';
|
192 | }
|
193 | else if (splitPath.length === 2 && splitPath[0] === '') {
|
194 |
|
195 | return accountUrl;
|
196 | }
|
197 | else if (splitPath.length > 1) {
|
198 | return null;
|
199 | }
|
200 | return accountUrl;
|
201 | }
|
202 | }
|
203 | exports.TaskAgentApi = TaskAgentApi;
|