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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations