mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Change "generateSSHKey" function signature
This commit is contained in:
parent
e07a4dc7ba
commit
c24b0c6bb4
@ -82,7 +82,7 @@ module.exports = {
|
||||
var username = getUsername(req.user);
|
||||
// console.log('req.body:', req.body);
|
||||
if ( req.body && req.body.name ) {
|
||||
runtime.storage.sshkeys.generateSSHKey(username, req.body.email || "", req.body.name, req.body)
|
||||
runtime.storage.sshkeys.generateSSHKey(username, req.body)
|
||||
.then(function(name) {
|
||||
// console.log('generate key --- success name:', name);
|
||||
res.json({
|
||||
|
@ -83,16 +83,21 @@ function getSSHKey(username, name) {
|
||||
});
|
||||
}
|
||||
|
||||
function generateSSHKey(username, email, name, data) {
|
||||
function generateSSHKey(username, options) {
|
||||
options = options || {};
|
||||
var name = options.name || "";
|
||||
return checkExistSSHKeyFiles(username, name)
|
||||
.then(function(result) {
|
||||
if ( result ) {
|
||||
throw new Error('Some SSH Keyfile exists');
|
||||
}
|
||||
else {
|
||||
var email = options.email || "";
|
||||
var password = options.password || "";
|
||||
var size = options.size || 2048;
|
||||
var sshKeyFileBasename = username + '_' + name;
|
||||
var privateKeyFilePath = fspath.join(sshkeyDir, sshKeyFileBasename);
|
||||
return generateSSHKeyPair(privateKeyFilePath, email, data.password, data.size)
|
||||
return generateSSHKeyPair(privateKeyFilePath, email, password, size)
|
||||
.then(function() {
|
||||
return name;
|
||||
});
|
||||
|
@ -245,15 +245,16 @@ describe("storage/localfilesystem/sshkeys", function() {
|
||||
it('should generate sshkey file with empty data', function(done) {
|
||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||
var username = 'test';
|
||||
var email = 'test@test.com';
|
||||
var filename = 'test-key01';
|
||||
var data = {};
|
||||
var options = {
|
||||
email: 'test@test.com',
|
||||
name: 'test-key01'
|
||||
};
|
||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
||||
retObj.should.be.equal(filename);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
||||
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||
retObj.should.be.equal(options.name);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
@ -269,17 +270,17 @@ describe("storage/localfilesystem/sshkeys", function() {
|
||||
it('should generate sshkey file with password data', function(done) {
|
||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||
var username = 'test';
|
||||
var email = 'test@test.com';
|
||||
var filename = 'test-key01';
|
||||
var data = {
|
||||
var options = {
|
||||
email: 'test@test.com',
|
||||
name: 'test-key01',
|
||||
password: 'testtest'
|
||||
};
|
||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
||||
retObj.should.be.equal(filename);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
||||
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||
retObj.should.be.equal(options.name);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
@ -295,17 +296,17 @@ describe("storage/localfilesystem/sshkeys", function() {
|
||||
it('should generate sshkey file with size data', function(done) {
|
||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||
var username = 'test';
|
||||
var email = 'test@test.com';
|
||||
var filename = 'test-key01';
|
||||
var data = {
|
||||
var options = {
|
||||
email: 'test@test.com',
|
||||
name: 'test-key01',
|
||||
size: 4096
|
||||
};
|
||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
||||
retObj.should.be.equal(filename);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
||||
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||
retObj.should.be.equal(options.name);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
@ -322,18 +323,18 @@ describe("storage/localfilesystem/sshkeys", function() {
|
||||
this.timeout(5000);
|
||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||
var username = 'test';
|
||||
var email = 'test@test.com';
|
||||
var filename = 'test-key01';
|
||||
var data = {
|
||||
var options = {
|
||||
email: 'test@test.com',
|
||||
name: 'test-key01',
|
||||
password: 'testtest',
|
||||
size: 4096
|
||||
};
|
||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
||||
retObj.should.be.equal(filename);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
||||
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||
retObj.should.be.equal(options.name);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
@ -350,17 +351,17 @@ describe("storage/localfilesystem/sshkeys", function() {
|
||||
this.timeout(5000);
|
||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||
var username = 'test';
|
||||
var email = 'test@test.com';
|
||||
var filename = 'test-key01';
|
||||
var data = {
|
||||
var options = {
|
||||
email: 'test@test.com',
|
||||
name: 'test-key01',
|
||||
size: 3333
|
||||
};
|
||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
||||
retObj.should.be.equal(filename);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
||||
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||
retObj.should.be.equal(options.name);
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
|
Loading…
Reference in New Issue
Block a user