use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.
the class DefaultSchedulingContextTest method shouldCreatePermittedAgentContextCorrectly.
@Test
public void shouldCreatePermittedAgentContextCorrectly() throws Exception {
AgentConfig linux = agent("uuid1", "linux");
AgentConfig windows = agent("uuid2", "windows");
windows.disable();
Agents matchingAgents = new Agents(linux, windows);
EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig();
existing.add("firstVar", "firstVal");
existing.add("overriddenVar", "originalVal");
SchedulingContext schedulingContext = new DefaultSchedulingContext("approver", matchingAgents);
schedulingContext = schedulingContext.overrideEnvironmentVariables(existing);
EnvironmentVariablesConfig stageLevel = new EnvironmentVariablesConfig();
stageLevel.add("stageVar", "stageVal");
stageLevel.add("overriddenVar", "overriddenVal");
StageConfig config = StageConfigMother.custom("test", Approval.automaticApproval());
config.setVariables(stageLevel);
SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables());
ReflectionUtil.setField(context, "rerun", true);
SchedulingContext permittedAgentContext = context.permittedAgent("uuid1");
Agents agents = (Agents) ReflectionUtil.getField(permittedAgentContext, "agents");
assertThat(agents.size(), is(1));
assertThat(agents.get(0).getAgentIdentifier().getUuid(), is("uuid1"));
assertThat(permittedAgentContext.isRerun(), is(true));
assertThat(permittedAgentContext.getApprovedBy(), is("approver"));
EnvironmentVariablesConfig environmentVariablesUsed = permittedAgentContext.getEnvironmentVariablesConfig();
assertThat(environmentVariablesUsed.size(), is(3));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("firstVar", "firstVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("overriddenVar", "overriddenVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("stageVar", "stageVal")));
}
use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.
the class DefaultSchedulingContextTest method shouldCreateRerunSchedulingContextCorrectly.
@Test
public void shouldCreateRerunSchedulingContextCorrectly() throws Exception {
AgentConfig linux = agent("uuid1", "linux");
AgentConfig windows = agent("uuid2", "windows");
windows.disable();
Agents matchingAgents = new Agents(linux, windows);
EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig();
existing.add("firstVar", "firstVal");
existing.add("overriddenVar", "originalVal");
SchedulingContext schedulingContext = new DefaultSchedulingContext("approver", matchingAgents);
schedulingContext = schedulingContext.overrideEnvironmentVariables(existing);
EnvironmentVariablesConfig stageLevel = new EnvironmentVariablesConfig();
stageLevel.add("stageVar", "stageVal");
stageLevel.add("overriddenVar", "overriddenVal");
StageConfig config = StageConfigMother.custom("test", Approval.automaticApproval());
config.setVariables(stageLevel);
SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables());
SchedulingContext rerunContext = context.rerunContext();
assertThat(rerunContext.isRerun(), is(true));
assertThat(rerunContext.getApprovedBy(), is("approver"));
Agents agents = (Agents) ReflectionUtil.getField(rerunContext, "agents");
assertThat(agents, is(matchingAgents));
EnvironmentVariablesConfig environmentVariablesUsed = rerunContext.getEnvironmentVariablesConfig();
assertThat(environmentVariablesUsed.size(), is(3));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("firstVar", "firstVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("overriddenVar", "overriddenVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("stageVar", "stageVal")));
}
use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.
the class EnvironmentVariableSqlMapDao method load.
public EnvironmentVariablesConfig load(final Long entityId, final EnvironmentVariableType type) {
List<EnvironmentVariableConfig> result = (List<EnvironmentVariableConfig>) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus transactionStatus) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(EnvironmentVariableConfig.class).add(Restrictions.eq("entityId", entityId)).add(Restrictions.eq("entityType", type.toString())).addOrder(Order.asc("id"));
criteria.setCacheable(true);
return criteria.list();
}
});
for (EnvironmentVariableConfig var : result) {
var.ensureEncrypted();
}
return new EnvironmentVariablesConfig(result);
}
use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.
the class JobPlanXmlViewModelTest method shouldConvertJobPlanToXmlDocument.
@Test
public void shouldConvertJobPlanToXmlDocument() throws IOException, DocumentException {
EnvironmentVariableConfig secureEnvVariable = new EnvironmentVariableConfig(new GoCipher(), "secureVariable", "value2", true);
DefaultJobPlan jobPlan1 = JobInstanceMother.jobPlan("job-1", 1);
jobPlan1.setJobId(10);
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
variables.add("some_var", "blah");
variables.add(secureEnvVariable);
jobPlan1.setVariables(variables);
DefaultJobPlan jobPlan2 = JobInstanceMother.jobPlan("job-2", 1);
jobPlan2.setJobId(11);
JobPlanXmlViewModel jobPlanXmlViewModel = new JobPlanXmlViewModel(ArrayUtil.asList(new WaitingJobPlan(jobPlan1, "envName"), new WaitingJobPlan(jobPlan2, null)));
String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<scheduledJobs>" + "<job name=\"job-1\" id=\"10\">" + "<link rel=\"self\" href=\"http://baseurl/go/tab/build/detail/pipeline/1/stage/1/job-1\"/>" + "<buildLocator>pipeline/1/stage/1/job-1</buildLocator>" + "<environment>envName</environment>" + "<resources><resource><![CDATA[foo]]></resource><resource><![CDATA[bar]]></resource></resources>" + "<environmentVariables><variable name=\"some_var\">blah</variable><variable name=\"secureVariable\">****</variable></environmentVariables>" + "</job>" + "<job name=\"job-2\" id=\"11\">" + "<link rel=\"self\" href=\"http://baseurl/go/tab/build/detail/pipeline/1/stage/1/job-2\"/>" + "<buildLocator>pipeline/1/stage/1/job-2</buildLocator>" + "<resources><resource><![CDATA[foo]]></resource><resource><![CDATA[bar]]></resource></resources>" + "</job>" + "</scheduledJobs>";
Document document = jobPlanXmlViewModel.toXml(new XmlWriterContext("http://baseurl/go", null, null, null, null));
assertEquals(expectedXml, document.asXML());
}
use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.
the class JobXmlViewModelTest method shouldMaskSecureVariables.
@Test
public void shouldMaskSecureVariables() throws IOException, DocumentException {
EnvironmentVariableConfig envVariable = new EnvironmentVariableConfig(null, "stdVariable", "value1", false);
EnvironmentVariableConfig secureEnvVariable = new EnvironmentVariableConfig(new GoCipher(), "secureVariable", "value2", true);
EnvironmentVariablesConfig environmentVariablesConfig = new EnvironmentVariablesConfig();
environmentVariablesConfig.add(envVariable);
environmentVariablesConfig.add(secureEnvVariable);
when(jobPlan.getVariables()).thenReturn(environmentVariablesConfig);
DOMDocument document = (DOMDocument) jobXmlViewModel.toXml(xmlWriterContext);
Assert.assertThat(document.asXML(), containsString("<environmentvariables><variable name=\"stdVariable\"><![CDATA[value1]]></variable><variable name=\"secureVariable\"><![CDATA[****]]></variable></environmentvariables>"));
}
Aggregations