@contrail/cli 1.0.0 → 1.0.5
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/.vscode/settings.json +5 -5
- package/bin/init +3 -3
- package/lib/{create-app → apps/create-app}/create.d.ts +1 -1
- package/lib/apps/create-app/create.js +59 -0
- package/lib/apps/create-app/setup-template.d.ts +1 -0
- package/lib/apps/create-app/setup-template.js +34 -0
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.d.ts +10 -10
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.js +97 -78
- package/lib/apps/deploy-app/app-deployer.d.ts +8 -0
- package/lib/{deploy-app → apps/deploy-app}/app-deployer.js +79 -58
- package/lib/apps/deploy-app/app-template-parsers.d.ts +7 -0
- package/lib/apps/deploy-app/app-template-parsers.js +37 -0
- package/lib/{deploy-app → apps/deploy-app}/deploy.d.ts +2 -2
- package/lib/apps/deploy-app/deploy.js +58 -0
- package/lib/apps/deploy-app/interfaces.d.ts +74 -0
- package/lib/apps/deploy-app/interfaces.js +4 -0
- package/lib/auth/auth.d.ts +9 -0
- package/lib/auth/auth.js +2 -0
- package/lib/auth/login.d.ts +2 -1
- package/lib/auth/login.js +113 -79
- package/lib/cli.d.ts +5 -5
- package/lib/cli.js +36 -30
- package/lib/common.d.ts +1 -0
- package/lib/common.js +5 -0
- package/lib/types/interfaces.d.ts +51 -0
- package/lib/{deploy-app → types}/interfaces.js +0 -0
- package/lib/types/option-set-uploader.d.ts +1 -0
- package/lib/types/option-set-uploader.js +75 -0
- package/lib/types/types-extractor.d.ts +1 -0
- package/lib/types/types-extractor.js +93 -0
- package/lib/types/types-uploader.d.ts +1 -0
- package/lib/types/types-uploader.js +171 -0
- package/package.json +63 -63
- package/publish.sh +5 -0
- package/src/apps/create-app/create.ts +73 -0
- package/src/apps/create-app/setup-template.ts +38 -0
- package/src/{deploy-app → apps/deploy-app}/actions-deployer.ts +122 -87
- package/src/{deploy-app → apps/deploy-app}/app-deployer.ts +86 -63
- package/src/apps/deploy-app/app-template-parsers.ts +43 -0
- package/src/apps/deploy-app/deploy.ts +67 -0
- package/src/apps/deploy-app/interfaces.ts +78 -0
- package/src/auth/auth.ts +10 -0
- package/src/auth/login.ts +127 -89
- package/src/cli.ts +38 -33
- package/src/common.ts +5 -0
- package/src/types/interfaces.ts +54 -0
- package/src/types/option-set-uploader.ts +83 -0
- package/src/types/types-extractor.ts +116 -0
- package/src/types/types-uploader.ts +198 -0
- package/templates/javascript/actions/example/action.js +37 -37
- package/templates/javascript/app.yml +54 -42
- package/templates/javascript/package.json +23 -23
- package/templates/typescript/actions/exampleAction.ts +38 -0
- package/templates/typescript/app.yml +56 -0
- package/templates/typescript/package.json +24 -0
- package/templates/typescript/tsconfig.json +31 -0
- package/tsconfig.json +30 -22
- package/tslint.json +57 -57
- package/lib/create-app/create.js +0 -48
- package/lib/create-app/setup-template.d.ts +0 -1
- package/lib/create-app/setup-template.js +0 -48
- package/lib/deploy-app/actions.d.ts +0 -5
- package/lib/deploy-app/actions.js +0 -17
- package/lib/deploy-app/app-declaration.d.ts +0 -20
- package/lib/deploy-app/app-declaration.js +0 -0
- package/lib/deploy-app/app-deployer.d.ts +0 -9
- package/lib/deploy-app/app.d.ts +0 -8
- package/lib/deploy-app/app.js +0 -56
- package/lib/deploy-app/deploy.js +0 -30
- package/lib/deploy-app/interfaces.d.ts +0 -34
- package/src/create-app/create.ts +0 -58
- package/src/create-app/setup-template.ts +0 -61
- package/src/deploy-app/deploy.ts +0 -34
- package/src/deploy-app/interfaces.ts +0 -35
|
@@ -1,63 +1,86 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
await new ActionsDeployer().deployActions(appDeclaration,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public async
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Auth } from '../../auth/auth';
|
|
4
|
+
import { ActionsDeployer } from './actions-deployer';
|
|
5
|
+
import { App, AppDeclaration } from './interfaces';
|
|
6
|
+
import { TriggerKeyDefinitionParser, ConfigPropertiesParser } from './app-template-parsers';
|
|
7
|
+
|
|
8
|
+
export class AppDeployer {
|
|
9
|
+
public async deploy(appDeclaration: AppDeclaration) {
|
|
10
|
+
let app = await this.getExistingApp(appDeclaration);
|
|
11
|
+
if (!app) {
|
|
12
|
+
app = await this.createNewApp(appDeclaration);
|
|
13
|
+
} else {
|
|
14
|
+
app = await this.updateExistingApp(appDeclaration, app);
|
|
15
|
+
}
|
|
16
|
+
await new ActionsDeployer().deployActions(appDeclaration, app);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async getExistingApp(appDeclaration: AppDeclaration): Promise<App> {
|
|
20
|
+
const orgId = Auth.config.orgId;
|
|
21
|
+
const apps = [];
|
|
22
|
+
|
|
23
|
+
apps.push(...await new Entities().get({
|
|
24
|
+
entityName: 'app',
|
|
25
|
+
criteria: {
|
|
26
|
+
orgId,
|
|
27
|
+
private: true,
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
apps.push(...await new Entities().get({
|
|
31
|
+
entityName: 'app',
|
|
32
|
+
criteria: {
|
|
33
|
+
orgId,
|
|
34
|
+
private: false,
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
return apps.find(app => app.identifier === appDeclaration.appIdentifier);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private async createNewApp(appDeclaration: AppDeclaration) {
|
|
42
|
+
const newApp = {
|
|
43
|
+
identifier: appDeclaration.appIdentifier,
|
|
44
|
+
name: appDeclaration.appName,
|
|
45
|
+
public: appDeclaration.visibility === 'public',
|
|
46
|
+
description: appDeclaration.appDescription,
|
|
47
|
+
publisher: appDeclaration.publisher,
|
|
48
|
+
thumbnail: appDeclaration.thumbnail,
|
|
49
|
+
eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
|
|
50
|
+
keywords: appDeclaration.keywords,
|
|
51
|
+
configProperties: ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration),
|
|
52
|
+
triggerKeyDefinitions: TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration),
|
|
53
|
+
};
|
|
54
|
+
const app = await new Entities().create({ entityName: 'app', object: newApp });
|
|
55
|
+
console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
56
|
+
return app;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public async updateExistingApp(appDeclaration: AppDeclaration, existingApp) {
|
|
60
|
+
const updates = {
|
|
61
|
+
name: appDeclaration.appName,
|
|
62
|
+
public: appDeclaration.visibility === 'public',
|
|
63
|
+
description: appDeclaration.appDescription,
|
|
64
|
+
publisher: appDeclaration.publisher,
|
|
65
|
+
thumbnail: appDeclaration.thumbnail,
|
|
66
|
+
eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
|
|
67
|
+
keywords: appDeclaration.keywords,
|
|
68
|
+
configProperties: ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration),
|
|
69
|
+
triggerKeyDefinitions: TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration),
|
|
70
|
+
};
|
|
71
|
+
const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
|
|
72
|
+
console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
73
|
+
return app;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public async remove(appDeclaration: AppDeclaration) {
|
|
77
|
+
let app = await this.getExistingApp(appDeclaration);
|
|
78
|
+
if (app) {
|
|
79
|
+
app = await new Entities().delete({ entityName: 'app', id: app.id });
|
|
80
|
+
console.log(`%s Deleted app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
81
|
+
} else {
|
|
82
|
+
throw new Error('App not found.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AppDeclaration, TriggerKeyDefinition, ConfigPropertyElements } from './interfaces';
|
|
2
|
+
|
|
3
|
+
export class TriggerKeyDefinitionParser {
|
|
4
|
+
public static buildTriggersArray(appDeclaration: AppDeclaration): Array<TriggerKeyDefinition> {
|
|
5
|
+
const triggers: Array<TriggerKeyDefinition> = [];
|
|
6
|
+
|
|
7
|
+
for (const triggerName of Object.keys(appDeclaration.triggers)) {
|
|
8
|
+
const triggerDeclaration = appDeclaration.triggers[triggerName];
|
|
9
|
+
|
|
10
|
+
const triggerDefinition = {
|
|
11
|
+
triggerKey: triggerDeclaration.external ? `${appDeclaration.appIdentifier}:${triggerDeclaration.key}` : triggerDeclaration.key,
|
|
12
|
+
name: triggerDeclaration.name,
|
|
13
|
+
external: triggerDeclaration.external,
|
|
14
|
+
description: triggerDeclaration.description,
|
|
15
|
+
};
|
|
16
|
+
if (!triggerDefinition.triggerKey || !triggerDefinition.name) {
|
|
17
|
+
throw new Error('Illegal trigger declaration: must have key and name');
|
|
18
|
+
}
|
|
19
|
+
triggers.push(triggerDefinition);
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
return triggers;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class ConfigPropertiesParser {
|
|
27
|
+
public static getConfigProperties(configPropertyElements: ConfigPropertyElements) {
|
|
28
|
+
const appConfiguration = [];
|
|
29
|
+
for (const configKey of Object.keys(configPropertyElements)) {
|
|
30
|
+
const declaration = configPropertyElements[configKey];
|
|
31
|
+
const config: any = {
|
|
32
|
+
label: declaration.label,
|
|
33
|
+
slug: configKey,
|
|
34
|
+
propertyType: declaration.propertyType, // TODO should support options
|
|
35
|
+
};
|
|
36
|
+
if (declaration.options) {
|
|
37
|
+
config.options = declaration.options;
|
|
38
|
+
}
|
|
39
|
+
appConfiguration.push(config);
|
|
40
|
+
}
|
|
41
|
+
return appConfiguration;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { authUser } from '../../auth/login';
|
|
4
|
+
import { AppDeployer } from './app-deployer';
|
|
5
|
+
import { AppDeclaration } from './interfaces';
|
|
6
|
+
import { getSeparatorByPlatform } from '../../common';
|
|
7
|
+
const yaml = require('js-yaml');
|
|
8
|
+
|
|
9
|
+
function loadAppConfig(){
|
|
10
|
+
const TARGET_DIR = process.cwd();
|
|
11
|
+
try {
|
|
12
|
+
const separator = getSeparatorByPlatform();
|
|
13
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'app.yml', 'utf8'));
|
|
14
|
+
console.log(doc);
|
|
15
|
+
return doc;
|
|
16
|
+
} catch (e) {
|
|
17
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function deployApp(args) {
|
|
22
|
+
let appDeclaration: AppDeclaration;
|
|
23
|
+
try {
|
|
24
|
+
appDeclaration = loadAppConfig();
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.log(`%s Application Deployment Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
console.log(`%s Deploying Application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
await authUser();
|
|
35
|
+
await new AppDeployer().deploy(appDeclaration);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
console.log(`%s Application Deployment Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('%s Deployment Complete.', chalk.green.bold('COMPLETE'));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function removeApp(args) {
|
|
46
|
+
let appDeclaration: AppDeclaration;
|
|
47
|
+
try {
|
|
48
|
+
appDeclaration = loadAppConfig();
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
console.log(`%s Application Removal Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log(`%s Removing Application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
await authUser();
|
|
59
|
+
await new AppDeployer().remove(appDeclaration);
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.log(`%s Application Removal Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log('%s Application Removal Complete.', chalk.green.bold('COMPLETE'));
|
|
67
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Describes the derivative JSON / object represented
|
|
2
|
+
* in app.yml file.
|
|
3
|
+
*/
|
|
4
|
+
export interface AppDeclaration {
|
|
5
|
+
appIdentifier: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
appDescription?: string;
|
|
8
|
+
visibility: 'private' | 'public';
|
|
9
|
+
publisher: string;
|
|
10
|
+
version: string;
|
|
11
|
+
eventWorkflowTriggerKeyMapping: string;
|
|
12
|
+
thumbnail?: string;
|
|
13
|
+
keywords?: Array<string>;
|
|
14
|
+
actions?: { [key: string]: AppActionDeclaration };
|
|
15
|
+
appConfiguration: ConfigPropertyElements;
|
|
16
|
+
triggers: { [key: string]: AppTriggerDeclaration };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ConfigPropertyElements {
|
|
20
|
+
[key: string]: ConfigPropertyElement;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ConfigPropertyElement {
|
|
24
|
+
propertyType: string;
|
|
25
|
+
options?: any[];
|
|
26
|
+
label: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AppActionDeclaration {
|
|
30
|
+
handler: string;
|
|
31
|
+
name: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
actionConfiguration?: ConfigPropertyElements;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface AppTriggerDeclaration {
|
|
37
|
+
key: string;
|
|
38
|
+
name: string;
|
|
39
|
+
external?: boolean;
|
|
40
|
+
description?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface App {
|
|
44
|
+
id: string;
|
|
45
|
+
identifier: string;
|
|
46
|
+
name: string;
|
|
47
|
+
public: boolean;
|
|
48
|
+
description?: string;
|
|
49
|
+
publisher: string;
|
|
50
|
+
thumbnail: string; // should be a public link
|
|
51
|
+
eventWorkflowTriggerKeyMapping: string;
|
|
52
|
+
configProperties?: ConfigProperty[];
|
|
53
|
+
triggerKeyDefinitions?: TriggerKeyDefinition[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class ConfigProperty {
|
|
57
|
+
slug: string;
|
|
58
|
+
propertyType: string;
|
|
59
|
+
options?: any[];
|
|
60
|
+
label: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface EventWorkflowActionDefinition {
|
|
64
|
+
id?: string;
|
|
65
|
+
identifier?: string;
|
|
66
|
+
name?: string;
|
|
67
|
+
executeFunctionString?: string;
|
|
68
|
+
ownerKey?: string;
|
|
69
|
+
public?: boolean;
|
|
70
|
+
configProperties?: ConfigProperty[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class TriggerKeyDefinition {
|
|
74
|
+
name: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
triggerKey: string;
|
|
77
|
+
external?: boolean;
|
|
78
|
+
}
|
package/src/auth/auth.ts
ADDED
package/src/auth/login.ts
CHANGED
|
@@ -1,89 +1,127 @@
|
|
|
1
|
-
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import { Request, setConfig } from '@contrail/sdk';
|
|
4
|
+
import { Auth, AuthContext } from './auth';
|
|
5
|
+
|
|
6
|
+
const CONFIGURATION = {
|
|
7
|
+
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
8
|
+
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function authUser(): Promise<AuthContext>{
|
|
12
|
+
const questions = [];
|
|
13
|
+
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
14
|
+
questions.push({
|
|
15
|
+
type: 'input',
|
|
16
|
+
name: 'email',
|
|
17
|
+
validate: (val) => !!val,
|
|
18
|
+
message: 'Email',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (!process.env.CONTRAIL_CLI_PASSWORD) {
|
|
22
|
+
questions.push({
|
|
23
|
+
type: 'password',
|
|
24
|
+
name: 'password',
|
|
25
|
+
validate: (val) => !!val,
|
|
26
|
+
message: 'Password',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (!process.env.CONTRAIL_CLI_ORGSLUG) {
|
|
30
|
+
questions.push({
|
|
31
|
+
type: 'input',
|
|
32
|
+
name: 'orgSlug',
|
|
33
|
+
validate: (val) => !!val,
|
|
34
|
+
message: 'Org (slug)',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const answers = await inquirer.prompt(questions);
|
|
39
|
+
const params = {
|
|
40
|
+
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
41
|
+
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
42
|
+
orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
|
|
43
|
+
};
|
|
44
|
+
if (!params.email || !params.password){
|
|
45
|
+
throw new Error('Email and Password required');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const poolData = {
|
|
49
|
+
UserPoolId: CONFIGURATION.userPoolId,
|
|
50
|
+
ClientId: CONFIGURATION.clientId,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
|
|
54
|
+
const authData = {
|
|
55
|
+
Username: params.email,
|
|
56
|
+
Password: params.password,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
|
|
60
|
+
const userData = {
|
|
61
|
+
Username: params.email,
|
|
62
|
+
Pool: userPool,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
|
|
66
|
+
|
|
67
|
+
return new Promise( (resolve, reject) => {
|
|
68
|
+
cognitoUser.authenticateUser(authDetails, {
|
|
69
|
+
onSuccess: async (result) => {
|
|
70
|
+
const user = result;
|
|
71
|
+
const config = await setAuthContext(user, params);
|
|
72
|
+
|
|
73
|
+
resolve(config);
|
|
74
|
+
},
|
|
75
|
+
onFailure: (err) => {
|
|
76
|
+
reject(err);
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function setAuthContext(user, params): Promise<AuthContext> {
|
|
83
|
+
|
|
84
|
+
// TODO Dont allow user to set this - they could set dev
|
|
85
|
+
const questions = [];
|
|
86
|
+
questions.push({
|
|
87
|
+
type: 'list',
|
|
88
|
+
name: 'environment',
|
|
89
|
+
message: 'Which environment would you like to use?',
|
|
90
|
+
choices: ['Dev', 'Prod'],
|
|
91
|
+
default: 'Dev',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
let apiGateway;
|
|
95
|
+
const answers = await inquirer.prompt(questions);
|
|
96
|
+
if (answers.environment === 'Dev') {
|
|
97
|
+
apiGateway = 'https://api.vibeiq.com/dev/api';
|
|
98
|
+
} else {
|
|
99
|
+
apiGateway = 'https://api.vibeiq.com/prod/api';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Set Auth Config
|
|
103
|
+
Auth.config = {
|
|
104
|
+
apiUserToken: user.idToken.jwtToken,
|
|
105
|
+
apiGateway,
|
|
106
|
+
orgSlug: params.orgSlug,
|
|
107
|
+
};
|
|
108
|
+
// SET SDK CONFIG
|
|
109
|
+
setConfig(Auth.config);
|
|
110
|
+
|
|
111
|
+
const currentUser = await Request.request('/users/current', {
|
|
112
|
+
method: 'GET',
|
|
113
|
+
headers: {
|
|
114
|
+
'Accept': 'application/json',
|
|
115
|
+
'Content-Type': 'application/json',
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
if (!currentUser) {
|
|
119
|
+
throw Error('Could not get current user');
|
|
120
|
+
}
|
|
121
|
+
const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
|
|
122
|
+
if (org) {
|
|
123
|
+
Auth.config.orgId = org.orgId || org.id;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return Object.assign({}, Auth.config);
|
|
127
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
import { create } from './create-app/create';
|
|
3
|
-
import { deployApp, removeApp } from './deploy-app/deploy';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
|
|
2
|
+
import { create } from './apps/create-app/create';
|
|
3
|
+
import { deployApp, removeApp } from './apps/deploy-app/deploy';
|
|
4
|
+
import { getTypes } from './types/types-extractor';
|
|
5
|
+
import { uploadTypes } from './types/types-uploader';
|
|
6
|
+
/**
|
|
7
|
+
* Built using documentation here:
|
|
8
|
+
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export async function cli(args) {
|
|
12
|
+
const command = args[2];
|
|
13
|
+
switch (command) {
|
|
14
|
+
case 'create-app': {
|
|
15
|
+
create(args);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case 'deploy-app': {
|
|
19
|
+
deployApp(args);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case 'remove-app': {
|
|
23
|
+
removeApp(args);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case 'extract-types': {
|
|
27
|
+
getTypes(args);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case 'upload-types': {
|
|
31
|
+
uploadTypes(args);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
default: {
|
|
35
|
+
console.log('Illegal command.');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|