Skip to content

Commit

Permalink
Remove unnecessary old config logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlwilson committed Oct 29, 2023
1 parent 3324292 commit 7f6bc30
Show file tree
Hide file tree
Showing 80 changed files with 165 additions and 1,780 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ public class Authorization implements Validatable, ParamsAttributeAware, ConfigO

private final ConfigErrors configErrors = new ConfigErrors();
public static final String NAME = "name";
public static final String ALLOW_GROUP_ADMINS="allowGroupAdmins";
public static final String ALLOW_GROUP_ADMINS = "allowGroupAdmins";
public static final String PRIVILEGES = "privileges";
public static final String VALUE = "value";
public static final String PRIVILEGE_TYPE = "privilege_type";
public static final String TYPE = "type";

private ConfigOrigin origin;
Expand All @@ -61,52 +60,70 @@ public void setOrigins(ConfigOrigin origins) {
origin = origins;
}

public static enum UserType {
public enum UserType {
USER {
@Override public Admin makeUser(String name) {
@Override
public Admin makeUser(String name) {
return new AdminUser(new CaseInsensitiveString(name));
}},
}
},
ROLE {
@Override public Admin makeUser(String name) {
@Override
public Admin makeUser(String name) {
return new AdminRole(new CaseInsensitiveString(name));
}};
}
};

abstract public Admin makeUser(String name);
}

public static enum PrivilegeType {
public enum PrivilegeType {
ADMIN {
@Override public AdminsConfig group(Authorization authorization) {
@Override
public AdminsConfig group(Authorization authorization) {
return authorization.getAdminsConfig();
}
@Override public void set(PresentationElement el) {

@Override
public void set(PresentationElement el) {
el.makeAdmin();
}},
}
},
OPERATE {
@Override public AdminsConfig group(Authorization authorization) {
@Override
public AdminsConfig group(Authorization authorization) {
return authorization.getOperationConfig();
}
@Override public void set(PresentationElement el) {

@Override
public void set(PresentationElement el) {
el.makeOperator();
}},
}
},
VIEW {
@Override public AdminsConfig group(Authorization authorization) {
@Override
public AdminsConfig group(Authorization authorization) {
return authorization.getViewConfig();
}
@Override public void set(PresentationElement el) {

@Override
public void set(PresentationElement el) {
el.makeViewer();
}};
}
};

abstract public AdminsConfig group(Authorization authorization);

public abstract void set(PresentationElement el);
}

public static enum PrivilegeState {
public enum PrivilegeState {
ON {
@Override public void apply(AdminsConfig adminsConfig, Admin userOrRole) {
@Override
public void apply(AdminsConfig adminsConfig, Admin userOrRole) {
adminsConfig.add(userOrRole);
}},
}
},
OFF,
DISABLED;

Expand Down Expand Up @@ -204,19 +221,6 @@ public boolean isAllowGroupAdmins() {
return allowGroupAdmins;
}

public List<PrivilegeType> privilagesOfRole(final CaseInsensitiveString roleName){
List<PrivilegeType> result = new ArrayList<>();
if (isRoleAnAdmin(roleName)){
result.add(PrivilegeType.ADMIN);
}
if (isRoleAnOperator(roleName)){
result.add(PrivilegeType.OPERATE);
}
if (isRoleAViewer(roleName)){
result.add(PrivilegeType.VIEW);
}
return result;
}

public void validateTree(ValidationContext validationContext) {
for (Admin admin : getAdminsConfig()) {
Expand All @@ -236,7 +240,6 @@ public void validateTree(ValidationContext validationContext) {

@Override
public void validate(ValidationContext validationContext) {
return;
}

@Override
Expand Down Expand Up @@ -270,7 +273,7 @@ public void setConfigAttributes(Object attributes) {
state.apply(privilegeGroup, admin);
}
//Give default view permission if no checkbox has been checked in the admin UI
if(!(adminsConfig.contains(admin) || operationConfig.contains(admin) || viewConfig.contains(admin))){
if (!(adminsConfig.contains(admin) || operationConfig.contains(admin) || viewConfig.contains(admin))) {
viewConfig.add(admin);
}
}
Expand Down Expand Up @@ -320,21 +323,18 @@ public void removeAllUsagesOfRole(Role role) {

public static class PresentationElement implements Comparable<PresentationElement>, Validatable {
public static final String NAME = "name";
private String name;

public static final String TYPE = "type";
private UserType type;
private final String name;

private final UserType type;

public static final String ADMIN_PRIVILEGE = "admin";
private PrivilegeState adminPrivilege;

public static final String OPERATE_PRIVILEGE = "operate";
private PrivilegeState operatePrivilege;

public static final String VIEW_PRIVILEGE = "view";
private PrivilegeState viewPrivilege;

private ConfigErrors configErrors = new ConfigErrors();
private final ConfigErrors configErrors = new ConfigErrors();


public PresentationElement(String name, UserType type) {
Expand Down Expand Up @@ -447,25 +447,4 @@ private void addPresentationPrivilege(Admin admin, ArrayList<PresentationElement
}
privilegeType.set(el);
}

private boolean isRoleAnAdmin(final CaseInsensitiveString roleName){
return containsRole(roleName, adminsConfig.getRoles());
}

private boolean isRoleAnOperator(final CaseInsensitiveString roleName){
return containsRole(roleName, operationConfig.getRoles());
}

private boolean isRoleAViewer(final CaseInsensitiveString roleName){
return containsRole(roleName, viewConfig.getRoles());
}

private boolean containsRole(final CaseInsensitiveString roleName, List<AdminRole> roles){
for(AdminRole role : roles){
if (role.getName().equals(roleName)){
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/
package com.thoughtworks.go.config;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

import com.thoughtworks.go.config.preprocessor.ClassAttributeCache;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

@Component
public class ConfigCache {

private ClassAttributeCache.FieldCache fieldCache = new ClassAttributeCache.FieldCache();
private final ClassAttributeCache.FieldCache fieldCache = new ClassAttributeCache.FieldCache();

public static boolean isAnnotationPresent(AnnotatedElement element, Class<? extends Annotation> annotationClass) {
return element.isAnnotationPresent(annotationClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
public class ConfigSaveValidationContext implements ValidationContext {
private final Validatable immediateParent;
private final ConfigSaveValidationContext parentContext;
private HashMap<Class, Object> objectOfType;
private HashMap<String, MaterialConfigs> fingerprintToMaterials = null;
private final Map<Class<?>, Object> objectOfType;
private Map<String, MaterialConfigs> fingerprintToMaterials = null;

public ConfigSaveValidationContext(Validatable immediateParent) {
this(immediateParent, null);
Expand Down Expand Up @@ -119,12 +119,8 @@ private <T> T loadFirstOfType(Class<T> klass) {
}

private <T> T getFirstOfType(Class<T> klass) {
Object o = objectOfType.get(klass);
if (o == null) {
o = _getFirstOfType(klass);
objectOfType.put(klass, o);
}
return (T) o;
//noinspection unchecked
return (T) objectOfType.computeIfAbsent(klass, this::_getFirstOfType);
}

private <T> T _getFirstOfType(Class<T> klass) {
Expand All @@ -138,12 +134,14 @@ private <T> T _getFirstOfType(Class<T> klass) {
if (immediateParent == null) {
return null;
} else if (immediateParent.getClass().equals(klass)) {
//noinspection unchecked
return (T) immediateParent;
} else {
// added because of higher hierarchy of configuration types.
// now there are interfaces with more than one implementation
// so when asking for CruiseConfig there are 2 matching classes - BasicCruiseConfig and MergeCruiseConfig
if (klass.isAssignableFrom(immediateParent.getClass())) {
//noinspection unchecked
return (T) immediateParent;
}
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public class ExecTask extends AbstractTask implements CommandTask {
public static final String ARGS = "args";
public static final String ARG_LIST_STRING = "argListString";
public static final String WORKING_DIR = "workingDirectory";
public static final String TIMEOUT = "timeout";
private final String CUSTOM_COMMAND = "Custom Command";
private static final String CUSTOM_COMMAND = "Custom Command";

public ExecTask() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import static org.apache.commons.lang3.StringUtils.isEmpty;

public class GoConfigClassWriter {
private Class<?> aClass;
private ConfigCache configCache;
private final Class<?> aClass;
private final ConfigCache configCache;
private final ConfigElementImplementationRegistry registry;

public GoConfigClassWriter(Class aClass, ConfigCache configCache, final ConfigElementImplementationRegistry registry) {
Expand Down

This file was deleted.

Loading

0 comments on commit 7f6bc30

Please sign in to comment.