use of com.tremolosecurity.unison.openshiftv3.OpenShiftTarget in project OpenUnison by TremoloSecurity.
the class OpenShiftWorkflows method generateWorkflows.
@Override
public List<Map<String, String>> generateWorkflows(WorkflowType wf, ConfigManager cfg, HashMap<String, Attribute> params) throws ProvisioningException {
ArrayList<Map<String, String>> wfData = new ArrayList<Map<String, String>>();
String targetName = params.get("target").getValues().get(0);
HashSet<String> nameFilter = new HashSet<String>();
Attribute attr = params.get("filter");
if (attr != null) {
nameFilter.addAll(attr.getValues());
}
OpenShiftTarget target = (OpenShiftTarget) cfg.getProvisioningEngine().getTarget(targetName).getProvider();
String kind = params.get("kind").getValues().get(0);
try {
String token = target.getAuthToken();
HttpCon con = target.createClient();
try {
String json = target.callWS(token, con, kind);
Gson gson = new Gson();
TypeToken<com.tremolosecurity.unison.openshiftv3.model.List<Item>> tokenType = new TypeToken<com.tremolosecurity.unison.openshiftv3.model.List<Item>>() {
};
com.tremolosecurity.unison.openshiftv3.model.List<Item> list = gson.fromJson(json, tokenType.getType());
for (Item item : list.getItems()) {
HashMap<String, String> wfParams = new HashMap<String, String>();
String name = (String) item.getMetadata().get("name");
if (nameFilter.contains(name)) {
continue;
}
wfParams.put("name", name);
if (item.getMetadata().containsKey("annotations")) {
com.google.gson.internal.LinkedTreeMap annotations = (com.google.gson.internal.LinkedTreeMap) item.getMetadata().get("annotations");
for (Object key : annotations.keySet()) {
String keyName = (String) key;
keyName = keyName.replace("-", "_");
keyName = keyName.replace(".", "_");
wfParams.put((String) keyName, (String) annotations.get(key));
}
}
if (item.getMetadata().containsKey("labels")) {
com.google.gson.internal.LinkedTreeMap annotations = (com.google.gson.internal.LinkedTreeMap) item.getMetadata().get("labels");
for (Object key : annotations.keySet()) {
String keyName = (String) key;
keyName = keyName.replace("-", "_");
keyName = keyName.replace(".", "_");
wfParams.put((String) keyName, (String) annotations.get(key));
}
}
wfData.add(wfParams);
}
} finally {
con.getBcm().close();
con.getHttp().close();
}
} catch (Exception e) {
throw new ProvisioningException("Could not load", e);
}
return wfData;
}
use of com.tremolosecurity.unison.openshiftv3.OpenShiftTarget in project OpenUnison by TremoloSecurity.
the class WorkflowListClusters method generateWorkflows.
@Override
public List<Map<String, String>> generateWorkflows(WorkflowType wf, ConfigManager cfg, HashMap<String, Attribute> params) throws ProvisioningException {
List<TargetType> targets = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getTargets().getTarget();
List<Map<String, String>> k8sTargets = new ArrayList<Map<String, String>>();
for (TargetType tt : targets) {
if (tt.getClassName().equalsIgnoreCase("com.tremolosecurity.unison.openshiftv3.OpenShiftTarget")) {
OpenShiftTarget target = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(tt.getName()).getProvider();
Map<String, String> wfParams = new HashMap<String, String>();
wfParams.put("cluster", tt.getName());
wfParams.put("clusterlabel", target.getLabel());
k8sTargets.add(wfParams);
}
}
return k8sTargets;
}
use of com.tremolosecurity.unison.openshiftv3.OpenShiftTarget in project OpenUnison by TremoloSecurity.
the class DeleteObject method execute.
@Override
public void execute(ConfigManager configManager, JobExecutionContext context) throws ProvisioningException {
if (configManager == null || configManager.getProvisioningEngine() == null) {
logger.warn("System not fully initialized");
return;
}
String target = context.getJobDetail().getJobDataMap().getString("target");
String uri = context.getJobDetail().getJobDataMap().getString("uri");
OpenShiftTarget os = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(target).getProvider();
HttpCon con = null;
try {
con = os.createClient();
String token = os.getAuthToken();
os.callWSDelete(token, con, uri);
} catch (Exception e) {
throw new ProvisioningException("Could not clear object", e);
} finally {
if (con != null) {
con.getBcm().close();
try {
con.getHttp().close();
} catch (IOException e) {
logger.warn("Could not close connection", e);
}
}
}
}
Aggregations