use of com.tremolosecurity.config.xml.TargetType in project OpenUnison by TremoloSecurity.
the class LoadTargetsFromK8s method createTarget.
private TargetType createTarget(JSONObject item, String name) throws ProvisioningException {
TargetType target = new TargetType();
target.setName(name);
target.setParams(new TargetConfigType());
HttpCon nonwatchHttp = null;
JSONObject spec = (JSONObject) item.get("spec");
try {
nonwatchHttp = this.k8sWatch.getK8s().createClient();
String token = this.k8sWatch.getK8s().getAuthToken();
StringBuffer b = new StringBuffer();
b.setLength(0);
OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("className"));
target.setClassName(b.toString());
JSONArray params = (JSONArray) spec.get("params");
for (Object o : params) {
JSONObject param = (JSONObject) o;
ParamType pt = new ParamType();
b.setLength(0);
OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("name"));
pt.setName(b.toString());
b.setLength(0);
OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("value"));
pt.setValue(b.toString());
target.getParams().getParam().add(pt);
}
JSONArray secretParams = (JSONArray) spec.get("secretParams");
for (Object o : secretParams) {
JSONObject secretParam = (JSONObject) o;
String paramName = (String) secretParam.get("name");
String secretName = (String) secretParam.get("secretName");
String secretKey = (String) secretParam.get("secretKey");
String secretValue = this.k8sWatch.getSecretValue(secretName, secretKey, token, nonwatchHttp);
ParamType pt = new ParamType();
pt.setName(paramName);
pt.setValue(secretValue);
target.getParams().getParam().add(pt);
}
JSONArray attrs = (JSONArray) spec.get("targetAttributes");
for (Object o : attrs) {
JSONObject attr = (JSONObject) o;
TargetAttributeType ta = new TargetAttributeType();
b.setLength(0);
OpenUnisonConfigLoader.integrateIncludes(b, (String) attr.get("name"));
ta.setName(b.toString());
b.setLength(0);
OpenUnisonConfigLoader.integrateIncludes(b, (String) attr.get("source"));
ta.setSource(b.toString());
ta.setSourceType((String) attr.get("sourceType"));
ta.setTargetType((String) attr.get("targetType"));
target.getTargetAttribute().add(ta);
}
synchronized (this.tremolo.getProvisioning().getTargets().getTarget()) {
int found = -1;
int ii = 0;
for (TargetType tt : this.tremolo.getProvisioning().getTargets().getTarget()) {
if (tt.getName().equals(target.getName())) {
found = ii;
break;
}
ii++;
}
if (found >= 0) {
this.tremolo.getProvisioning().getTargets().getTarget().remove(found);
}
this.tremolo.getProvisioning().getTargets().getTarget().add(target);
}
return target;
} catch (Exception e) {
throw new ProvisioningException("Could not add target '" + name + "'", e);
} finally {
if (nonwatchHttp != null) {
try {
nonwatchHttp.getHttp().close();
} catch (IOException e) {
}
nonwatchHttp.getBcm().close();
}
}
}
use of com.tremolosecurity.config.xml.TargetType in project OpenUnison by TremoloSecurity.
the class LoadTargetsFromK8s method addObject.
@Override
public void addObject(TremoloType cfg, JSONObject item) throws ProvisioningException {
JSONObject metadata = (JSONObject) item.get("metadata");
String name = (String) metadata.get("name");
logger.info("Creating target '" + name + "'");
TargetType target = createTarget(item, name);
this.provisioningEngine.addDynamicTarget(cfgMgr, target);
}
use of com.tremolosecurity.config.xml.TargetType in project OpenUnison by TremoloSecurity.
the class LoadTargetsFromK8s method modifyObject.
@Override
public void modifyObject(TremoloType cfg, JSONObject item) throws ProvisioningException {
JSONObject metadata = (JSONObject) item.get("metadata");
String name = (String) metadata.get("name");
logger.info("Replacing target '" + name + "'");
TargetType target = this.createTarget(item, name);
this.provisioningEngine.replaceTarget(cfgMgr, target);
}
use of com.tremolosecurity.config.xml.TargetType in project OpenUnison by TremoloSecurity.
the class ListClusters method getSourceList.
@Override
public List<NVP> getSourceList(HttpFilterRequest request) throws Exception {
List<TargetType> targets = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getTargets().getTarget();
List<NVP> k8sTargets = new ArrayList<NVP>();
for (TargetType tt : targets) {
if (tt.getClassName().equalsIgnoreCase("com.tremolosecurity.unison.openshiftv3.OpenShiftTarget")) {
OpenShiftTarget target = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(tt.getName()).getProvider();
k8sTargets.add(new NVP(target.getLabel(), tt.getName()));
}
}
return k8sTargets;
}
use of com.tremolosecurity.config.xml.TargetType in project OpenUnison by TremoloSecurity.
the class SendMessageThread method generateTargets.
private void generateTargets(ConfigManager cfgMgr) throws ProvisioningException {
if (cfgMgr.getCfg().getProvisioning() == null) {
return;
}
this.targetIDs = new HashMap<String, Targets>();
Iterator<TargetType> it = cfgMgr.getCfg().getProvisioning().getTargets().getTarget().iterator();
while (it.hasNext()) {
TargetType targetCfg = it.next();
addTarget(cfgMgr, targetCfg);
}
if (cfgMgr.getCfg().getProvisioning().getTargets().getDynamicTargets() != null && cfgMgr.getCfg().getProvisioning().getTargets().getDynamicTargets().isEnabled()) {
DynamicPortalUrlsType dynamicTargets = cfgMgr.getCfg().getProvisioning().getTargets().getDynamicTargets();
String className = dynamicTargets.getClassName();
HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
for (ParamType pt : dynamicTargets.getParams()) {
Attribute attr = cfgAttrs.get(pt.getName());
if (attr == null) {
attr = new Attribute(pt.getName());
cfgAttrs.put(pt.getName(), attr);
}
attr.getValues().add(pt.getValue());
}
try {
DynamicTargets dynTargets = (DynamicTargets) Class.forName(className).newInstance();
dynTargets.loadDynamicTargets(cfgMgr, this, cfgAttrs);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new ProvisioningException("Could not initialize dynamic targets", e);
}
}
}
Aggregations