UNPKG

azdev-automation

Version:

Azure DevOps automation framework enables access control automation of projects, pipelines and repositories configuration in Azure DevOps Services

74 lines (73 loc) 3.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Automation = void 0; const apifactory_1 = require("./factories/apifactory"); const artifactfactory_1 = require("./factories/artifactfactory"); const automationfactory_1 = require("./factories/automationfactory"); const configurationreader_1 = require("./readers/configurationreader"); const logger_1 = require("./loggers/logger"); class Automation { constructor(endpoint, parameters) { this.endpoint = endpoint; this.parameters = parameters; this.logger = new logger_1.Logger("azdev-automation", false); const apiFactory = new apifactory_1.ApiFactory(this.endpoint.account, this.endpoint.token, this.logger); const artifactFactory = new artifactfactory_1.ArtifactFactory(this.parameters.config, this.parameters.policies, this.parameters.schemas); this.configurationReader = new configurationreader_1.ConfigurationReader(artifactFactory, this.logger); this.automationFactory = new automationfactory_1.AutomationFactory(apiFactory, this.logger); } async run() { const projectUpdater = await this.automationFactory.createProjectUpdater(); const buildUpdater = await this.automationFactory.createBuildUpdater(); const releaseUpdater = await this.automationFactory.createReleaseUpdater(); const repositoryUpdater = await this.automationFactory.createRepositoryUpdater(); const workUpdater = await this.automationFactory.createWorkUpdater(); const endpointUpdater = await this.automationFactory.createEndpointUpdater(); const configuration = await this.configurationReader.read(); for (const project of configuration) { this.logger.log(`Configuring <${project.name}> project automation`); let targetProject = await projectUpdater.getProject(project.name); if (targetProject) { if (this.parameters.projectSetup) { targetProject = await projectUpdater.updateProject(project); } } else { if (this.parameters.projectSetup) { targetProject = await projectUpdater.createProject(project); } else { throw new Error(`Target project <${project.name}> not found`); } } // Features first time initialization is required for // Related policies to work correctly (permissions, etc) await releaseUpdater.initialize(targetProject.name); await endpointUpdater.initialize(targetProject.name, targetProject.id); if (this.parameters.accessPermissions) { if (project.permissions.project) { await projectUpdater.updatePermissions(targetProject, project.permissions.project); } if (project.permissions.build) { await buildUpdater.updatePermissions(targetProject, project.permissions.build); } if (project.permissions.release) { await releaseUpdater.updatePermissions(targetProject, project.permissions.release); } if (project.permissions.repository) { await repositoryUpdater.updatePermissions(targetProject, project.permissions.repository); } if (project.permissions.work) { await workUpdater.updatePermissions(targetProject, project.permissions.work); } } if (this.parameters.branchPolicies) { throw new Error("Feature not implemented"); } if (this.parameters.serviceConnections) { throw new Error("Feature not implemented"); } } } } exports.Automation = Automation;