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);
|
var username = getUsername(req.user);
|
||||||
// console.log('req.body:', req.body);
|
// console.log('req.body:', req.body);
|
||||||
if ( req.body && req.body.name ) {
|
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) {
|
.then(function(name) {
|
||||||
// console.log('generate key --- success name:', name);
|
// console.log('generate key --- success name:', name);
|
||||||
res.json({
|
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)
|
return checkExistSSHKeyFiles(username, name)
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
if ( result ) {
|
if ( result ) {
|
||||||
throw new Error('Some SSH Keyfile exists');
|
throw new Error('Some SSH Keyfile exists');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
var email = options.email || "";
|
||||||
|
var password = options.password || "";
|
||||||
|
var size = options.size || 2048;
|
||||||
var sshKeyFileBasename = username + '_' + name;
|
var sshKeyFileBasename = username + '_' + name;
|
||||||
var privateKeyFilePath = fspath.join(sshkeyDir, sshKeyFileBasename);
|
var privateKeyFilePath = fspath.join(sshkeyDir, sshKeyFileBasename);
|
||||||
return generateSSHKeyPair(privateKeyFilePath, email, data.password, data.size)
|
return generateSSHKeyPair(privateKeyFilePath, email, password, size)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return name;
|
return name;
|
||||||
});
|
});
|
||||||
|
@ -245,15 +245,16 @@ describe("storage/localfilesystem/sshkeys", function() {
|
|||||||
it('should generate sshkey file with empty data', function(done) {
|
it('should generate sshkey file with empty data', function(done) {
|
||||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||||
var username = 'test';
|
var username = 'test';
|
||||||
var email = 'test@test.com';
|
var options = {
|
||||||
var filename = 'test-key01';
|
email: 'test@test.com',
|
||||||
var data = {};
|
name: 'test-key01'
|
||||||
|
};
|
||||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||||
retObj.should.be.equal(filename);
|
retObj.should.be.equal(options.name);
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||||
done();
|
done();
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
@ -269,17 +270,17 @@ describe("storage/localfilesystem/sshkeys", function() {
|
|||||||
it('should generate sshkey file with password data', function(done) {
|
it('should generate sshkey file with password data', function(done) {
|
||||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||||
var username = 'test';
|
var username = 'test';
|
||||||
var email = 'test@test.com';
|
var options = {
|
||||||
var filename = 'test-key01';
|
email: 'test@test.com',
|
||||||
var data = {
|
name: 'test-key01',
|
||||||
password: 'testtest'
|
password: 'testtest'
|
||||||
};
|
};
|
||||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||||
retObj.should.be.equal(filename);
|
retObj.should.be.equal(options.name);
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||||
done();
|
done();
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
@ -295,17 +296,17 @@ describe("storage/localfilesystem/sshkeys", function() {
|
|||||||
it('should generate sshkey file with size data', function(done) {
|
it('should generate sshkey file with size data', function(done) {
|
||||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||||
var username = 'test';
|
var username = 'test';
|
||||||
var email = 'test@test.com';
|
var options = {
|
||||||
var filename = 'test-key01';
|
email: 'test@test.com',
|
||||||
var data = {
|
name: 'test-key01',
|
||||||
size: 4096
|
size: 4096
|
||||||
};
|
};
|
||||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||||
retObj.should.be.equal(filename);
|
retObj.should.be.equal(options.name);
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||||
done();
|
done();
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
@ -322,18 +323,18 @@ describe("storage/localfilesystem/sshkeys", function() {
|
|||||||
this.timeout(5000);
|
this.timeout(5000);
|
||||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||||
var username = 'test';
|
var username = 'test';
|
||||||
var email = 'test@test.com';
|
var options = {
|
||||||
var filename = 'test-key01';
|
email: 'test@test.com',
|
||||||
var data = {
|
name: 'test-key01',
|
||||||
password: 'testtest',
|
password: 'testtest',
|
||||||
size: 4096
|
size: 4096
|
||||||
};
|
};
|
||||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||||
retObj.should.be.equal(filename);
|
retObj.should.be.equal(options.name);
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||||
done();
|
done();
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
@ -350,17 +351,17 @@ describe("storage/localfilesystem/sshkeys", function() {
|
|||||||
this.timeout(5000);
|
this.timeout(5000);
|
||||||
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
|
||||||
var username = 'test';
|
var username = 'test';
|
||||||
var email = 'test@test.com';
|
var options = {
|
||||||
var filename = 'test-key01';
|
email: 'test@test.com',
|
||||||
var data = {
|
name: 'test-key01',
|
||||||
size: 3333
|
size: 3333
|
||||||
};
|
};
|
||||||
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
localfilesystem.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
sshkeys.init(mockSettings, mockRuntime).then(function() {
|
||||||
sshkeys.generateSSHKey(username, email, filename, data).then(function(retObj) {
|
sshkeys.generateSSHKey(username, options).then(function(retObj) {
|
||||||
retObj.should.be.equal(filename);
|
retObj.should.be.equal(options.name);
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
|
||||||
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.true();
|
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
|
||||||
done();
|
done();
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
|
Loading…
Reference in New Issue
Block a user