Search in sources :

Example 1 with DomainsResponse

use of com.tremolosecurity.unison.openstack.model.DomainsResponse in project OpenUnison by TremoloSecurity.

the class KeystoneProvisioningTarget method getDomainName.

public String getDomainName(String id) throws ProvisioningException {
    HttpCon con = null;
    try {
        con = this.createClient();
        KSToken token = this.getToken(con);
        StringBuffer b = new StringBuffer();
        b.append(this.url).append("/domains/").append(id);
        String json = this.callWS(token.getAuthToken(), con, b.toString());
        Gson gson = new Gson();
        DomainsResponse resp = gson.fromJson(json, DomainsResponse.class);
        if (resp.getDomain() == null) {
            return null;
        } else {
            return resp.getDomain().getName();
        }
    } catch (Exception e) {
        throw new ProvisioningException("Could not work with keystone", e);
    } finally {
        if (con != null) {
            con.getBcm().shutdown();
        }
    }
}
Also used : HttpCon(com.tremolosecurity.provisioning.util.HttpCon) DomainsResponse(com.tremolosecurity.unison.openstack.model.DomainsResponse) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) KSToken(com.tremolosecurity.unison.openstack.util.KSToken) Gson(com.google.gson.Gson) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException)

Example 2 with DomainsResponse

use of com.tremolosecurity.unison.openstack.model.DomainsResponse in project OpenUnison by TremoloSecurity.

the class KeystoneProvisioningTarget method getDomainID.

public String getDomainID(String token, HttpCon con, String name) throws Exception {
    StringBuffer b = new StringBuffer();
    b.append(this.url).append("/domains?name=").append(URLEncoder.encode(name, "UTF-8"));
    String json = this.callWS(token, con, b.toString());
    Gson gson = new Gson();
    DomainsResponse resp = gson.fromJson(json, DomainsResponse.class);
    if (resp.getDomains().isEmpty()) {
        return null;
    } else {
        return resp.getDomains().get(0).getId();
    }
}
Also used : DomainsResponse(com.tremolosecurity.unison.openstack.model.DomainsResponse) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)2 DomainsResponse (com.tremolosecurity.unison.openstack.model.DomainsResponse)2 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)1 KSToken (com.tremolosecurity.unison.openstack.util.KSToken)1 IOException (java.io.IOException)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1