thrashr888 / grunt-sftp-deploy

Grunt task for code deployment over sftp
MIT License
155 stars 37 forks source link

authkey? #45

Open danjessen opened 10 years ago

danjessen commented 10 years ago

Is it possible to connect without setting the authkey and setting the credentials directly in the auth object?

I am making a simple deploy file for work, and we all share the same user, but different ssh keys. I just want to make it easy to send around 1 file instead of multiple.

Androguide commented 10 years ago

See #47

danjessen commented 10 years ago

Hmn yes ... maybe. I'll have to look into it. I'm not quite sure that's what I was looking for. I already have the credentials in a different json file for a plugin i use in Sublime Text, I just want to be able to read them from there ;)

Edit: Nevermind, I have to read up on my Node ....

process.env['VARIABLE'] = 'value';
Androguide commented 10 years ago

Yeah, you could all have the environment variable named the same but pointing to different keys on each developer's machine

danjessen commented 10 years ago

Well, all this info is already in a different file. I use the SFTP plugin for Sublime Text, and this plugin already requires the credentials to be in a json formattede file. So I just wan't to read the info from there.

Androguide commented 10 years ago

Oh, then you could modify the getAuthByKey function (Line 146) as follows, you should then be able to pass the path to your json file in the authKey parameter of the grunt task:

function getAuthByKey (inKey) {
    if (fs.existsSync(inKey)) {
      var tmpStr = grunt.file.read(inKey);
      var retVal = null;
      if (inKey !== null && tmpStr.length) retVal = JSON.parse(tmpStr)[inKey];
      return retVal;
    } else {
      var tmpStr;
      var retVal = null;

      if (fs.existsSync('.ftppass')) {
        tmpStr = grunt.file.read('.ftppass');
        if (inKey !== null && tmpStr.length) retVal = JSON.parse(tmpStr)[inKey];
      }
      return retVal;
    }
  }
robogeek commented 9 years ago

FWIW -- I had a similar thought, that the auth might be

auth: {
    host: 'example.com',
    username: 'userName',
}

Then the code could auto-lookup the sshkey from the users home directory. But maybe that's putting too much information into a repository? (host name && user name in a repository both could be a risk?)

auth: {
    host: 'example.com',
    port: 22,
    authKey: process.env.HOME +"/.sftp-deploy-example.txt"
},

Works ...

ImanMh commented 9 years ago

I wish I could give it the host and port only and it would ask for username and password when I ran grunt sftp-deploy:dist is it possible? I don't like to write my username and password in a plain text file any where in my system.