use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.
the class ClusterProfilePermissionTest method shouldReturnUserPermissibleClusterProfiles.
@Test
void shouldReturnUserPermissibleClusterProfiles() {
cruiseConfig.getElasticConfig().getClusterProfiles().add(new ClusterProfile("dev_cluster", "ecs"));
cruiseConfig.getElasticConfig().getClusterProfiles().add(new ClusterProfile("prod_cluster", "ecs"));
when(securityService.doesUserHasPermissions(SessionUtils.currentUsername(), VIEW, CLUSTER_PROFILE, "dev_cluster", null)).thenReturn(true);
when(securityService.doesUserHasPermissions(SessionUtils.currentUsername(), VIEW, CLUSTER_PROFILE, "prod_cluster", null)).thenReturn(true);
when(securityService.doesUserHasPermissions(SessionUtils.currentUsername(), ADMINISTER, CLUSTER_PROFILE, "dev_cluster", null)).thenReturn(true);
when(securityService.doesUserHasPermissions(SessionUtils.currentUsername(), ADMINISTER, CLUSTER_PROFILE, "prod_cluster", null)).thenReturn(false);
Map<String, Object> permissions = permission.permissions(username);
Map<String, Object> clusterProfile = new LinkedHashMap<>();
clusterProfile.put("view", asList("dev_cluster", "prod_cluster"));
clusterProfile.put("administer", asList("dev_cluster"));
assertThat(permissions).isEqualTo(clusterProfile);
}
use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.
the class ElasticAgentProfilePermissionTest method shouldReturnEmptyListWhenUserHasNoPermissionsOnElasticAgentProfiles.
@Test
void shouldReturnEmptyListWhenUserHasNoPermissionsOnElasticAgentProfiles() {
cruiseConfig.getElasticConfig().getClusterProfiles().add(new ClusterProfile("dev_cluster", "ecs"));
cruiseConfig.getElasticConfig().getClusterProfiles().add(new ClusterProfile("prod_cluster", "ecs"));
cruiseConfig.getElasticConfig().getProfiles().add(new ElasticProfile("build-agent", "dev_cluster"));
cruiseConfig.getElasticConfig().getProfiles().add(new ElasticProfile("deploy-agent", "prod_cluster"));
Map<String, Object> permissions = permission.permissions(username);
Map<String, Object> elasticAgentProfile = new LinkedHashMap<>();
elasticAgentProfile.put("view", Collections.emptyList());
elasticAgentProfile.put("administer", Collections.emptyList());
assertThat(permissions).isEqualTo(elasticAgentProfile);
}
use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.
the class ElasticAgentProfilePermissionTest method shouldReturnUserPermissibleElasticAgentProfiles.
@Test
void shouldReturnUserPermissibleElasticAgentProfiles() {
cruiseConfig.getElasticConfig().getClusterProfiles().add(new ClusterProfile("dev_cluster", "ecs"));
cruiseConfig.getElasticConfig().getClusterProfiles().add(new ClusterProfile("prod_cluster", "ecs"));
cruiseConfig.getElasticConfig().getProfiles().add(new ElasticProfile("build-agent", "dev_cluster"));
cruiseConfig.getElasticConfig().getProfiles().add(new ElasticProfile("deploy-agent", "prod_cluster"));
when(securityService.doesUserHasPermissions(SessionUtils.currentUsername(), VIEW, ELASTIC_AGENT_PROFILE, "build-agent", "dev_cluster")).thenReturn(true);
when(securityService.doesUserHasPermissions(SessionUtils.currentUsername(), VIEW, ELASTIC_AGENT_PROFILE, "deploy-agent", "prod_cluster")).thenReturn(true);
when(securityService.doesUserHasPermissions(SessionUtils.currentUsername(), ADMINISTER, ELASTIC_AGENT_PROFILE, "build-agent", "dev_cluster")).thenReturn(true);
when(securityService.doesUserHasPermissions(SessionUtils.currentUsername(), ADMINISTER, ELASTIC_AGENT_PROFILE, "deploy-agent", "prod_cluster")).thenReturn(false);
Map<String, Object> permissions = permission.permissions(username);
Map<String, Object> elasticAgentProfile = new LinkedHashMap<>();
elasticAgentProfile.put("view", Arrays.asList("build-agent", "deploy-agent"));
elasticAgentProfile.put("administer", Arrays.asList("build-agent"));
assertThat(permissions).isEqualTo(elasticAgentProfile);
}
use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.
the class JobInstanceSqlMapDao method save.
@Override
public void save(long jobId, JobPlan jobPlan) {
for (Resource resource : jobPlan.getResources()) {
resourceRepository.saveCopyOf(jobId, resource);
}
for (ArtifactPlan artifactPlan : jobPlan.getArtifactPlans()) {
artifactPlanRepository.saveCopyOf(jobId, artifactPlan);
}
environmentVariableDao.save(jobId, EnvironmentVariableType.Job, jobPlan.getVariables());
if (jobPlan.requiresElasticAgent()) {
ElasticProfile elasticProfile = jobPlan.getElasticProfile();
ClusterProfile clusterProfile = jobPlan.getClusterProfile();
jobAgentMetadataDao.save(new JobAgentMetadata(jobId, elasticProfile, clusterProfile));
}
}
use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.
the class JobController method addElasticAgentInfo.
private void addElasticAgentInfo(JobInstance jobInstance, Map data) {
if (!jobInstance.currentStatus().isActive()) {
return;
}
final JobAgentMetadata jobAgentMetadata = jobAgentMetadataDao.load(jobInstance.getId());
if (jobAgentMetadata == null) {
return;
}
ClusterProfile clusterProfile = jobAgentMetadata.clusterProfile();
if (clusterProfile == null) {
return;
}
final String pluginId = clusterProfile.getPluginId();
final ElasticAgentPluginInfo pluginInfo = elasticAgentMetadataStore.getPluginInfo(pluginId);
if (pluginInfo != null && pluginInfo.getCapabilities().supportsAgentStatusReport()) {
String clusterProfileId = jobAgentMetadata.clusterProfile().getId();
String elasticProfileId = jobAgentMetadata.elasticProfile().getId();
data.put("clusterProfileId", clusterProfileId);
data.put("elasticAgentProfileId", elasticProfileId);
data.put("elasticAgentPluginId", pluginId);
data.put("doesUserHaveViewAccessToStatusReportPage", securityService.doesUserHasPermissions(SessionUtils.currentUsername(), SupportedAction.VIEW, SupportedEntity.ELASTIC_AGENT_PROFILE, elasticProfileId, clusterProfileId));
final Agent agent = agentService.getAgentByUUID(jobInstance.getAgentUuid());
if (agent != null && agent.isElastic()) {
data.put("elasticAgentPluginId", agent.getElasticPluginId());
data.put("elasticAgentId", agent.getElasticAgentId());
return;
}
}
}
Aggregations