UNPKG

@digital-ai/plugin-dai-deploy-backend

Version:

Backend functionalities for the dai-deploy backstage plugin

75 lines (71 loc) 2.43 kB
'use strict'; var apiConfig = require('./apiConfig.cjs.js'); var responseUtil = require('./responseUtil.cjs.js'); class CurrentDeploymentStatusApi { logger; config; constructor(logger, config) { this.logger = logger; this.config = config; } static fromConfig(config, logger) { return new CurrentDeploymentStatusApi(logger, config); } async getCurrentDeploymentStatus(appName, beginDate, endDate, order, pageNumber, resultsPerPage, taskSet) { this.logger?.debug( `Calling Current deployment status api, start from: ${beginDate} to: ${endDate}, in order of ${order}` ); const authCredentials = apiConfig.getCredentials(this.config); const apiUrl = apiConfig.getDeployApiHost(this.config); const requestBody = [ { type: "udm.Application", id: appName } ]; const response = await fetch( `${apiUrl}${apiConfig.CURRENT_DEPLOYMENT_STATUS_API_PATH}?begin=${beginDate}&end=${endDate} &order=${order}&page=${pageNumber}&resultsPerPage=${resultsPerPage}&taskSet=${taskSet}`, { method: "POST", headers: { Authorization: `Basic ${authCredentials}`, "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify(requestBody) } ); if (!response.ok) { await responseUtil.parseErrorResponse(this.logger, response); } const data = await response.json(); const deploymentActiveData = []; data.forEach( (d) => deploymentActiveData.push({ owner: d.owner, state: d.state, startDate: d.startDate, completionDate: d.completionDate, metadata: { version: d.metadata.version, environment: d.metadata.environment, application: d.metadata.application, taskType: d.metadata.taskType }, scheduledDate: d.scheduledDate, detailsRedirectUri: apiConfig.getCurrentTaskDetailsRedirectUri(this.config, d.id), environmentRedirectUri: apiConfig.getEnvironmentRedirectUri( this.config, d.metadata.environment_id ) }) ); return { deploymentStatus: deploymentActiveData, totalCount: Number(response.headers.get("X-Total-Count")) }; } } exports.CurrentDeploymentStatusApi = CurrentDeploymentStatusApi; //# sourceMappingURL=CurrentDeploymentStatusApi.cjs.js.map