Search in sources :

Example 36 with OpenShiftTarget

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;
}
Also used : Attribute(com.tremolosecurity.saml.Attribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Item(com.tremolosecurity.unison.openshiftv3.model.Item) GroupItem(com.tremolosecurity.unison.openshiftv3.model.groups.GroupItem) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) TypeToken(com.google.gson.reflect.TypeToken) HashMap(java.util.HashMap) Map(java.util.Map)

Example 37 with OpenShiftTarget

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;
}
Also used : HashMap(java.util.HashMap) TargetType(com.tremolosecurity.config.xml.TargetType) ArrayList(java.util.ArrayList) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget) HashMap(java.util.HashMap) Map(java.util.Map)

Example 38 with OpenShiftTarget

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);
            }
        }
    }
}
Also used : HttpCon(com.tremolosecurity.provisioning.util.HttpCon) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget) IOException(java.io.IOException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException)

Aggregations

OpenShiftTarget (com.tremolosecurity.unison.openshiftv3.OpenShiftTarget)36 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)30 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)27 JSONObject (org.json.simple.JSONObject)18 ArrayList (java.util.ArrayList)13 JSONParser (org.json.simple.parser.JSONParser)13 HashMap (java.util.HashMap)12 IOException (java.io.IOException)11 Workflow (com.tremolosecurity.provisioning.core.Workflow)9 LDAPException (com.novell.ldap.LDAPException)7 List (java.util.List)7 Map (java.util.Map)7 Attribute (com.tremolosecurity.saml.Attribute)6 GitFile (com.tremolosecurity.provisioning.tasks.dataobj.GitFile)5 JSONArray (org.json.simple.JSONArray)4 ParseException (org.json.simple.parser.ParseException)4 Gson (com.google.gson.Gson)3 LDAPEntry (com.novell.ldap.LDAPEntry)3 K8sUser (com.tremolosecurity.myvd.dataObj.K8sUser)3 User (com.tremolosecurity.provisioning.core.User)3