Search in sources :

Example 1 with InstanceRefreshInformation

use of com.yahoo.athenz.zts.InstanceRefreshInformation in project athenz by yahoo.

the class InstanceClientRefresh method main.

public static void main(String[] args) throws MalformedURLException, IOException {
    // parse our command line to retrieve required input
    CommandLine cmd = parseCommandLine(args);
    String domainName = cmd.getOptionValue("domain").toLowerCase();
    String serviceName = cmd.getOptionValue("service").toLowerCase();
    String provider = cmd.getOptionValue("provider").toLowerCase();
    String instance = cmd.getOptionValue("instance");
    String dnsSuffix = cmd.getOptionValue("dnssuffix");
    String instanceKeyPath = cmd.getOptionValue("instancekey");
    String ztsUrl = cmd.getOptionValue("ztsurl");
    // now we need to generate our CSR so we can get
    // a TLS certificate for our instance
    PrivateKey instanceKey = Crypto.loadPrivateKey(new File(instanceKeyPath));
    String csr = generateCSR(domainName, serviceName, instance, dnsSuffix, instanceKey);
    if (csr == null) {
        System.err.println("Unable to generate CSR for instance");
        System.exit(1);
    }
    System.out.println("CSR: \n" + csr + "\n");
    // now let's generate our instance refresh object that will be sent
    // to the ZTS Server
    InstanceRefreshInformation info = new InstanceRefreshInformation().setToken(true).setCsr(csr);
    // now contact zts server to request identity for instance
    InstanceIdentity identity = null;
    try (ZTSClient ztsClient = new ZTSClient(ztsUrl)) {
        identity = ztsClient.postInstanceRefreshInformation(provider, domainName, serviceName, instance, info);
    } catch (ZTSClientException ex) {
        System.out.println("Unable to register instance: " + ex.getMessage());
        System.exit(2);
    }
    System.out.println("Identity TLS Certificate: \n" + identity.getX509Certificate());
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) InstanceRefreshInformation(com.yahoo.athenz.zts.InstanceRefreshInformation) PrivateKey(java.security.PrivateKey) ZTSClient(com.yahoo.athenz.zts.ZTSClient) ZTSClientException(com.yahoo.athenz.zts.ZTSClientException) DERIA5String(org.bouncycastle.asn1.DERIA5String) File(java.io.File) InstanceIdentity(com.yahoo.athenz.zts.InstanceIdentity)

Aggregations

InstanceIdentity (com.yahoo.athenz.zts.InstanceIdentity)1 InstanceRefreshInformation (com.yahoo.athenz.zts.InstanceRefreshInformation)1 ZTSClient (com.yahoo.athenz.zts.ZTSClient)1 ZTSClientException (com.yahoo.athenz.zts.ZTSClientException)1 File (java.io.File)1 PrivateKey (java.security.PrivateKey)1 CommandLine (org.apache.commons.cli.CommandLine)1 DERIA5String (org.bouncycastle.asn1.DERIA5String)1