Vault

Storing secrets for docker containers can be tricky to get right. There is this thing called vault that does it pretty safely for you. The idea is that there should be nothing sensitve stored in the configuration of your containers. This is hard because when you need keys and passwords it is quite common to store those as environment variables and then refences those. You should not do that, that is bad.

vaultproject.io

vault server: docker run -p 8200:8200 --cap-add=IPC_LOCK -e 'VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200' -v /Users/myuser/vault:/vault/file vault

host side setup the vault addr export VAULT_ADDR='http://127.0.0.1:8200'

hubot

Here is an example of how to maintin a basic prompting conversation with a hubbot. This repsonds to the inital trigger and then from there will prompt a user through a series of questions, using a simple switch. This could be used for building up a series of commands to run on teh backend or setting something up…

  robot.respond(/wizard start/i, function(msg) {
    var user = {stage: 1};
    var name = msg.message.user.name.toLowerCase()
    robot.brain.set(name, user);
    console.log("user created: "+name+" stage: "+user.stage);
    });
  robot.hear(/(\w+)/i, function(msg) {
   var name = msg.message.user.name.toLowerCase();
   var user = robot.brain.get(name) || null;
    if (user != null){ 
      console.log("user exists: "+name+" stage: "+user.stage);
      var answer = msg.message.rawText;
      if (answer == "reset"){
        delete user;
      }
      if (answer == "exit"){
        user = {stage: 7};
        robot.brain.remove(name);
      }
      switch (user.stage){
        case 1: 
          msg.reply("Q"+user.stage+". What is your name");
          console.log(answer);
          break;
        case 2: 
          user.name = answer;
          msg.reply("Q"+user.stage+". What is your age");
          console.log(answer);
          break;
        case 3: 
          user.age = answer;
          msg.reply("Q"+user.stage+". What is your gender");
          console.log(answer);
          break;
        case 4:
          user.gender = answer;
          msg.reply("Q"+user.stage+". What is your favorite color");
          console.log(answer);
          break;
        case 5:
          user.color = answer;
        }
        user.stage++;
      robot.brain.set(name, user);
      if(user.stage  == 6 ){
        msg.reply("Hi "+user.name+". You are "+user.age+", "+user.gender+" and your favorite color is "+user.color);
        robot.brain.remove(name);
      }
      if(user.stage  > 6 ){
         delete user;
         robot.brain.remove(name);
      }    
    }

  }); 
}