Search in sources :

Example 1 with PipelineGroupVisitor

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

the class CcTrayViewAuthority method groupsAndTheirViewers.

public Map<String, Viewers> groupsAndTheirViewers() {
    final Map<String, Viewers> pipelinesAndViewers = new HashMap<>();
    SecurityConfig security = goConfigService.security();
    final Map<String, Collection<String>> rolesToUsers = rolesToUsers(security);
    final Set<String> superAdmins = namesOf(security.adminsConfig(), rolesToUsers);
    goConfigService.groups().accept(new PipelineGroupVisitor() {

        @Override
        public void visit(PipelineConfigs pipelineConfigs) {
            if (!pipelineConfigs.hasAuthorizationDefined()) {
                pipelinesAndViewers.put(pipelineConfigs.getGroup(), Everyone.INSTANCE);
                return;
            }
            Set<String> pipelineGroupAdmins = namesOf(pipelineConfigs.getAuthorization().getAdminsConfig(), rolesToUsers);
            Set<String> pipelineGroupViewers = namesOf(pipelineConfigs.getAuthorization().getViewConfig(), rolesToUsers);
            Set<String> viewers = new HashSet<>();
            viewers.addAll(superAdmins);
            viewers.addAll(pipelineGroupAdmins);
            viewers.addAll(pipelineGroupViewers);
            pipelinesAndViewers.put(pipelineConfigs.getGroup(), new AllowedViewers(viewers));
        }
    });
    return pipelinesAndViewers;
}
Also used : AllowedViewers(com.thoughtworks.go.domain.cctray.viewers.AllowedViewers) Viewers(com.thoughtworks.go.domain.cctray.viewers.Viewers) PipelineGroupVisitor(com.thoughtworks.go.domain.PipelineGroupVisitor) AllowedViewers(com.thoughtworks.go.domain.cctray.viewers.AllowedViewers)

Example 2 with PipelineGroupVisitor

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

the class GoDashboardCurrentStateLoader method allPipelines.

public List<GoDashboardPipeline> allPipelines(CruiseConfig config) {
    List<String> pipelineNames = CaseInsensitiveString.toStringList(config.getAllPipelineNames());
    PipelineInstanceModels historyForDashboard = loadHistoryForPipelines(pipelineNames);
    LOGGER.debug("Loading permissions from authority");
    final Map<CaseInsensitiveString, Permissions> pipelinesAndTheirPermissions = permissionsAuthority.pipelinesAndTheirPermissions();
    final List<GoDashboardPipeline> pipelines = new ArrayList<>(1024);
    LOGGER.debug("Populating dashboard pipelines");
    config.accept(new PipelineGroupVisitor() {

        @Override
        public void visit(final PipelineConfigs group) {
            group.accept(new PiplineConfigVisitor() {

                @Override
                public void visit(PipelineConfig pipelineConfig) {
                    long start = System.currentTimeMillis();
                    Permissions permissions = permissionsFor(pipelineConfig, pipelinesAndTheirPermissions);
                    pipelines.add(createGoDashboardPipeline(pipelineConfig, permissions, historyForDashboard, group));
                    LOGGER.debug("It took {}ms to process pipeline {}", (System.currentTimeMillis() - start), pipelineConfig.getName());
                }
            });
        }
    });
    LOGGER.debug("Done populating dashboard pipelines");
    this.everLoadedCurrentState = true;
    return pipelines;
}
Also used : PipelineGroupVisitor(com.thoughtworks.go.domain.PipelineGroupVisitor) PipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels) PipelineInstanceModels.createPipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels) Permissions(com.thoughtworks.go.config.security.Permissions) PiplineConfigVisitor(com.thoughtworks.go.domain.PiplineConfigVisitor)

Example 3 with PipelineGroupVisitor

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

the class CcTrayConfigChangeHandler method findAllProjectStatusesForStagesAndJobsIn.

private List<ProjectStatus> findAllProjectStatusesForStagesAndJobsIn(CruiseConfig config) {
    final List<ProjectStatus> projectStatuses = new ArrayList<>();
    final Map<CaseInsensitiveString, Permissions> pipelinesAndTheirPermissions = pipelinePermissionsAuthority.pipelinesAndTheirPermissions();
    config.accept(new PipelineGroupVisitor() {

        @Override
        public void visit(PipelineConfigs group) {
            for (PipelineConfig pipelineConfig : group) {
                Users usersWithViewPermissionsForPipeline = usersWithViewPermissionsFor(pipelineConfig, pipelinesAndTheirPermissions);
                updateProjectStatusForPipeline(usersWithViewPermissionsForPipeline, pipelineConfig, projectStatuses);
            }
        }
    });
    return projectStatuses;
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) ArrayList(java.util.ArrayList) Permissions(com.thoughtworks.go.config.security.Permissions) Users(com.thoughtworks.go.config.security.users.Users) PipelineGroupVisitor(com.thoughtworks.go.domain.PipelineGroupVisitor)

Example 4 with PipelineGroupVisitor

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

the class GoDashboardService method allPipelineGroupsForDashboard.

