@p0security/cli 0.3.0

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.
Files changed (103) hide show
  1. package/CONTRIBUTING.md +23 -0
  2. package/LICENSE.md +675 -0
  3. package/README.md +201 -0
  4. package/dist/commands/__tests__/login.test.d.ts +1 -0
  5. package/dist/commands/__tests__/login.test.js +75 -0
  6. package/dist/commands/__tests__/ls.test.d.ts +1 -0
  7. package/dist/commands/__tests__/ls.test.js +84 -0
  8. package/dist/commands/__tests__/request.test.d.ts +1 -0
  9. package/dist/commands/__tests__/request.test.js +94 -0
  10. package/dist/commands/__tests__/ssh.test.d.ts +1 -0
  11. package/dist/commands/__tests__/ssh.test.js +107 -0
  12. package/dist/commands/aws/__tests__/__input__/saml-response.d.ts +11 -0
  13. package/dist/commands/aws/__tests__/__input__/saml-response.js +18 -0
  14. package/dist/commands/aws/__tests__/__input__/sts-response.d.ts +11 -0
  15. package/dist/commands/aws/__tests__/__input__/sts-response.js +37 -0
  16. package/dist/commands/aws/__tests__/role.test.d.ts +1 -0
  17. package/dist/commands/aws/__tests__/role.test.js +98 -0
  18. package/dist/commands/aws/index.d.ts +4 -0
  19. package/dist/commands/aws/index.js +26 -0
  20. package/dist/commands/aws/role.d.ts +27 -0
  21. package/dist/commands/aws/role.js +123 -0
  22. package/dist/commands/index.d.ts +2 -0
  23. package/dist/commands/index.js +49 -0
  24. package/dist/commands/login.d.ts +14 -0
  25. package/dist/commands/login.js +93 -0
  26. package/dist/commands/ls.d.ts +4 -0
  27. package/dist/commands/ls.js +78 -0
  28. package/dist/commands/request.d.ts +12 -0
  29. package/dist/commands/request.js +116 -0
  30. package/dist/commands/ssh.d.ts +11 -0
  31. package/dist/commands/ssh.js +154 -0
  32. package/dist/common/auth/oidc.d.ts +4 -0
  33. package/dist/common/auth/oidc.js +18 -0
  34. package/dist/common/auth/server.d.ts +15 -0
  35. package/dist/common/auth/server.js +73 -0
  36. package/dist/common/fetch.d.ts +16 -0
  37. package/dist/common/fetch.js +39 -0
  38. package/dist/common/mime.d.ts +14 -0
  39. package/dist/common/mime.js +17 -0
  40. package/dist/common/xml.d.ts +21 -0
  41. package/dist/common/xml.js +52 -0
  42. package/dist/drivers/__mocks__/auth.d.ts +30 -0
  43. package/dist/drivers/__mocks__/auth.js +46 -0
  44. package/dist/drivers/api.d.ts +3 -0
  45. package/dist/drivers/api.js +69 -0
  46. package/dist/drivers/auth.d.ts +11 -0
  47. package/dist/drivers/auth.js +122 -0
  48. package/dist/drivers/env.d.ts +15 -0
  49. package/dist/drivers/env.js +38 -0
  50. package/dist/drivers/firestore.d.ts +10 -0
  51. package/dist/drivers/firestore.js +53 -0
  52. package/dist/drivers/stdio.d.ts +25 -0
  53. package/dist/drivers/stdio.js +44 -0
  54. package/dist/index.d.ts +1 -0
  55. package/dist/index.js +23 -0
  56. package/dist/middlewares/version.d.ts +8 -0
  57. package/dist/middlewares/version.js +77 -0
  58. package/dist/plugins/__mocks__/login.d.ts +14 -0
  59. package/dist/plugins/__mocks__/login.js +24 -0
  60. package/dist/plugins/aws/__mocks__/assumeRole.d.ts +12 -0
  61. package/dist/plugins/aws/__mocks__/assumeRole.js +20 -0
  62. package/dist/plugins/aws/api.d.ts +12 -0
  63. package/dist/plugins/aws/api.js +16 -0
  64. package/dist/plugins/aws/assumeRole.d.ts +14 -0
  65. package/dist/plugins/aws/assumeRole.js +55 -0
  66. package/dist/plugins/aws/config.d.ts +5 -0
  67. package/dist/plugins/aws/config.js +38 -0
  68. package/dist/plugins/aws/ssm/index.d.ts +18 -0
  69. package/dist/plugins/aws/ssm/index.js +274 -0
  70. package/dist/plugins/aws/ssm/install.d.ts +7 -0
  71. package/dist/plugins/aws/ssm/install.js +133 -0
  72. package/dist/plugins/aws/types.d.ts +54 -0
  73. package/dist/plugins/aws/types.js +2 -0
  74. package/dist/plugins/google/login.d.ts +2 -0
  75. package/dist/plugins/google/login.js +76 -0
  76. package/dist/plugins/login.d.ts +13 -0
  77. package/dist/plugins/login.js +19 -0
  78. package/dist/plugins/okta/aws.d.ts +5 -0
  79. package/dist/plugins/okta/aws.js +42 -0
  80. package/dist/plugins/okta/login.d.ts +8 -0
  81. package/dist/plugins/okta/login.js +165 -0
  82. package/dist/plugins/ssh/types.d.ts +22 -0
  83. package/dist/plugins/ssh/types.js +2 -0
  84. package/dist/public/favicon.ico +0 -0
  85. package/dist/public/redirect-landing.html +40 -0
  86. package/dist/testing/firestore.d.ts +2 -0
  87. package/dist/testing/firestore.js +16 -0
  88. package/dist/testing/yargs.d.ts +12 -0
  89. package/dist/testing/yargs.js +23 -0
  90. package/dist/types/identity.d.ts +23 -0
  91. package/dist/types/identity.js +2 -0
  92. package/dist/types/index.d.ts +11 -0
  93. package/dist/types/index.js +15 -0
  94. package/dist/types/oidc.d.ts +41 -0
  95. package/dist/types/oidc.js +2 -0
  96. package/dist/types/org.d.ts +20 -0
  97. package/dist/types/org.js +2 -0
  98. package/dist/types/request.d.ts +35 -0
  99. package/dist/types/request.js +20 -0
  100. package/dist/util.d.ts +42 -0
  101. package/dist/util.js +87 -0
  102. package/p0 +16 -0
  103. package/package.json +70 -0
