Search in sources :

Example 1 with EnvironmentVariable

use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.

the class EnvironmentVariableSqlMapDao method load.

public EnvironmentVariables load(final Long entityId, final EnvironmentVariableType type) {
    List<EnvironmentVariable> result = (List<EnvironmentVariable>) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus transactionStatus) {
            Criteria criteria = sessionFactory.getCurrentSession().createCriteria(EnvironmentVariable.class).add(Restrictions.eq("entityId", entityId)).add(Restrictions.eq("entityType", type.toString())).addOrder(Order.asc("id"));
            criteria.setCacheable(true);
            return criteria.list();
        }
    });
    return new EnvironmentVariables(result);
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) EnvironmentVariables(com.thoughtworks.go.domain.EnvironmentVariables) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List) Criteria(org.hibernate.Criteria)

Example 2 with EnvironmentVariable

use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.

the class EnvironmentVariableSqlMapDaoIntegrationTest method shouldSavePlainTextEnvironmentVariable.

@Test
public void shouldSavePlainTextEnvironmentVariable() {
    EnvironmentVariables variables = new EnvironmentVariables();
    String plainText = "plainText";
    String key = "key";
    variables.add(new EnvironmentVariable(key, plainText, false));
    dao.save(1L, Job, variables);
    EnvironmentVariables actual = dao.load(1L, Job);
    assertThat(actual.get(0).getName(), is(key));
    assertThat(actual.get(0).getValue(), is(plainText));
    assertThat(actual.get(0).isSecure(), is(false));
}
Also used : EnvironmentVariables(com.thoughtworks.go.domain.EnvironmentVariables) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) Test(org.junit.Test)

Example 3 with EnvironmentVariable

use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.

the class EnvironmentVariableSqlMapDaoIntegrationTest method shouldSaveSecureEnvironmentVariable.

@Test
public void shouldSaveSecureEnvironmentVariable() {
    EnvironmentVariables variables = new EnvironmentVariables();
    String plainText = "plainText";
    String key = "key";
    variables.add(new EnvironmentVariable(key, plainText, true));
    dao.save(1L, Job, variables);
    EnvironmentVariables actual = dao.load(1L, Job);
    assertThat(actual.get(0).getName(), is(key));
    assertThat(actual.get(0).getValue(), is(plainText));
    assertThat(actual.get(0).isSecure(), is(true));
}
Also used : EnvironmentVariables(com.thoughtworks.go.domain.EnvironmentVariables) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) Test(org.junit.Test)

Example 4 with EnvironmentVariable

use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.

the class EnvironmentVariableSqlMapDaoIntegrationTest method shouldDeleteEnvironmentVariable.

@Test
public void shouldDeleteEnvironmentVariable() throws Exception {
    EnvironmentVariables variables = new EnvironmentVariables();
    String plainText = "plainText";
    String key = "key";
    variables.add(new EnvironmentVariable(key, plainText, false));
    dao.save(1L, Job, variables);
    EnvironmentVariables variableFromDb = dao.load(1L, Job);
    assertThat(variableFromDb.size(), is(1));
    dao.deleteAll(variableFromDb);
    variableFromDb = dao.load(1L, Job);
    assertThat(variableFromDb.size(), is(0));
}
Also used : EnvironmentVariables(com.thoughtworks.go.domain.EnvironmentVariables) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) Test(org.junit.Test)

Example 5 with EnvironmentVariable

use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.

the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithTheProvidedEnvironmentVariables.

@Test
public void shouldScheduleAPipelineWithTheProvidedEnvironmentVariables() throws IOException {
    pipelineConfig.addEnvironmentVariable("ENV_VAR1", "VAL1");
    pipelineConfig.addEnvironmentVariable("ENV_VAR2", "VAL2");
    pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true));
    pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR2", "SECURE_VAL2", true));
    pipelineConfigService.updatePipelineConfig(admin, pipelineConfig, entityHashingService.md5ForEntity(pipelineConfig), new HttpLocalizedOperationResult());
    Integer pipelineCounterBefore = pipelineSqlMapDao.getCounterForPipeline(pipelineName);
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "ENV_VAR1", "overridden_value", false));
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "overridden_secure_value", true));
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline %s accepted", pipelineName)));
    assertThat(result.httpCode(), is(202));
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(true));
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));
    BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
    assertNotNull(buildCause);
    assertThat(buildCause.getApprover(), is(CaseInsensitiveString.str(admin.getUsername())));
    assertThat(buildCause.getMaterialRevisions().findRevisionFor(pipelineConfig.materialConfigs().first()).getLatestRevisionString(), is("s3"));
    assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1"));
    assertThat(buildCause.getVariables().size(), is(2));
    EnvironmentVariable plainTextVariable = (EnvironmentVariable) CollectionUtils.find(buildCause.getVariables(), new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            EnvironmentVariable variable = (EnvironmentVariable) o;
            return variable.getName().equals("ENV_VAR1");
        }
    });
    EnvironmentVariable secureVariable = (EnvironmentVariable) CollectionUtils.find(buildCause.getVariables(), new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            EnvironmentVariable variable = (EnvironmentVariable) o;
            return variable.getName().equals("SECURE_VAR1");
        }
    });
    assertThat(plainTextVariable.getValue(), is("overridden_value"));
    assertThat(secureVariable.getValue(), is("overridden_secure_value"));
    assertThat(secureVariable.isSecure(), is(true));
    scheduleService.autoSchedulePipelinesFromRequestBuffer();
    Integer pipelineCounterAfter = pipelineSqlMapDao.getCounterForPipeline(pipelineName);
    assertThat(pipelineCounterAfter, is(pipelineCounterBefore + 1));
    BuildCause buildCauseOfLatestRun = pipelineSqlMapDao.findBuildCauseOfPipelineByNameAndCounter(pipelineName, pipelineCounterAfter);
    assertThat(buildCauseOfLatestRun, is(buildCause));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Predicate(org.apache.commons.collections.Predicate) Test(org.junit.Test)

Aggregations

EnvironmentVariable (com.thoughtworks.go.domain.EnvironmentVariable)6 Test (org.junit.Test)5 EnvironmentVariables (com.thoughtworks.go.domain.EnvironmentVariables)4 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)2 GoCipher (com.thoughtworks.go.security.GoCipher)2 PipelineScheduleOptions (com.thoughtworks.go.server.domain.PipelineScheduleOptions)2 MaterialUpdateSuccessfulMessage (com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 Predicate (org.apache.commons.collections.Predicate)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 List (java.util.List)1 Criteria (org.hibernate.Criteria)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1