@kumologica/sdk 4.0.0-beta1 → 4.0.0-beta2

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.
@@ -1,35 +1,53 @@
1
- exports.command = 'save';
1
+ const path = require('path');
2
+ const os = require('os');
3
+
4
+ exports.command = 'save [key]';
2
5
  exports.desc = `Saves kumologica license in local file system.\n
3
6
 
4
7
  Documentation:
5
8
  https://docs.kumologica.com/docs/references/cli/LicenseSave.html`;
6
9
 
7
- exports.builder = {
8
- "key": {
9
- describe: "The license key received in email from kumologica.com.\n ",
10
- type: 'string',
11
- alias: 'l',
12
- nargs: 1
10
+ exports.builder = (yargs) => {
11
+ yargs
12
+ .positional('key', {
13
+ describe: 'The license key received in email from kumologica.com.',
14
+ type: 'string',
15
+
16
+ demandOption: true // Makes the positional argument required
17
+ });
18
+ };
19
+
20
+ function getHomeDir() {
21
+ const platform = process.platform;
22
+ switch (platform) {
23
+ case 'win32':
24
+ return process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming');
25
+ case 'darwin':
26
+ return path.join(os.homedir(), 'Library', 'Application Support');
27
+ default:
28
+ return path.join(os.homedir(), '.config');
13
29
  }
14
30
  }
15
31
 
16
32
  function display(argv) {
17
- console.log(`\nSaving license key \n`);
33
+ console.log(`\nSaving license key ${argv.key}\n`);
18
34
  }
19
35
 
20
- const { saveLicense } = require('../../../../tools/src/license/index');
21
-
22
36
  exports.handler = function (argv) {
23
37
  display(argv);
24
38
 
25
39
  try {
26
40
 
27
41
  if (argv.key) {
28
- const electron = require('electron');
42
+ const electron = require('electron');
43
+ const tools = require('../../../src/app/lib/utils/tools.min.js');
44
+
45
+ const userDataPath = path.join(getHomeDir(), "Kumologica Designer");
29
46
 
47
+ console.log(`User data path: ${userDataPath}`);
30
48
  // Get the userDataPath directory
31
- const userDataPath = (electron.app || electron.remote.app).getPath('userData');
32
- saveLicense(userDataPath, argv.key);
49
+ //const userDataPath = (electron.app || electron.remote.app).getPath('userData');
50
+ tools.license.save(userDataPath, argv.key);
33
51
  console.log('License key saved successfully.');
34
52
  } else {
35
53
  console.log('No license key provided. Use the --key option to specify the license key.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumologica/sdk",
3
- "version": "4.0.0-beta1",
3
+ "version": "4.0.0-beta2",
4
4
  "productName": "Kumologica Designer",
5
5
  "copyright": "Copyright 2020 Kumologica Pty Ltd, All Rights Reserved.",
6
6
  "author": "Kumologica Pty Ltd <contact@kumologica.com>",
@@ -84,9 +84,9 @@
84
84
  "@aws-sdk/credential-providers": "^3.556.0",
85
85
  "@aws-sdk/lib-dynamodb": "^3.549.0",
86
86
  "@electron/remote": "^2.0.8",
87
- "@kumologica/builder": "4.0.0-beta1",
88
- "@kumologica/devkit": "4.0.0-beta1",
89
- "@kumologica/runtime": "4.0.0-beta1",
87
+ "@kumologica/builder": "4.0.0-beta2",
88
+ "@kumologica/devkit": "4.0.0-beta2",
89
+ "@kumologica/runtime": "4.0.0-beta2",
90
90
  "adm-zip": "0.4.13",
91
91
  "ajv": "8.10.0",
92
92
  "archive-type": "^4.0.0",
@@ -1 +1 @@
1
- require("crypto");var e,o,n,r,l=require("fs"),c=require("path");function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function t(){return o?e:(o=1,e={display:function(e){var o,l,r,n;e&&e.sub&&e.licenseType?({sub:e,email:o,licenseType:l,iat:r,exp:n}=e,console.log("--- License Details ---"),console.log("Subscriber: "+e),console.log("Email: "+o),console.log("License Type: "+l),console.log("Issued At: "+new Date(r).toLocaleString()),console.log("Expiry: "+("perpetual"===n?"Perpetual":new Date(n).toLocaleString())),console.log("------------------------")):console.error("Invalid license data.")},verify:function(e,o,l){return!0},save:function(e,o){var r=l,n=c.join(e,"kumologica.license");try{r.writeFileSync(n,o,"utf-8"),console.log("License saved successfully at: "+n)}catch(e){console.error("Failed to save license: "+e.message)}},read:function(e){var o=l,r=c.join(e,"kumologica.license");try{let e=o.readFileSync(r,"utf-8");return console.log("License read successfully from: "+r),e}catch(e){return console.error("Failed to read license: "+e.message),null}}})}var i=(()=>{if(r)return n;r=1;var e=t();return n={license:e}})(),u=s(i);module.exports=u;
1
+ var e,o,n,l,r=require("crypto"),s=require("fs"),t=require("path");function c(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function i(){if(!o){o=1;let i="base64";e={display:function(e){e?(console.log("--- License Details ---"),console.log("Subscriber: "+e.sub),console.log("Email: "+e.email),console.log("License Type: "+e.licenseType),console.log("Issued By: "+e.iss),console.log("Issued At: "+new Date(e.iat).toLocaleString()),console.log("Expiry: "+("perpetual"===e.exp?"Perpetual":new Date(e.exp).toLocaleString())),console.log("------------------------")):console.error("Invalid license data.")},verify:function(e){console.log("Verifying license..."),publicKeyPem=(()=>{var l=Buffer.from("XkI1bxBWOXhHBztkdXIuEXlKLBcSIWstZlEzOEADPyFCCVkUeQNIIxwWDU4QEiEyLHpfOjwHCVNlL3tTFiIvMGkcZCkOBnNgIjtybUckA3x7BRARDElXRxECPlB4OgF4aWIRDQAGLBI2Jns3eTINDkx+XSN9bAAFDHllInIdCEg8SzICC2JJJyl4CGk5JAB/EBQcLW4+dzcuMGxhLglhbHUZF2ZwFQMJEl08cAVfWGd5ADtje34SDUJCHxUlWh83aghXDnJXXwxxCFsUNANhCzJ0MHoiVyEvLlh2OC5gf2UwdGZhDxAvMllUcCgSWl1w",i).toString().split("").reverse().join("");let r="";for(let o=0;o<l.length;o++){let e="34jfd#d-cDFG23@W096ml".charCodeAt(o%21);r+=String.fromCharCode(l.charCodeAt(o)^e)}return Buffer.from(r,i).toString()})();var o=r,[e,l]=e.split(".");if(!e||!l)throw new Error("Invalid license format. Expected payload.signature");var e=Buffer.from(e,"base64url").toString("utf-8"),n=JSON.parse(e),e=Buffer.from(e,"utf-8"),l=Buffer.from(l,"base64url"),o=o.createVerify("SHA256");if(o.update(e),o.end(),o.verify(publicKeyPem,l))return console.log("✅ License is valid."),console.log("Issued To (sub):",n.sub),console.log("License Type:",n.licenseType),console.log("Expiry (exp):",n.exp),n;throw new Error("Invalid license signature. License may have been tampered.")},save:function(e,o){var l=s,r=t,r=(console.log("saving key to: "+e),r.join(e,"kumologica.license"));try{l.writeFileSync(r,o,"utf-8"),console.log("License saved successfully at: "+r)}catch(e){console.error("Failed to save license: "+e.message)}},read:function(e){var o=s,l=t.join(e,"kumologica.license");try{let e=o.readFileSync(l,"utf-8");return console.log("License read successfully from: "+l),e}catch(e){return console.error("Failed to read license: "+e.message),null}}}}return e}var a=(()=>{if(l)return n;l=1;var e=i();return n={license:e}})(),u=c(a);module.exports=u;
@@ -4,12 +4,13 @@ const {
4
4
  PLATFORMS,
5
5
  } = require("@kumologica/runtime");
6
6
  const tcpPortUsed = require("tcp-port-used");
7
-
8
7
  const os = require("os");
8
+
9
+ const tools = require('../app/lib/utils/tools.min.js');
9
10
  /**
10
11
  * This class will encapsulate the adminApp and FlowApp into two servers.
11
12
  * It will be the one running on the development box of the user (either local or remote),
12
- * and it will serve all the functioanlity to the Kumologica Cloud Editor.
13
+ * and it will serve all the functionality to the Kumologica Cloud Editor.
13
14
  */
14
15
 
15
16
  class DesignerServer {
@@ -40,8 +41,36 @@ class DesignerServer {
40
41
  );
41
42
  }
42
43
 
44
+ readLicense() {
45
+ const electron = require('electron');
46
+ const licensePath = (electron.app || electron.remote.app).getPath('userData');
47
+
48
+ console.log(`License path: ${licensePath}`);
49
+ console.log(`platform: ${this.config.platform}`);
50
+
51
+ const licenseData = tools.license.read(licensePath);
52
+ console.log(`License read from: ${licensePath}`);
53
+
54
+ return licenseData;
55
+ }
56
+
57
+ verifyLicense(licenseData) {
58
+ const lData = tools.license.verify(licenseData);
59
+ if (lData) {
60
+ tools.license.display(lData);
61
+ }
62
+ return lData;
63
+ }
64
+
43
65
  async start() {
44
66
  // Check if port passed by parameter is available otherwise allocate a new one
67
+
68
+ if (!process.env.KUMOLOGICA_LICENSE) {
69
+ process.env.KUMOLOGICA_LICENSE = this.readLicense();
70
+ }
71
+
72
+ this.verifyLicense(process.env.KUMOLOGICA_LICENSE);
73
+
45
74
  this.config.port = await this.allocatePort(this.config.port);
46
75
  this.flowServer = new AbstractServerfulServer(
47
76
  this.config,
@@ -1,115 +0,0 @@
1
- exports.command = 'kumohub';
2
- exports.desc = `Deploy kumologica flow to kumohub.io account`;
3
-
4
- exports.builder = {
5
- "flow-file-name": {
6
- describe: "The name of kumologica flow file.\n Auto search if not provided.\n",
7
- type: 'string',
8
- alias: 'f',
9
- nargs: 1
10
- },
11
- "service-name": {
12
- describe: "The name of service.\n flow file name without extension if not provided.\n Service name will be sanitized to be compatible with aws lambda name restrictions.\n",
13
- type: 'string',
14
- nargs: 1
15
- },
16
- "project-directory": {
17
- describe: "The root directory of project.\n Process working directory if not provided.\n",
18
- type: 'string',
19
- alias: 'd',
20
- nargs: 1
21
- },
22
- "environment": {
23
- describe: `Environment variables, JSON Syntax: '{"Variables": {"key": "value", ...}}'\n`,
24
- type: 'string',
25
- nargs: 1
26
- },
27
- "account": {
28
- describe: "The name of kumohub.io account\n",
29
- type: 'string',
30
- required: true,
31
- alias: 'a',
32
- nargs: 1
33
- },
34
- "username": {
35
- describe: "The username to login to kumohub.io account\n",
36
- type: 'string',
37
- required: true,
38
- alias: 'u',
39
- nargs: 1
40
- },
41
- "password": {
42
- describe: "The username password to login to kumohub.io account\n",
43
- type: 'string',
44
- required: true,
45
- alias: 'p',
46
- nargs: 1
47
- },
48
- "workspace": {
49
- describe: "The name of the workspace where flow to be deployed.\n",
50
- type: 'string',
51
- required: true,
52
- alias: 'w',
53
- nargs: 1
54
- },
55
- "stage": {
56
- describe: "The name of the stage where flow to be deployed\n",
57
- type: 'string',
58
- required: true,
59
- alias: 's',
60
- nargs: 1
61
- },
62
- "policy": {
63
- describe: "The name of security policy to assign to the flow.\n",
64
- type: 'string',
65
- required: true,
66
- default: "Public",
67
- nargs: 1
68
- },
69
- "memory": {
70
- describe: "The amount of memory (MB) to be allocated to the flow. 128 MB to 10240 MB\n",
71
- type: 'string',
72
- nargs: 1,
73
- default: "512"
74
- },
75
- "timeout": {
76
- describe: "The amount of seconds flow should be run before timing out. Up to 900 seconds\n",
77
- type: 'string',
78
- nargs: 1,
79
- default: "30"
80
- },
81
- "description": {
82
- describe: "The description of function.\n",
83
- type: 'string',
84
- nargs: 1
85
- }
86
- }
87
-
88
- function display(argv) {
89
- console.log(`\nDeploying flow to kumohub.io with following parameters: \n`);
90
- console.log('project-directory: %s', argv["project-directory"] || '');
91
- console.log('flow-file-name: %s', argv["flow-file-name"] || '');
92
- console.log('service-name: %s', argv["service-name"] || '');
93
- console.log('environment vars: %s', argv["environment"] || '');
94
- console.log('username: %s', argv["username"] || '');
95
- console.log('password: %s', argv["password"]? "provided": "missing");
96
- console.log('workspace: %s', argv["workspace"] || '');
97
- console.log('stage: %s', argv["stage"] || '');
98
- console.log('policy: %s', argv["policy"] || '');
99
- console.log('memory: %s', argv["memory"] || '');
100
- console.log('timeout: %s', argv["timeout"] || '');
101
- console.log('description: %s', argv["description"] || '');
102
- }
103
-
104
- exports.handler = function (argv) {
105
- display(argv);
106
-
107
- try {
108
- const { deploy } = require('@kumologica/builder');
109
- deploy('kumohub', argv);
110
- } catch (e) {
111
- console.log(`${e.message}`);
112
- process.exit(1);
113
- }
114
- }
115
-