-
Notifications
You must be signed in to change notification settings - Fork 60
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 #64 from Travelport-Ukraine/master
Merged Milestone v0.5.0
- Loading branch information
Showing
23 changed files
with
405 additions
and
78 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
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,31 @@ | ||
# Terminal :computer: | ||
|
||
Terminal service provides an interface to run terminal commands | ||
for terminal-enabled uAPI credentials. | ||
|
||
You can use Terminal service to run commands on behalf of your own PCC | ||
or to use `emulatePcc` option to run commands on behalf of other PC using your own Service bureau. | ||
|
||
## API | ||
|
||
**TerminalService** | ||
* [`.executeCommand()`](#execute_command) ⇒ `Promise` | ||
* [`.closeSession()`](#close_session) ⇒ `Promise` | ||
|
||
## Methods | ||
### .executeCommand(command) | ||
<a name="execute_command"></a> | ||
Executes a command in terminal and returns its terminal response | ||
|
||
**Returns**: `Promise` that returns terminal command response in `String` format | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| command | `String` | String representation of the command you want to execute | | ||
|
||
### .closeSession() | ||
<a name="close_session"></a> | ||
When you have finished command execution it's necessary to close terminal connection | ||
to free up space in the terminal pool. Takes no parameters | ||
|
||
**Returns**: `Promise` which fullfills with true if terminal was succesfully closed |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Utils :hotel: | ||
# Utils :cd: | ||
|
||
Some powerfull utils that can help you build best products. | ||
|
||
|
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
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,78 @@ | ||
import { lib as screenLib } from 'galileo-screen'; | ||
import { | ||
TerminalRuntimeError, | ||
} from './TerminalErrors'; | ||
import terminalService from './TerminalService'; | ||
|
||
const responseHasMoreData = response => (response.slice(-1).join('') === ')><'); | ||
|
||
module.exports = function (settings) { | ||
const service = terminalService(settings); | ||
const emulatePcc = settings.emulatePcc || false; | ||
const timeout = settings.timeout || false; | ||
const state = { | ||
sessionToken: null, | ||
}; | ||
const processResponse = (response, previousResponse = []) => { | ||
const processedResponse = screenLib.mergeLastLinesAtIntersection( | ||
previousResponse.slice(0, -1), | ||
response | ||
); | ||
if (!responseHasMoreData(response)) { | ||
return processedResponse.join('\n'); | ||
} | ||
return service.executeCommand({ | ||
sessionToken: state.sessionToken, | ||
command: 'MD', | ||
}).then( | ||
mdResponse => processResponse(mdResponse, processedResponse) | ||
); | ||
}; | ||
const getSessionToken = () => new Promise((resolve, reject) => { | ||
// Return token if already obtained | ||
if (state.sessionToken !== null) { | ||
resolve(state.sessionToken); | ||
return; | ||
} | ||
// Getting token | ||
service.getSessionToken({ | ||
timeout, | ||
}).then((sessionToken) => { | ||
// Remember sesion token | ||
Object.assign(state, { | ||
sessionToken, | ||
}); | ||
// Return if no emulation needed | ||
if (!emulatePcc) { | ||
resolve(sessionToken); | ||
return; | ||
} | ||
// Emulate pcc | ||
service.executeCommand({ | ||
sessionToken, | ||
command: `SEM/${emulatePcc}/AG`, | ||
}).then((response) => { | ||
if (!response[0].match(/^PROCEED/)) { | ||
reject(new TerminalRuntimeError.TerminalEmulationFailed(response)); | ||
return; | ||
} | ||
resolve(sessionToken); | ||
}); | ||
}).catch(reject); | ||
}); | ||
return { | ||
executeCommand: command => getSessionToken().then( | ||
sessionToken => service.executeCommand({ | ||
command, | ||
sessionToken, | ||
}).then( | ||
response => processResponse(response) | ||
) | ||
), | ||
closeSession: () => getSessionToken().then( | ||
sessionToken => service.closeSession({ | ||
sessionToken, | ||
}) | ||
), | ||
}; | ||
}; |
Oops, something went wrong.