public List<GoDashboardPipelineGroup> allPipelineGroupsForDashboard(PipelineSelections pipelineSelections, Username user) {
    GoDashboardPipelines allPipelines = cache.allEntries();
    List<GoDashboardPipelineGroup> pipelineGroups = new ArrayList<>();
    goConfigService.groups().accept(new PipelineGroupVisitor() {

        @Override
        public void visit(PipelineConfigs group) {
            GoDashboardPipelineGroup dashboardPipelineGroup = dashboardPipelineGroupFor(group, pipelineSelections, user, allPipelines);
            if (dashboardPipelineGroup.hasPipelines()) {
                pipelineGroups.add(dashboardPipelineGroup);
            }
        }
    });
    return pipelineGroups;
}
Also used : ArrayList(java.util.ArrayList) PipelineConfigs(com.thoughtworks.go.config.PipelineConfigs) PipelineGroupVisitor(com.thoughtworks.go.domain.PipelineGroupVisitor)

Example 5 with PipelineGroupVisitor

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

the class GoConfigPipelinePermissionsAuthority method pipelinesInGroupsAndTheirPermissions.

private Map<CaseInsensitiveString, Permissions> pipelinesInGroupsAndTheirPermissions(PipelineGroups groups) {
    final Map<CaseInsensitiveString, Permissions> pipelinesAndTheirPermissions = new HashMap<>();
    final SecurityConfig security = goConfigService.security();
    final Map<String, Collection<String>> rolesToUsers = rolesToUsers(security);
    final Set<String> superAdminUsers = namesOf(security.adminsConfig(), rolesToUsers);
    final Set<PluginRoleConfig> superAdminPluginRoles = pluginRolesFor(security.adminsConfig().getRoles());
    final boolean hasNoAdminsDefinedAtRootLevel = noSuperAdminsDefined();
    groups.accept(new PipelineGroupVisitor() {

        @Override
        public void visit(PipelineConfigs group) {
            Set<String> viewers = new HashSet<>();
            Set<String> operators = new HashSet<>();
            Set<String> admins = new HashSet<>();
            Set<String> pipelineGroupViewers = namesOf(group.getAuthorization().getViewConfig(), rolesToUsers);
            Set<String> pipelineGroupOperators = namesOf(group.getAuthorization().getOperationConfig(), rolesToUsers);
            Set<String> pipelineGroupAdmins = namesOf(group.getAuthorization().getAdminsConfig(), rolesToUsers);
            Set<PluginRoleConfig> pipelineGroupViewerRoles = pluginRolesFor(group.getAuthorization().getViewConfig().getRoles());
            Set<PluginRoleConfig> pipelineGroupOperatorRoles = pluginRolesFor(group.getAuthorization().getOperationConfig().getRoles());
            Set<PluginRoleConfig> pipelineGroupAdminRoles = pluginRolesFor(group.getAuthorization().getAdminsConfig().getRoles());
            pipelineGroupAdminRoles.addAll(superAdminPluginRoles);
            pipelineGroupOperatorRoles.addAll(pipelineGroupAdminRoles);
            pipelineGroupViewerRoles.addAll(pipelineGroupAdminRoles);
            admins.addAll(superAdminUsers);
            admins.addAll(pipelineGroupAdmins);
            operators.addAll(admins);
            operators.addAll(pipelineGroupOperators);
            viewers.addAll(admins);
            viewers.addAll(pipelineGroupViewers);
            boolean hasNoAuthDefinedAtGroupLevel = !group.hasAuthorizationDefined();
            for (PipelineConfig pipeline : group) {
                if (hasNoAdminsDefinedAtRootLevel) {
                    pipelinesAndTheirPermissions.put(pipeline.name(), new Permissions(Everyone.INSTANCE, Everyone.INSTANCE, Everyone.INSTANCE, Everyone.INSTANCE));
                } else if (hasNoAuthDefinedAtGroupLevel) {
                    AllowedUsers adminUsers = new AllowedUsers(admins, pipelineGroupAdminRoles);
                    pipelinesAndTheirPermissions.put(pipeline.name(), new Permissions(Everyone.INSTANCE, Everyone.INSTANCE, adminUsers, Everyone.INSTANCE));
                } else {
                    AllowedUsers pipelineOperators = pipelineOperators(pipeline, admins, new AllowedUsers(operators, pipelineGroupOperatorRoles), rolesToUsers);
                    Permissions permissions = new Permissions(new AllowedUsers(viewers, pipelineGroupViewerRoles), new AllowedUsers(operators, pipelineGroupOperatorRoles), new AllowedUsers(admins, pipelineGroupAdminRoles), pipelineOperators);
                    pipelinesAndTheirPermissions.put(pipeline.name(), permissions);
                }
            }
        }
    });
    return pipelinesAndTheirPermissions;
}
Also used : AllowedUsers(com.thoughtworks.go.config.security.users.AllowedUsers) PipelineGroupVisitor(com.thoughtworks.go.domain.PipelineGroupVisitor)

Aggregations

PipelineGroupVisitor (com.thoughtworks.go.domain.PipelineGroupVisitor)5 Permissions (com.thoughtworks.go.config.security.Permissions)2 ArrayList (java.util.ArrayList)2 PipelineConfigs (com.thoughtworks.go.config.PipelineConfigs)1 AllowedUsers (com.thoughtworks.go.config.security.users.AllowedUsers)1 Users (com.thoughtworks.go.config.security.users.Users)1 PiplineConfigVisitor (com.thoughtworks.go.domain.PiplineConfigVisitor)1 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)1 AllowedViewers (com.thoughtworks.go.domain.cctray.viewers.AllowedViewers)1 Viewers (com.thoughtworks.go.domain.cctray.viewers.Viewers)1 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)1 PipelineInstanceModels.createPipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels)1