Example usage for io.vertx.core.json JsonObject put

List of usage examples for io.vertx.core.json JsonObject put

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject put.

Prototype

public JsonObject put(String key, Object value) 

Source Link

Document

Put an Object into the JSON object with the specified key.

Usage

From source file:examples.ConfigVaultExamples.java

License:Apache License

public void example1WithConfig(Vertx vertx) {
    JsonObject vault_config = new JsonObject().put("host", "127.0.0.1") // The host name
            .put("port", 8200) // The port
            .put("ssl", true); // Whether or not SSL is used (disabled by default)

    // Certificates
    PemKeyCertOptions certs = new PemKeyCertOptions().addCertPath("target/vault/config/ssl/client-cert.pem")
            .addKeyPath("target/vault/config/ssl/client-privatekey.pem");
    vault_config.put("pemKeyCertOptions", certs.toJson());

    // Truststore
    JksOptions jks = new JksOptions().setPath("target/vault/config/ssl/truststore.jks");
    vault_config.put("trustStoreOptions", jks.toJson());

    // Path to the secret to read.
    vault_config.put("path", "secret/my-secret");

    ConfigStoreOptions store = new ConfigStoreOptions().setType("vault").setConfig(vault_config);

    ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));
}

From source file:examples.ConfigVaultExamples.java

License:Apache License

public void exampleWithToken(Vertx vertx, String token) {
    JsonObject vault_config = new JsonObject();

    // ...//from www. ja  va  2 s  . co  m

    // Path to the secret to read.
    vault_config.put("path", "secret/my-secret");

    // The token
    vault_config.put("token", token);

    ConfigStoreOptions store = new ConfigStoreOptions().setType("vault").setConfig(vault_config);

    ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));
}

From source file:examples.ConfigVaultExamples.java

License:Apache License

public void exampleWithTokenCreation(Vertx vertx, String token) {
    JsonObject vault_config = new JsonObject();

    // .../*from ww  w . j  a  va2s .  c o m*/

    // Path to the secret to read.
    vault_config.put("path", "secret/my-secret");

    // Configure the token generation

    // Configure the token request (https://www.vaultproject.io/docs/auth/token.html)
    JsonObject tokenRequest = new JsonObject().put("ttl", "1h").put("noDefault", true)

            // The token to use to request the generation (parts of the tokenRequest object)
            .put("token", token);

    vault_config.put("auth-backend", "token") // Indicate the auth backend to use
            .put("renew-window", 5000L) // Renew error margin in ms
            .put("token-request", tokenRequest); // Pass the token generation configuration

    ConfigStoreOptions store = new ConfigStoreOptions().setType("vault").setConfig(vault_config);

    ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));
}

From source file:examples.ConfigVaultExamples.java

License:Apache License

public void exampleWithCerts(Vertx vertx) {
    JsonObject vault_config = new JsonObject();

    // .../*from   w  w  w.ja  va 2  s  .  com*/

    PemKeyCertOptions certs = new PemKeyCertOptions().addCertPath("target/vault/config/ssl/client-cert.pem")
            .addKeyPath("target/vault/config/ssl/client-privatekey.pem");
    vault_config.put("pemKeyCertOptions", certs.toJson());

    PemTrustOptions trust = new PemTrustOptions().addCertPath("target/vault/config/ssl/cert.pem");
    vault_config.put("pemTrustStoreOptions", trust.toJson());

    JksOptions jks = new JksOptions().setPath("target/vault/config/ssl/truststore.jks");
    vault_config.put("trustStoreOptions", jks.toJson());

    vault_config.put("auth-backend", "cert");

    // Path to the secret to read.
    vault_config.put("path", "secret/my-secret");

    ConfigStoreOptions store = new ConfigStoreOptions().setType("vault").setConfig(vault_config);

    ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));
}

From source file:examples.ConfigVaultExamples.java

License:Apache License

public void exampleWithAppRole(Vertx vertx, String appRoleId, String secretId) {
    JsonObject vault_config = new JsonObject();

    // ...// ww  w .j  a  v  a2 s.co m

    vault_config.put("auth-backend", "approle") // Set the auth-backend to approle
            .put("approle", new JsonObject() // Configure the role id and secret it
                    .put("role-id", appRoleId).put("secret-id", secretId));

    // Path to the secret to read.
    vault_config.put("path", "secret/my-secret");

    ConfigStoreOptions store = new ConfigStoreOptions().setType("vault").setConfig(vault_config);

    ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));
}

From source file:examples.ConfigVaultExamples.java

License:Apache License

public void exampleWithUserPass(Vertx vertx, String username, String password) {
    JsonObject vault_config = new JsonObject();

    // ...//from  ww  w  . j a v a  2  s.  com

    vault_config.put("auth-backend", "userpass") // Set the auth-backend to userpass
            .put("user-credentials", new JsonObject().put("username", username).put("password", password));

    // Path to the secret to read.
    vault_config.put("path", "secret/my-secret");

    ConfigStoreOptions store = new ConfigStoreOptions().setType("vault").setConfig(vault_config);

    ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));
}

From source file:examples.InitMongoDatastore.java

License:Open Source License

public void initMongoDatastore(Vertx vertx, String database) {
    Objects.requireNonNull(database, "database is required");
    JsonObject config = new JsonObject();
    config.put("connection_string", "mongodb://localhost:27017");
    config.put("db_name", database);
    MongoClient mongoClient = MongoClient.createNonShared(vertx, config);
    MongoDataStore mongoDataStore = new MongoDataStore(vertx, mongoClient, config);
}

From source file:examples.VertxAmqpBridgeExamples.java

License:Apache License

public void example1(Vertx vertx) {
    AmqpBridge bridge = AmqpBridge.create(vertx);
    // Start the bridge, then use the event loop thread to process things thereafter.
    bridge.start("localhost", 5672, res -> {
        // Set up a producer using the bridge, send a message with it.
        MessageProducer<JsonObject> producer = bridge.createProducer("myAmqpAddress");

        JsonObject amqpMsgPayload = new JsonObject();
        amqpMsgPayload.put("body", "myStringContent");

        producer.send(amqpMsgPayload);/*from  w w  w.  ja  v a 2  s.c  om*/
    });
}

From source file:examples.VertxAmqpBridgeExamples.java

License:Apache License

public void example3(MessageProducer<JsonObject> producer) {
    JsonObject applicationProperties = new JsonObject();
    applicationProperties.put("name", "value");

    JsonObject amqpMsgPayload = new JsonObject();
    amqpMsgPayload.put("application_properties", applicationProperties);

    producer.send(amqpMsgPayload);/*from  ww  w .  j  a v  a2s.co m*/
}

From source file:examples.VertxAmqpBridgeExamples.java

License:Apache License

@SuppressWarnings("unused")
public void example10(MessageProducer<JsonObject> producer) {
    JsonObject amqpMsgPayload = new JsonObject();
    amqpMsgPayload.put("body", "myRequest");

    producer.<JsonObject>send(amqpMsgPayload, res -> {
        JsonObject amqpReplyMessagePayload = res.result().body();
        // ...do something with reply message...
    });/* w  w  w  .  jav a  2  s.c o m*/
}