Search in sources :

Example 1 with ClientAction

use of com.fathomdb.cli.output.ClientAction in project platformlayer by platformlayer.

the class SshItem method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey key = path.resolve(getContext());
    UntypedItem untypedItem = client.getItemUntyped(key, Format.XML);
    InetAddress sshAddress = findSshAddress(client, untypedItem);
    ClientAction action = null;
    if (sshAddress != null) {
        String user = "root";
        ProjectId project = key.getProject();
        if (project == null) {
            project = client.getProject();
        }
        if (project == null) {
            throw new CliException("Cannot determine project");
        }
        String projectKey = project.getKey();
        String serviceKey = "service-" + key.getServiceType().getKey();
        File sshKey = IoUtils.resolve("~/.credentials/ssh/" + projectKey + "/" + serviceKey);
        // Hmmm... user? key?
        action = new ClientAction(ClientAction.ClientActionType.SSH, user + "@" + sshAddress.getHostAddress(), sshKey.getAbsolutePath());
    }
    return action;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) ClientAction(com.fathomdb.cli.output.ClientAction) UntypedItem(org.platformlayer.common.UntypedItem) CliException(com.fathomdb.cli.CliException) ProjectId(org.platformlayer.ids.ProjectId) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) InetAddress(java.net.InetAddress) File(java.io.File)

Example 2 with ClientAction

use of com.fathomdb.cli.output.ClientAction in project platformlayer by platformlayer.

the class OpenItem method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey key = path.resolve(getContext());
    UntypedItem untypedItem = client.getItemUntyped(key, getFormat());
    List<EndpointInfo> endpointList = EndpointInfo.getEndpoints(untypedItem.getTags());
    Set<EndpointInfo> endpoints = Sets.newHashSet(endpointList);
    EndpointInfo bestEndpoint = null;
    for (EndpointInfo candidate : endpoints) {
        if (bestEndpoint == null) {
            bestEndpoint = candidate;
        } else {
            throw new IllegalArgumentException("Cannot choose between: " + bestEndpoint + " and " + candidate);
        }
    }
    ClientAction action = null;
    if (bestEndpoint != null) {
        // TODO: How do we want to do this? A new tag??
        String id = key.getServiceType().getKey() + ":" + key.getItemType().getKey();
        if (id.equals("jenkins:jenkinsService")) {
            action = new ClientAction(ClientAction.ClientActionType.BROWSER, "http://" + bestEndpoint.publicIp + ":" + bestEndpoint.publicIp);
        }
    }
    return action;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) ClientAction(com.fathomdb.cli.output.ClientAction) UntypedItem(org.platformlayer.common.UntypedItem) EndpointInfo(org.platformlayer.core.model.EndpointInfo) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Aggregations

ClientAction (com.fathomdb.cli.output.ClientAction)2 PlatformLayerClient (org.platformlayer.PlatformLayerClient)2 UntypedItem (org.platformlayer.common.UntypedItem)2 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 CliException (com.fathomdb.cli.CliException)1 File (java.io.File)1 InetAddress (java.net.InetAddress)1 EndpointInfo (org.platformlayer.core.model.EndpointInfo)1 ProjectId (org.platformlayer.ids.ProjectId)1