Tag Archives: OpenShift

How to Delete a SSH Key with the OpenShift REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    client.target("https://openshift.redhat.com/broker/rest/user/keys/samplekey").request().delete();

    client.close();
  }

}
Advertisements

How to Update a SSH Key with the OpenShift REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    client.target("https://openshift.redhat.com/broker/rest/user/keys/samplekey").queryParam("type", ...).queryParam("content", ...).request().put(Entity.json(""));

    client.close();
  }

}

How to Get a SSH Key with the OpenShift REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    final Response res = client.target("https://openshift.redhat.com/broker/rest/user/keys/samplekey").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to Add a SSH Key with the OpenShift REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    client.target("https://openshift.redhat.com/broker/rest/user/keys").queryParam("name", ...).queryParam("type", ...).queryParam("content", ...).request().post(Entity.json(""));

    client.close();
  }

}

How to List SSH Keys with the OpenShift REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    final Response res = client.target("https://openshift.redhat.com/broker/rest/user/keys").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to Change the Subscription Plan with the OpenShift REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    client.target("https://openshift.redhat.com/broker/rest/user").queryParam("plan_id", "sampleplan").request().put(Entity.json(""));

    client.close();
  }

}

How to Get a Subscription Plan with the OpenShift REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    final Response res = client.target("https://openshift.redhat.com/broker/rest/plans/sampleplan").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to Delete an User with the OpenShift REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    client.target("https://openshift.redhat.com/broker/rest/user").request().delete();

    client.close();
  }

}

How to Get an User with the OpenShift REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    final Response res = client.target("https://openshift.redhat.com/broker/rest/user").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}

How to Delete a Cartridge from an Application with the OpenShift REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@SuppressWarnings("serial")
@WebServlet(name = "SampleOpenShiftServlet", value = "/")
public final class SampleOpenShiftServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("username", "password"));

    client.target("https://openshift.redhat.com/broker/rest/domains/sampledomain/applications/sampleapplication/cartridges/samplecartridge").request().delete();

    client.close();
  }

}