Created
August 24, 2016 16:52
-
-
Save scottpurdy/8c4bbbcd2ec24ed0fc6058ff1209eed1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Numenta Platform for Intelligent Computing (NuPIC) | |
* Copyright (C) 2016, Numenta, Inc. Unless you have purchased from | |
* Numenta, Inc. a separate commercial license for this software code, the | |
* following terms and conditions apply: | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU Affero Public License version 3 as | |
* published by the Free Software Foundation. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
* See the GNU Affero Public License for more details. | |
* | |
* You should have received a copy of the GNU Affero Public License | |
* along with this program. If not, see http://www.gnu.org/licenses. | |
* | |
* http://numenta.org/licenses/ | |
*/ | |
package com.numenta.bamboo.tasks; | |
import com.atlassian.bamboo.build.logger.BuildLogger; | |
import com.atlassian.bamboo.build.logger.interceptors.ErrorMemorisingInterceptor; | |
import com.atlassian.bamboo.build.logger.interceptors.LogMemorisingInterceptor; | |
import com.atlassian.bamboo.configuration.ConfigurationMap; | |
import com.atlassian.bamboo.credentials.CredentialsAccessor; | |
import com.atlassian.bamboo.credentials.CredentialsData; | |
import com.atlassian.bamboo.deployments.execution.DeploymentContext; | |
import com.atlassian.bamboo.deployments.execution.DeploymentTaskContext; | |
import com.atlassian.bamboo.deployments.execution.DeploymentTaskType; | |
import com.atlassian.bamboo.process.ExternalProcessBuilder; | |
import com.atlassian.bamboo.process.ProcessService; | |
import com.atlassian.bamboo.security.EncryptionService; | |
import com.atlassian.bamboo.task.*; | |
import com.atlassian.bamboo.utils.ConfigUtils; | |
import com.atlassian.bamboo.v2.build.agent.capability.CapabilityContext; | |
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned; | |
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport; | |
import com.atlassian.utils.process.ExternalProcess; | |
import com.google.common.base.Preconditions; | |
import org.apache.commons.configuration.XMLConfiguration; | |
import org.apache.commons.io.filefilter.WildcardFileFilter; | |
import org.jetbrains.annotations.NotNull; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import java.io.File; | |
import java.io.FilenameFilter; | |
import java.util.*; | |
/** | |
* Bamboo task used to deploy docker images to quay.io | |
*/ | |
@Scanned | |
public class PythonDeployTask implements DeploymentTaskType { | |
@Autowired | |
private CapabilityContext capabilityContext; | |
@Autowired | |
private ProcessService processService; | |
@Autowired | |
private CredentialsAccessor credentialsAccessor; | |
@Autowired | |
private EncryptionService encryptionService; | |
@Override | |
public TaskResult execute(@NotNull DeploymentTaskContext taskContext) throws TaskException { | |
BuildLogger buildLogger = taskContext.getBuildLogger(); | |
ConfigurationMap config = taskContext.getConfigurationMap(); | |
TaskResultBuilder taskResultBuilder = TaskResultBuilder.newBuilder(taskContext); | |
DeploymentContext deploymentContext = taskContext.getDeploymentContext(); | |
// Configure builder logger | |
ErrorMemorisingInterceptor errorLines = ErrorMemorisingInterceptor.newInterceptor(); | |
buildLogger.getInterceptorStack().add(errorLines); | |
LogMemorisingInterceptor recentLogLines = new LogMemorisingInterceptor(200); | |
buildLogger.getInterceptorStack().add(recentLogLines); | |
buildLogger.addBuildLogEntry("Start executing PyPI deployment task"); | |
// Get PyPI credentials | |
CredentialsData credentialsData = Preconditions.checkNotNull(this.credentialsAccessor.getCredentials(config.getAsLong(NumentaConstants.CFG_PYPI_CREDENTIALS_ID))); | |
XMLConfiguration pypiCredentials = Preconditions.checkNotNull(ConfigUtils.getXmlConfigFromXmlString(credentialsData.getXml())); | |
// Get and validate the credentials | |
String repository = Preconditions.checkNotNull(pypiCredentials.getString(NumentaConstants.PYPI_REPOSITORY)); | |
String username = Preconditions.checkNotNull(pypiCredentials.getString(NumentaConstants.PYPI_USERNAME)); | |
String password = Preconditions.checkNotNull(pypiCredentials.getString(NumentaConstants.PYPI_PASSWORD)); | |
password = this.encryptionService.decrypt(password); | |
// **Then we do the rest of our task-specific stuff using the decrypted credentials** | |
return taskResultBuilder.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment