use of com.tremolosecurity.unison.openshiftv3.model.Response in project OpenUnison by TremoloSecurity.
the class OpenShiftTarget method addUserToGroup.
public void addUserToGroup(String token, HttpCon con, String userName, String groupName, int approvalID, Workflow workflow) throws Exception {
Gson gson = new Gson();
StringBuffer b = new StringBuffer();
b.append("/apis/user.openshift.io/v1/groups/").append(groupName);
String json = this.callWS(token, con, b.toString());
com.tremolosecurity.unison.openshiftv3.model.groups.Group group = gson.fromJson(json, com.tremolosecurity.unison.openshiftv3.model.groups.Group.class);
if (group.getUsers() == null) {
group.setUsers(new HashSet<String>());
}
if (!group.getUsers().contains(userName)) {
group.getUsers().add(userName);
json = gson.toJson(group);
json = this.callWSPut(token, con, b.toString(), json);
Response resp = gson.fromJson(json, Response.class);
if (resp.getKind().equals("Group")) {
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, "group", groupName);
} else {
throw new Exception("Could not add group " + groupName + " to " + userName + " - " + resp.getReason());
}
}
}
Aggregations