package/dist/util.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ /** Copyright © 2024-present P0 Security
2
+
3
+ This file is part of @p0security/cli
4
+
5
+ @p0security/cli is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
6
+
7
+ @p0security/cli is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8
+
9
+ You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
10
+ **/
11
+ import child_process from "node:child_process";
12
+ export declare const P0_PATH: string;
13
+ /** Waits the specified delay (in ms)
14
+ *
15
+ * The returned promise is cancelable:
16
+ * ```
17
+ * const wait = sleep(10);
18
+ * ...
19
+ * wait.cancel();
20
+ * ```
21
+ */
22
+ export declare const sleep: (timeoutMillis: number) => Promise<void> & {
23
+ cancel: () => void;
24
+ };
25
+ /** Wrap a promise in a timeout
26
+ *
27
+ * If the promise does not resolve within the interval, throws an
28
+ * error.
29
+ */
30
+ export declare const timeout: <T extends unknown>(promise: Promise<NonNullable<T>>, timeoutMillis: number) => Promise<T & {}>;
31
+ /** Executes a subprocess, waiting for exit, and collecting all output
32
+ *
33
+ * Throws an error if the exit code is non-zero
34
+ */
35
+ export declare const exec: (command: string, args: string[], options?: child_process.SpawnOptionsWithoutStdio & {
36
+ /** If true, throws an error if exit code is non-zero */
37
+ check?: boolean;
38
+ }) => Promise<{
39
+ code: number | null;
40
+ stdout: string;
41
+ stderr: string;
42
+ }>;
package/dist/util.js ADDED
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.exec = exports.timeout = exports.sleep = exports.P0_PATH = void 0;
16
+ /** Copyright © 2024-present P0 Security
17
+
18
+ This file is part of @p0security/cli
19
+
20
+ @p0security/cli is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
21
+
22
+ @p0security/cli is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
25
+ **/
26
+ const node_child_process_1 = __importDefault(require("node:child_process"));
27
+ const node_os_1 = __importDefault(require("node:os"));
28
+ const node_path_1 = __importDefault(require("node:path"));
29
+ exports.P0_PATH = node_path_1.default.join(node_os_1.default.homedir(), ".p0");
30
+ /** Waits the specified delay (in ms)
31
+ *
32
+ * The returned promise is cancelable:
33
+ * ```
34
+ * const wait = sleep(10);
35
+ * ...
36
+ * wait.cancel();
37
+ * ```
38
+ */
39
+ const sleep = (timeoutMillis) => {
40
+ let timer = undefined;
41
+ const promise = new Promise((resolve) => {
42
+ timer = setTimeout(resolve, timeoutMillis);
43
+ });
44
+ return Object.assign(promise, { cancel: () => clearTimeout(timer) });
45
+ };
46
+ exports.sleep = sleep;
47
+ /** Wrap a promise in a timeout
48
+ *
49
+ * If the promise does not resolve within the interval, throws an
50
+ * error.
51
+ */
52
+ const timeout = (promise, timeoutMillis) => __awaiter(void 0, void 0, void 0, function* () {
53
+ const wait = (0, exports.sleep)(timeoutMillis);
54
+ const result = yield Promise.race([wait, promise]);
55
+ if (result === undefined)
56
+ throw new Error("Timeout");
57
+ wait.cancel();
58
+ return result;
59
+ });
60
+ exports.timeout = timeout;
61
+ /** Executes a subprocess, waiting for exit, and collecting all output
62
+ *
63
+ * Throws an error if the exit code is non-zero
64
+ */
65
+ const exec = (command, args, options) => __awaiter(void 0, void 0, void 0, function* () {
66
+ return new Promise((resolve, reject) => {
67
+ try {
68
+ const out = [];
69
+ const err = [];
70
+ const child = node_child_process_1.default.spawn(command, args, Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), { stdio: "pipe" }));
71
+ child.stdout.on("data", (d) => out.push(d));
72
+ child.stderr.on("data", (d) => err.push(d));
73
+ child.on("exit", (code) => {
74
+ const stdout = out.join("\n");
75
+ const stderr = err.join("\n");
76
+ const result = { code, stdout, stderr };
77
+ if (code !== 0 && (options === null || options === void 0 ? void 0 : options.check))
78
+ reject(Object.assign(new Error("Sub-process exited with code"), result));
79
+ resolve(result);
80
+ });
81
+ }
82
+ catch (error) {
83
+ reject(error);
84
+ }
85
+ });
86
+ });
87
+ exports.exec = exec;
package/p0 ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node --no-deprecation
2
+
3
+ const originalEmit = process.emit;
4
+ process.emit = function (name, data, ...args) {
5
+ if (
6
+ name === `warning` &&
7
+ typeof data === `object` &&
8
+ data.name === `ExperimentalWarning` &&
9
+ data.message.startsWith(`The Fetch API is an experimental feature.`)
10
+ ) {
11
+ return false;
12
+ }
13
+ return originalEmit.apply(process, arguments);
14
+ };
15
+
16
+ require(`${__dirname}/dist/index.js`).main();
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@p0security/cli",
3
+ "version": "0.3.0",
4
+ "description": "Execute infra CLI commands with P0 grants",
5
+ "main": "index.ts",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/p0-security/p0cli.git"
9
+ },
10
+ "author": "P0 Security",
11
+ "license": "GPL-3.0-only",
12
+ "bin": {
13
+ "p0": "p0"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "p0",
18
+ "README.md",
19
+ "CONTRIBUTING.md",
20
+ "LICENSE.md"
21
+ ],
22
+ "dependencies": {
23
+ "@rgrove/parse-xml": "^4.1.0",
24
+ "dotenv": "^16.4.1",
25
+ "express": "^4.18.2",
26
+ "firebase": "^10.7.2",
27
+ "inquirer": "^9.2.15",
28
+ "jsdom": "^24.0.0",
29
+ "lodash": "^4.17.21",
30
+ "open": "^8.4.0",
31
+ "pkce-challenge": "^4.1.0",
32
+ "pluralize": "^8.0.0",
33
+ "ps-tree": "^1.2.0",
34
+ "typescript": "^4.8.4",
35
+ "which": "^4.0.0",
36
+ "yargs": "^17.6.0"
37
+ },
38
+ "devDependencies": {
39
+ "@trivago/prettier-plugin-sort-imports": "^4.3.0",
40
+ "@types/express": "^4.17.21",
41
+ "@types/inquirer": "^9.0.7",
42
+ "@types/jest": "^29.5.12",
43
+ "@types/jsdom": "^21.1.6",
44
+ "@types/lodash": "^4.14.202",
45
+ "@types/node": "^18.11.7",
46
+ "@types/pluralize": "^0.0.33",
47
+ "@types/ps-tree": "^1.1.6",
48
+ "@types/which": "^3.0.3",
49
+ "@types/yargs": "^17.0.13",
50
+ "@typescript-eslint/eslint-plugin": "^6.4.0",
51
+ "@typescript-eslint/parser": "^6.0.0",
52
+ "eslint": "^8.56.0",
53
+ "eslint-config-prettier": "^9.1.0",
54
+ "eslint-config-standard-with-typescript": "^43.0.1",
55
+ "eslint-plugin-import": "^2.29.1",
56
+ "eslint-plugin-n": "^16.6.2",
57
+ "eslint-plugin-notice": "^0.9.10",
58
+ "eslint-plugin-promise": "^6.1.1",
59
+ "jest": "^29.7.0",
60
+ "prettier": "^3.2.4",
61
+ "ts-jest": "^29.1.2"
62
+ },
63
+ "scripts": {
64
+ "build": "tsc && cp -r public dist/",
65
+ "clean": "rm tsconfig.tsbuildinfo && rm -rf dist/",
66
+ "lint": "yarn prettier --check . && yarn run eslint --max-warnings 0 .",
67
+ "p0": "node --no-deprecation ./p0",
68
+ "prepublishOnly": "npm run clean && npm run build"
69
+ }
70
+ }