use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.
the class LoadResultGroupsFromK8s method modifyObject.
@Override
public void modifyObject(TremoloType cfg, JSONObject item) throws ProvisioningException {
String rawJson = item.toJSONString();
StringBuffer b = new StringBuffer();
b.setLength(0);
OpenUnisonConfigLoader.integrateIncludes(b, rawJson);
try {
JSONObject newRoot = (JSONObject) new JSONParser().parse(b.toString());
JSONObject metadata = (JSONObject) newRoot.get("metadata");
if (metadata == null) {
throw new ProvisioningException("No metadata");
}
String name = (String) metadata.get("name");
logger.info("modifying result group " + name);
ResultGroupType rgt = this.createResultGroup(newRoot, name);
ResultGroupType rgtToRemove = null;
for (ResultGroupType rgtCheck : cfg.getResultGroups().getResultGroup()) {
if (rgtCheck.getName().equalsIgnoreCase(name)) {
rgtToRemove = rgtCheck;
break;
}
}
if (rgtToRemove != null) {
cfg.getResultGroups().getResultGroup().remove(rgtToRemove);
}
cfg.getResultGroups().getResultGroup().add(rgt);
GlobalEntries.getGlobalEntries().getConfigManager().addResultGroup(rgt);
} catch (ParseException e) {
throw new ProvisioningException("Could not parse resultgroup", e);
}
}
use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.
the class LoadResultGroupsFromK8s method deleteObject.
@Override
public void deleteObject(TremoloType cfg, JSONObject item) throws ProvisioningException {
JSONObject metadata = (JSONObject) item.get("metadata");
if (metadata == null) {
throw new ProvisioningException("No metadata");
}
String name = (String) metadata.get("name");
logger.info("Deleting result group " + name);
ResultGroupType rgtToRemove = null;
for (ResultGroupType rgtCheck : cfg.getResultGroups().getResultGroup()) {
if (rgtCheck.getName().equalsIgnoreCase(name)) {
rgtToRemove = rgtCheck;
break;
}
}
if (rgtToRemove != null) {
cfg.getResultGroups().getResultGroup().remove(rgtToRemove);
GlobalEntries.getGlobalEntries().getConfigManager().removeResultGroup(rgtToRemove);
}
}
use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.
the class K8sProjectCheck method createTremoloUser.
@Override
public String createTremoloUser(NewUserRequest newUser, List<String> errors, AuthInfo userData) throws ProvisioningException {
if (errors.size() == 0) {
String targetName = newUser.getAttributes().get("cluster");
if (targetName == null) {
targetName = this.targetName;
}
OpenShiftTarget target = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(targetName).getProvider();
HttpCon con = null;
try {
String token = target.getAuthToken();
con = target.createClient();
if (target.isObjectExistsByName(token, con, "/api/v1/namespaces", newUser.getAttributes().get(this.projectAttributeName))) {
errors.add("Namespace name already exists");
return "";
}
} catch (Exception e) {
throw new ProvisioningException("Could not check if namespace exists", e);
} finally {
if (con != null) {
try {
con.getHttp().close();
} catch (IOException e) {
// doesn't matter
}
con.getBcm().close();
}
}
if (target.getGitUrl() != null && !target.getGitUrl().isEmpty()) {
String gitUrlForNs = newUser.getAttributes().get("gitUrl");
String sshPrivKey = newUser.getAttributes().get("gitSshKey");
if (gitUrlForNs == null || gitUrlForNs.isEmpty()) {
errors.add("Git URL is required for clusters configured to use git");
}
if (sshPrivKey == null || sshPrivKey.isEmpty()) {
errors.add("Git SSH Private Key is required for clusters configured to use git");
}
if (errors.size() > 0) {
return "";
}
GitUtils gitUtil = new GitUtils(gitUrlForNs, sshPrivKey);
try {
gitUtil.checkOut();
} catch (Throwable t) {
logger.warn("Could not checkout '" + gitUrlForNs + "'", t);
errors.add(t.getMessage());
} finally {
gitUtil.cleanup();
}
}
return this.workflowName;
} else {
return "";
}
}
use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.
the class LoadConfigMap method doTask.
@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
try {
logger.info("Loading " + this.target + "." + this.namespace + "." + this.configmap);
Map<String, String> cm = K8sUtils.loadConfigMap(target, namespace, configmap);
logger.info("map : " + cm.toString());
for (String wfname : mapping.keySet()) {
logger.info("wfname : " + wfname);
String cmname = this.mapping.get(wfname);
logger.info("cmname : " + cmname);
String cmval = cm.get(cmname);
logger.info("cmval : " + cmval);
if (cmval == null) {
StringBuilder sb = new StringBuilder();
sb.append("Unable to find key '").append(cmname).append("' in ").append(namespace).append(".").append(configmap);
logger.warn(sb.toString());
} else {
logger.info("putting " + wfname + " - " + cmval);
request.put(wfname, cmval);
}
}
} catch (Exception e) {
throw new ProvisioningException("Could not load configmap " + this.configmap + " from " + this.namespace);
}
return true;
}
use of com.tremolosecurity.provisioning.core.ProvisioningException in project OpenUnison by TremoloSecurity.
the class JavaScriptRegister method init.
@Override
public void init(ScaleJSRegisterConfig registerConfig) throws ProvisioningException {
initCompleted = false;
Context context = Context.newBuilder("js").allowAllAccess(true).build();
globals = new HashMap<String, Object>();
context.getBindings("js").putMember("globals", globals);
try {
Attribute attr = registerConfig.getCustomSubmissionConfig().get("javaScript");
if (attr == null) {
logger.error("javaScript not set");
return;
}
this.javaScript = attr.getValues().get(0);
globals = new HashMap<String, Object>();
context.getBindings("js").putMember("globals", globals);
Value val = context.eval("js", this.javaScript);
Value init = context.getBindings("js").getMember("init");
if (init == null || !init.canExecute()) {
throw new ProvisioningException("init function must be defined with one paramter");
}
Value doFilter = context.getBindings("js").getMember("createTremoloUser");
if (doFilter == null || !doFilter.canExecute()) {
throw new ProvisioningException("createTremoloUser function must be defined with three paramters");
}
doFilter = context.getBindings("js").getMember("setWorkflowParameters");
if (doFilter == null || !doFilter.canExecute()) {
throw new ProvisioningException("setWorkflowParameters function must be defined with three paramters");
}
init.executeVoid(registerConfig);
initCompleted = true;
} catch (Throwable t) {
logger.error("Could not initialize javascript filter", t);
return;
} finally {
if (context != null) {
context.close();
}
}
}
Aggregations