azdev-automation
Version:
Azure DevOps automation framework enables access control automation of projects, pipelines and repositories configuration in Azure DevOps Services
84 lines (83 loc) • 2.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EndpointHelper = void 0;
class EndpointHelper {
constructor(azdevClient, logger) {
this.debugLogger = logger.extend(this.constructor.name);
this.azdevClient = azdevClient;
}
async getServiceEndpoints(projectName) {
const debug = this.debugLogger.extend(this.getServiceEndpoints.name);
let results = [];
const existingServiceEndpoints = await this.azdevClient.get(`${projectName}/_apis/serviceendpoint/endpoints`);
if (existingServiceEndpoints || existingServiceEndpoints.value.length !== 0) {
results = existingServiceEndpoints.value;
}
debug(`Found <${projectName}> project <${results.length}> service connection(s)`);
return results;
}
async createGenericServiceEndpoint(name, url, description, projectName, projectId) {
const debug = this.debugLogger.extend(this.createGenericServiceEndpoint.name);
const body = {
name,
description,
type: "generic",
url,
authorization: {
parameters: {
username: "",
password: "",
},
scheme: "UsernamePassword",
},
isShared: false,
isReady: true,
serviceEndpointProjectReferences: [
{
projectReference: {
name: projectName,
id: projectId,
},
name,
},
],
};
const result = await this.azdevClient.post("_apis/serviceendpoint/endpoints", "7.1-preview.4", body);
debug(result);
return result;
}
async fakeServiceEndpoint(projectName, projectId) {
const debug = this.debugLogger.extend(this.fakeServiceEndpoint.name);
const body = {
name: "",
description: "",
type: "generic",
url: "",
authorization: {
parameters: {
username: "",
password: "",
},
scheme: "UsernamePassword",
},
isShared: false,
isReady: true,
serviceEndpointProjectReferences: [
{
projectReference: {
name: projectName,
id: projectId,
},
name: "",
},
],
};
try {
const result = await this.azdevClient.postNoRetry("_apis/serviceendpoint/endpoints", "7.1-preview.4", body);
}
catch {
debug("Must have initialized fake service endpoint");
}
}
}
exports.EndpointHelper = EndpointHelper;