1 | const { FlowManager, FlowNode } = require('@axway/flow');
|
2 | const CredentialManager = require('./credentialmanager');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function _getCredentialMethodSpec() {
|
10 | const getCredentialsSpec = {
|
11 | name: 'Get Credential',
|
12 | description: 'The Authorization flow-node can be used to retrieve the value of a known credential by name for use within the flow.',
|
13 | parameter: {
|
14 | type: 'object',
|
15 | properties: {
|
16 | name: {
|
17 | title: 'Name',
|
18 | type: 'string',
|
19 | description: 'The name of the configured credential to find and return.'
|
20 | }
|
21 | },
|
22 | required: [ 'name' ],
|
23 | additionalProperties: false
|
24 | },
|
25 | outputs: {
|
26 | next: {
|
27 | name: 'Next',
|
28 | description: 'Successfully retrieved the credential.',
|
29 | context: '$.credential',
|
30 | schema: {}
|
31 | },
|
32 | error: {
|
33 | name: 'Error',
|
34 | description: 'Error retrieving credential with the specified name.',
|
35 | context: '$.error',
|
36 | schema: {
|
37 | type: 'string'
|
38 | }
|
39 | }
|
40 | }
|
41 | };
|
42 |
|
43 | return getCredentialsSpec;
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | const getAuthorizationSpec = () => {
|
52 | const handlerSpec = {
|
53 | schemaVersion: '1',
|
54 | type: FlowManager.formatNodeHandlerUri('axway-flow-authorization', 'authz'),
|
55 | name: 'Authorization',
|
56 | icon: 'icon-GG-key',
|
57 | category: 'core',
|
58 | methods: {
|
59 | getCredential: _getCredentialMethodSpec()
|
60 | }
|
61 | };
|
62 |
|
63 | return handlerSpec;
|
64 | };
|
65 |
|
66 | class AuthorizationNode extends FlowNode {
|
67 | getCredential(req, cb) {
|
68 | const name = req.params.name;
|
69 |
|
70 | if (!name) {
|
71 | return cb.error(null, 'Missing required parameter: name');
|
72 | }
|
73 |
|
74 | const authToken = CredentialManager.getCredential(name);
|
75 | if (authToken === null) {
|
76 | return cb.error(null, 'Unable to resolve credential');
|
77 | }
|
78 |
|
79 | cb.next(null, authToken);
|
80 | }
|
81 | }
|
82 |
|
83 | exports = module.exports = {
|
84 | handler: AuthorizationNode,
|
85 | spec: getAuthorizationSpec
|
86 | };
|