@contrail/cli 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/auth/auth.d.ts +9 -0
- package/lib/auth/auth.js +2 -0
- package/lib/auth/login.js +23 -6
- package/lib/create-app/setup-template.js +3 -3
- package/lib/deploy-app/actions-deployer.js +0 -3
- package/lib/deploy-app/app-deployer.d.ts +1 -0
- package/lib/deploy-app/app-deployer.js +27 -1
- package/lib/deploy-app/interfaces.d.ts +9 -0
- package/package.json +1 -1
- package/src/auth/auth.ts +10 -0
- package/src/auth/login.ts +27 -8
- package/src/create-app/setup-template.ts +3 -7
- package/src/deploy-app/actions-deployer.ts +0 -3
- package/src/deploy-app/app-deployer.ts +29 -3
- package/src/deploy-app/interfaces.ts +8 -0
package/lib/auth/auth.js
ADDED
package/lib/auth/login.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
|
-
import { setConfig } from '@contrail/sdk';
|
|
3
|
+
import { Request, setConfig } from '@contrail/sdk';
|
|
4
|
+
import { Auth } from './auth';
|
|
4
5
|
const CONFIGURATION = {
|
|
5
6
|
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
6
7
|
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
@@ -59,7 +60,7 @@ export async function authUser() {
|
|
|
59
60
|
cognitoUser.authenticateUser(authDetails, {
|
|
60
61
|
onSuccess: async (result) => {
|
|
61
62
|
const user = result;
|
|
62
|
-
await
|
|
63
|
+
await setAuthContext(user, params);
|
|
63
64
|
resolve({ success: true, data: result });
|
|
64
65
|
},
|
|
65
66
|
onFailure: (err) => {
|
|
@@ -69,11 +70,27 @@ export async function authUser() {
|
|
|
69
70
|
});
|
|
70
71
|
});
|
|
71
72
|
}
|
|
72
|
-
async function
|
|
73
|
-
//
|
|
74
|
-
|
|
73
|
+
async function setAuthContext(user, params) {
|
|
74
|
+
// Set Auth Config
|
|
75
|
+
Auth.config = {
|
|
75
76
|
apiUserToken: user.idToken.jwtToken,
|
|
76
77
|
apiGateway: process.env.API_GATEWAY,
|
|
77
|
-
orgSlug,
|
|
78
|
+
orgSlug: params.orgSlug,
|
|
79
|
+
};
|
|
80
|
+
// SET SDK CONFIG
|
|
81
|
+
setConfig(Auth.config);
|
|
82
|
+
const currentUser = await Request.request('/users/current', {
|
|
83
|
+
method: 'GET',
|
|
84
|
+
headers: {
|
|
85
|
+
'Accept': 'application/json',
|
|
86
|
+
'Content-Type': 'application/json',
|
|
87
|
+
},
|
|
78
88
|
});
|
|
89
|
+
if (!currentUser) {
|
|
90
|
+
throw Error('Could not get current user');
|
|
91
|
+
}
|
|
92
|
+
const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
|
|
93
|
+
if (org) {
|
|
94
|
+
Auth.config.orgId = org.orgId || org.id;
|
|
95
|
+
}
|
|
79
96
|
}
|
|
@@ -7,9 +7,9 @@ import { projectInstall } from 'pkg-install';
|
|
|
7
7
|
const copy = promisify(ncp);
|
|
8
8
|
const TARGET_DIR = process.cwd();
|
|
9
9
|
const currentFileUrl = import.meta.url;
|
|
10
|
-
const TEMPLATE_DIR = path.resolve(new URL(currentFileUrl).pathname, '../../../templates/javascript').replace(/\\/g, '\\').replace(/
|
|
11
|
-
// console.log(
|
|
12
|
-
// console.log(
|
|
10
|
+
const TEMPLATE_DIR = path.resolve(new URL(currentFileUrl).pathname, '../../../templates/javascript').replace(/\\/g, '\\').replace(/(.):\\(.):/g, '');
|
|
11
|
+
// console.log('TEMPLATE_DIR: ', TEMPLATE_DIR);
|
|
12
|
+
// console.log('TARGET_DIR: ', TARGET_DIR);
|
|
13
13
|
function copyTemplate() {
|
|
14
14
|
return copy(TEMPLATE_DIR, TARGET_DIR, {
|
|
15
15
|
clobber: false,
|
|
@@ -5,7 +5,6 @@ export class ActionsDeployer {
|
|
|
5
5
|
async deployActions(appDeclaration, app) {
|
|
6
6
|
// FETCH ALL ACTIONS FROM THE API.
|
|
7
7
|
const existingActions = await this.getActionsForApp(app);
|
|
8
|
-
console.log('existingActions: ', existingActions);
|
|
9
8
|
// UPSERT / DELETE BASED ON ACTION IDENTIFIER
|
|
10
9
|
console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
|
|
11
10
|
for (const actionKey of Object.keys(appDeclaration.actions)) {
|
|
@@ -70,9 +69,7 @@ export class ActionsDeployer {
|
|
|
70
69
|
}
|
|
71
70
|
const CURRENT_DIR = process.cwd();
|
|
72
71
|
const functionLocaiton = CURRENT_DIR + '\\' + actionDeclaration.handler;
|
|
73
|
-
console.log('getFunction: ', functionLocaiton);
|
|
74
72
|
const content = fs.readFileSync(functionLocaiton);
|
|
75
|
-
console.log('content: ', content.toString());
|
|
76
73
|
return content.toString();
|
|
77
74
|
}
|
|
78
75
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
+
import { Auth } from '../auth/auth';
|
|
3
4
|
import { ActionsDeployer } from './actions-deployer';
|
|
4
5
|
export class AppDeployer {
|
|
5
6
|
async deploy(appDeclaration) {
|
|
@@ -24,7 +25,12 @@ export class AppDeployer {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
async getExistingApp(appDeclaration) {
|
|
27
|
-
const
|
|
28
|
+
const orgId = Auth.config.orgId;
|
|
29
|
+
const apps = await new Entities().get({ entityName: 'app', criteria: {
|
|
30
|
+
orgId,
|
|
31
|
+
private: (appDeclaration.visibility === 'private')
|
|
32
|
+
},
|
|
33
|
+
});
|
|
28
34
|
// console.log('Existing: ', apps);
|
|
29
35
|
return apps.find(app => app.identifier === appDeclaration.appIdentifier);
|
|
30
36
|
}
|
|
@@ -36,6 +42,8 @@ export class AppDeployer {
|
|
|
36
42
|
publisher: appDeclaration.publisher,
|
|
37
43
|
thumbnail: appDeclaration.thumbnail,
|
|
38
44
|
eventWorkflowTriggerKeyMapping: 'NONE',
|
|
45
|
+
keywords: appDeclaration.keywords,
|
|
46
|
+
configProperties: this.getAppConfigProperties(appDeclaration),
|
|
39
47
|
};
|
|
40
48
|
const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
|
|
41
49
|
console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
@@ -50,9 +58,27 @@ export class AppDeployer {
|
|
|
50
58
|
publisher: appDeclaration.publisher,
|
|
51
59
|
thumbnail: appDeclaration.thumbnail,
|
|
52
60
|
eventWorkflowTriggerKeyMapping: 'NONE',
|
|
61
|
+
keywords: appDeclaration.keywords,
|
|
62
|
+
configProperties: this.getAppConfigProperties(appDeclaration),
|
|
53
63
|
};
|
|
54
64
|
const app = await new Entities().create({ entityName: 'app', object: newApp });
|
|
55
65
|
console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
56
66
|
return app;
|
|
57
67
|
}
|
|
68
|
+
getAppConfigProperties(appDeclaration) {
|
|
69
|
+
const appConfiguration = [];
|
|
70
|
+
for (const configKey of Object.keys(appDeclaration.appConfiguration)) {
|
|
71
|
+
const declaration = appDeclaration.appConfiguration[configKey];
|
|
72
|
+
const config = {
|
|
73
|
+
label: declaration.label,
|
|
74
|
+
slug: configKey,
|
|
75
|
+
propertyType: declaration.propertyType,
|
|
76
|
+
};
|
|
77
|
+
if (declaration.options) {
|
|
78
|
+
config.options = declaration.options;
|
|
79
|
+
}
|
|
80
|
+
appConfiguration.push(config);
|
|
81
|
+
}
|
|
82
|
+
return appConfiguration;
|
|
83
|
+
}
|
|
58
84
|
}
|
|
@@ -9,9 +9,18 @@ export interface AppDeclartion {
|
|
|
9
9
|
publisher: string;
|
|
10
10
|
version: string;
|
|
11
11
|
thumbnail?: string;
|
|
12
|
+
keywords?: Array<string>;
|
|
12
13
|
actions?: {
|
|
13
14
|
[key: string]: AppActionDeclaration;
|
|
14
15
|
};
|
|
16
|
+
appConfiguration: {
|
|
17
|
+
[key: string]: AppConfigurationElement;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface AppConfigurationElement {
|
|
21
|
+
propertyType: string;
|
|
22
|
+
options?: any[];
|
|
23
|
+
label: string;
|
|
15
24
|
}
|
|
16
25
|
export interface AppActionDeclaration {
|
|
17
26
|
handler: string;
|
package/package.json
CHANGED
package/src/auth/auth.ts
ADDED
package/src/auth/login.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
|
-
import { Entities, setConfig } from '@contrail/sdk';
|
|
3
|
+
import { Entities, Request, setConfig } from '@contrail/sdk';
|
|
4
|
+
import { Auth } from './auth';
|
|
4
5
|
|
|
5
6
|
const CONFIGURATION = {
|
|
6
7
|
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
@@ -67,7 +68,8 @@ export async function authUser(){
|
|
|
67
68
|
cognitoUser.authenticateUser(authDetails, {
|
|
68
69
|
onSuccess: async (result) => {
|
|
69
70
|
const user = result;
|
|
70
|
-
await
|
|
71
|
+
await setAuthContext(user, params);
|
|
72
|
+
|
|
71
73
|
resolve({success: true, data: result});
|
|
72
74
|
},
|
|
73
75
|
onFailure: (err) => {
|
|
@@ -76,14 +78,31 @@ export async function authUser(){
|
|
|
76
78
|
},
|
|
77
79
|
});
|
|
78
80
|
});
|
|
79
|
-
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
async function
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
async function setAuthContext(user, params){
|
|
84
|
+
|
|
85
|
+
// Set Auth Config
|
|
86
|
+
Auth.config = {
|
|
85
87
|
apiUserToken: user.idToken.jwtToken,
|
|
86
88
|
apiGateway: process.env.API_GATEWAY,
|
|
87
|
-
orgSlug,
|
|
89
|
+
orgSlug: params.orgSlug,
|
|
90
|
+
};
|
|
91
|
+
// SET SDK CONFIG
|
|
92
|
+
setConfig(Auth.config);
|
|
93
|
+
|
|
94
|
+
const currentUser = await Request.request('/users/current', {
|
|
95
|
+
method: 'GET',
|
|
96
|
+
headers: {
|
|
97
|
+
'Accept': 'application/json',
|
|
98
|
+
'Content-Type': 'application/json',
|
|
99
|
+
},
|
|
88
100
|
});
|
|
89
|
-
|
|
101
|
+
if (!currentUser) {
|
|
102
|
+
throw Error('Could not get current user');
|
|
103
|
+
}
|
|
104
|
+
const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
|
|
105
|
+
if (org) {
|
|
106
|
+
Auth.config.orgId = org.orgId || org.id;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -9,13 +9,9 @@ const copy = promisify(ncp);
|
|
|
9
9
|
const TARGET_DIR = process.cwd();
|
|
10
10
|
|
|
11
11
|
const currentFileUrl = import .meta.url;
|
|
12
|
-
const TEMPLATE_DIR = path.resolve(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
).replace(/\\/g, '\\').replace(/C:\\C:/g, '');
|
|
16
|
-
|
|
17
|
-
// console.log("TEMPLATE_DIR: ", TEMPLATE_DIR)
|
|
18
|
-
// console.log("TARGET_DIR: ", TARGET_DIR)
|
|
12
|
+
const TEMPLATE_DIR = path.resolve(new URL(currentFileUrl).pathname, '../../../templates/javascript').replace(/\\/g, '\\').replace(/(.):\\(.):/g, '');
|
|
13
|
+
// console.log('TEMPLATE_DIR: ', TEMPLATE_DIR);
|
|
14
|
+
// console.log('TARGET_DIR: ', TARGET_DIR);
|
|
19
15
|
|
|
20
16
|
function copyTemplate(){
|
|
21
17
|
return copy(TEMPLATE_DIR, TARGET_DIR, {
|
|
@@ -8,7 +8,6 @@ export class ActionsDeployer {
|
|
|
8
8
|
|
|
9
9
|
// FETCH ALL ACTIONS FROM THE API.
|
|
10
10
|
const existingActions = await this.getActionsForApp(app);
|
|
11
|
-
console.log('existingActions: ', existingActions);
|
|
12
11
|
// UPSERT / DELETE BASED ON ACTION IDENTIFIER
|
|
13
12
|
console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
|
|
14
13
|
for (const actionKey of Object.keys(appDeclaration.actions)) {
|
|
@@ -79,9 +78,7 @@ export class ActionsDeployer {
|
|
|
79
78
|
}
|
|
80
79
|
const CURRENT_DIR = process.cwd();
|
|
81
80
|
const functionLocaiton = CURRENT_DIR + '\\' + actionDeclaration.handler;
|
|
82
|
-
console.log('getFunction: ', functionLocaiton);
|
|
83
81
|
const content = fs.readFileSync(functionLocaiton);
|
|
84
|
-
console.log('content: ', content.toString());
|
|
85
82
|
return content.toString();
|
|
86
83
|
}
|
|
87
84
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
+
import { config } from 'process';
|
|
4
|
+
import { Auth } from '../auth/auth';
|
|
3
5
|
import { ActionsDeployer } from './actions-deployer';
|
|
4
6
|
import { App, AppDeclartion } from './interfaces';
|
|
5
7
|
|
|
@@ -27,7 +29,11 @@ export class AppDeployer {
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
public async getExistingApp(appDeclaration: AppDeclartion) {
|
|
30
|
-
const
|
|
32
|
+
const orgId = Auth.config.orgId;
|
|
33
|
+
const apps = await new Entities().get({ entityName: 'app', criteria: {
|
|
34
|
+
orgId,
|
|
35
|
+
private: (appDeclaration.visibility === 'private')},
|
|
36
|
+
});
|
|
31
37
|
// console.log('Existing: ', apps);
|
|
32
38
|
return apps.find(app => app.identifier === appDeclaration.appIdentifier);
|
|
33
39
|
}
|
|
@@ -39,11 +45,12 @@ export class AppDeployer {
|
|
|
39
45
|
publisher: appDeclaration.publisher,
|
|
40
46
|
thumbnail: appDeclaration.thumbnail,
|
|
41
47
|
eventWorkflowTriggerKeyMapping: 'NONE',
|
|
48
|
+
keywords: appDeclaration.keywords,
|
|
49
|
+
configProperties: this.getAppConfigProperties(appDeclaration),
|
|
42
50
|
};
|
|
43
51
|
const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
|
|
44
52
|
console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
45
53
|
return app;
|
|
46
|
-
|
|
47
54
|
}
|
|
48
55
|
private async createNewApp(appDeclaration: AppDeclartion) {
|
|
49
56
|
const newApp = {
|
|
@@ -54,10 +61,29 @@ export class AppDeployer {
|
|
|
54
61
|
publisher: appDeclaration.publisher,
|
|
55
62
|
thumbnail: appDeclaration.thumbnail,
|
|
56
63
|
eventWorkflowTriggerKeyMapping: 'NONE',
|
|
57
|
-
|
|
64
|
+
keywords: appDeclaration.keywords,
|
|
65
|
+
configProperties: this.getAppConfigProperties(appDeclaration),
|
|
58
66
|
};
|
|
59
67
|
const app = await new Entities().create({ entityName: 'app', object: newApp });
|
|
60
68
|
console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
61
69
|
return app;
|
|
70
|
+
|
|
62
71
|
}
|
|
72
|
+
private getAppConfigProperties(appDeclaration: AppDeclartion){
|
|
73
|
+
const appConfiguration = [];
|
|
74
|
+
for (const configKey of Object.keys(appDeclaration.appConfiguration)) {
|
|
75
|
+
const declaration = appDeclaration.appConfiguration[configKey];
|
|
76
|
+
const config: any = {
|
|
77
|
+
label: declaration.label,
|
|
78
|
+
slug: configKey,
|
|
79
|
+
propertyType: declaration.propertyType,
|
|
80
|
+
};
|
|
81
|
+
if (declaration.options) {
|
|
82
|
+
config.options = declaration.options;
|
|
83
|
+
}
|
|
84
|
+
appConfiguration.push(config);
|
|
85
|
+
}
|
|
86
|
+
return appConfiguration;
|
|
87
|
+
}
|
|
88
|
+
|
|
63
89
|
}
|
|
@@ -9,7 +9,15 @@ export interface AppDeclartion {
|
|
|
9
9
|
publisher: string;
|
|
10
10
|
version: string;
|
|
11
11
|
thumbnail?: string;
|
|
12
|
+
keywords?: Array<string>;
|
|
12
13
|
actions?: { [key: string]: AppActionDeclaration };
|
|
14
|
+
appConfiguration: { [key: string]: AppConfigurationElement };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AppConfigurationElement {
|
|
18
|
+
propertyType: string;
|
|
19
|
+
options?: any[];
|
|
20
|
+
label: string;
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
export interface AppActionDeclaration {
|