-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from dappnode/v0.1.10
v0.1.10
- Loading branch information
Showing
21 changed files
with
343 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const fs = require('fs'); | ||
const {promisify} = require('util'); | ||
const paramsDefault = require('params'); | ||
|
||
// CALL DOCUMENTATION: | ||
// > kwargs: { | ||
// id, | ||
// isCore, | ||
// options | ||
// } | ||
// > result: { | ||
// id, | ||
// logs: <String with escape codes> (string) | ||
// } | ||
|
||
function createGetUserActionLogs({ | ||
params = paramsDefault, | ||
}) { | ||
const getUserActionLogs = async ({ | ||
options, | ||
}) => { | ||
const readFileAsync = promisify(fs.readFile); | ||
const {userActionLogsFilename} = params; | ||
|
||
if (!fs.existsSync(userActionLogsFilename)) { | ||
return { | ||
message: 'UserActionLogs are still empty, returning black', | ||
result: '', | ||
}; | ||
} | ||
const userActionLogs = await readFileAsync( | ||
userActionLogsFilename, | ||
{encoding: 'utf8'} | ||
); | ||
|
||
return { | ||
message: 'Got userActionLogs', | ||
result: userActionLogs, | ||
}; | ||
}; | ||
|
||
// Expose main method | ||
return getUserActionLogs; | ||
} | ||
|
||
|
||
module.exports = createGetUserActionLogs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const dockerDefault = require('modules/docker'); | ||
|
||
// CALL DOCUMENTATION: | ||
// > kwargs: { ports, logId } | ||
// > result: - | ||
|
||
function createManagePorts({ | ||
docker = dockerDefault, | ||
}) { | ||
const managePorts = async ({ | ||
action, | ||
ports, | ||
}) => { | ||
// ports should be an array of numerical ports | ||
// [5000, 5001] | ||
if (!Array.isArray(ports)) { | ||
throw Error('ports variable must be an array: '+JSON.stringify(ports)); | ||
} | ||
|
||
let msg; | ||
for (const port of ports) { | ||
switch (action) { | ||
case 'open': | ||
await docker.openPort(port); | ||
msg = 'Opened'; | ||
break; | ||
case 'close': | ||
await docker.closePort(port); | ||
msg = 'Closed'; | ||
break; | ||
default: | ||
throw Error('Unkown manage ports action: '+action); | ||
} | ||
} | ||
|
||
return { | ||
message: msg+' ports '+ports.join(', '), | ||
logMessage: true, | ||
userAction: true, | ||
}; | ||
}; | ||
|
||
// Expose main method | ||
return managePorts; | ||
} | ||
|
||
// function getPorts(MANIFEST) { | ||
// return (MANIFEST && MANIFEST.image && MANIFEST.image.ports) | ||
// ? MANIFEST.image.ports.map((p) => p.split(':')[0]) | ||
// : []; | ||
// } | ||
|
||
|
||
module.exports = createManagePorts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const chai = require('chai'); | ||
const expect = require('chai').expect; | ||
const createManagePorts = require('calls/createManagePorts'); | ||
|
||
chai.should(); | ||
|
||
describe('Call function: managePorts', function() { | ||
const openedPorts = []; | ||
const dockerMock = { | ||
openPort: async (port) => { | ||
openedPorts.push(port); | ||
}, | ||
}; | ||
|
||
const managePorts = createManagePorts({ | ||
docker: dockerMock, | ||
}); | ||
|
||
it('should open the requested ports', async () => { | ||
const ports = [5000, 5001]; | ||
const res = await managePorts({ | ||
action: 'open', | ||
ports, | ||
}); | ||
// Check opened ports | ||
expect(ports).to.deep.equal(openedPorts); | ||
// Check response message | ||
expect(res).to.be.ok; | ||
expect(res).to.have.property('message'); | ||
}); | ||
|
||
it('should throw an error with wrong ports variable', async () => { | ||
let error = '--- managePorts did not throw ---'; | ||
try { | ||
await managePorts({ | ||
action: 'open', | ||
ports: 'not an array', | ||
}); | ||
} catch (e) { | ||
error = e.message; | ||
} | ||
expect(error).to.include('ports variable must be an array'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.