Search in sources :

Example 46 with ClusterProfile

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);
}
Also used : ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 47 with 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);
}
Also used : ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 48 with ClusterProfile

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);
}
Also used : ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 49 with ClusterProfile

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));
    }
}
Also used : ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 50 with 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;
        }
    }
}
Also used : Agent(com.thoughtworks.go.config.Agent) ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Aggregations

ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)69 Test (org.junit.jupiter.api.Test)39 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)32 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)14 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)12 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)10 ClusterProfiles (com.thoughtworks.go.config.elastic.ClusterProfiles)8 Username (com.thoughtworks.go.server.domain.Username)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ElasticConfig (com.thoughtworks.go.config.elastic.ElasticConfig)6 Capabilities (com.thoughtworks.go.plugin.domain.elastic.Capabilities)6 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)5 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)5 JobAgentMetadata (com.thoughtworks.go.domain.JobAgentMetadata)4 ElasticAgentInformation (com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation)4 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)4 GoCipher (com.thoughtworks.go.security.GoCipher)4