neonctl 0.2.1 → 0.3.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/package.json +1 -1
- package/src/callback.html +3 -0
- package/src/commands/auth.js +6 -5
- package/src/config.js +1 -1
- package/src/index.js +32 -20
package/package.json
CHANGED
package/src/callback.html
CHANGED
package/src/commands/auth.js
CHANGED
|
@@ -38,7 +38,7 @@ const node_fs_1 = require("node:fs");
|
|
|
38
38
|
const auth_1 = require("../auth");
|
|
39
39
|
const log_1 = require("../log");
|
|
40
40
|
const CREDENTIALS_FILE = 'credentials.json';
|
|
41
|
-
const authFlow = ({ configDir, oauthHost, clientId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
const authFlow = ({ 'config-dir': configDir, 'oauth-host': oauthHost, 'client-id': clientId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
42
|
if (!clientId) {
|
|
43
43
|
throw new Error('Missing client id');
|
|
44
44
|
}
|
|
@@ -54,21 +54,22 @@ const authFlow = ({ configDir, oauthHost, clientId, }) => __awaiter(void 0, void
|
|
|
54
54
|
});
|
|
55
55
|
exports.authFlow = authFlow;
|
|
56
56
|
const ensureAuth = (props) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
if (props._[0] === 'auth') {
|
|
57
|
+
if (props.token || props._[0] === 'auth') {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
const credentialsPath = (0, node_path_1.join)(props
|
|
60
|
+
const credentialsPath = (0, node_path_1.join)(props['config-dir'], CREDENTIALS_FILE);
|
|
61
61
|
if ((0, node_fs_1.existsSync)(credentialsPath)) {
|
|
62
62
|
try {
|
|
63
63
|
const token = (yield Promise.resolve().then(() => __importStar(require(credentialsPath)))).access_token;
|
|
64
64
|
props.token = token;
|
|
65
|
+
return;
|
|
65
66
|
}
|
|
66
67
|
catch (e) {
|
|
67
|
-
|
|
68
|
+
yield (0, exports.authFlow)(props);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
else {
|
|
71
|
-
|
|
72
|
+
yield (0, exports.authFlow)(props);
|
|
72
73
|
}
|
|
73
74
|
});
|
|
74
75
|
exports.ensureAuth = ensureAuth;
|
package/src/config.js
CHANGED
|
@@ -14,7 +14,7 @@ const node_path_1 = require("node:path");
|
|
|
14
14
|
const node_fs_1 = require("node:fs");
|
|
15
15
|
const DIR_NAME = '.neonctl';
|
|
16
16
|
exports.defaultDir = (0, node_path_1.join)(process.cwd(), DIR_NAME);
|
|
17
|
-
const ensureConfigDir = ({ configDir, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const ensureConfigDir = ({ 'config-dir': configDir, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
if (!(0, node_fs_1.existsSync)(configDir)) {
|
|
19
19
|
(0, node_fs_1.mkdirSync)(configDir);
|
|
20
20
|
}
|
package/src/index.js
CHANGED
|
@@ -41,39 +41,41 @@ const gateway_1 = require("./api/gateway");
|
|
|
41
41
|
const auth_1 = require("./commands/auth");
|
|
42
42
|
const config_1 = require("./config");
|
|
43
43
|
const log_1 = require("./log");
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
if (_.length === 1) {
|
|
44
|
+
const showHelpMiddleware = (argv) => {
|
|
45
|
+
if (argv._.length === 1) {
|
|
47
46
|
yargs.showHelp();
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
});
|
|
48
|
+
};
|
|
51
49
|
const builder = yargs
|
|
52
50
|
.scriptName(package_json_1.default.name)
|
|
53
51
|
.usage('usage: $0 <cmd> [args]')
|
|
54
52
|
.help()
|
|
55
|
-
.option('
|
|
53
|
+
.option('json', {
|
|
54
|
+
describe: 'Set output format to JSON',
|
|
55
|
+
type: 'boolean',
|
|
56
|
+
})
|
|
57
|
+
.option('api-host', {
|
|
56
58
|
describe: 'The API host',
|
|
57
59
|
default: 'https://console.neon.tech',
|
|
58
60
|
})
|
|
59
61
|
// Setup config directory
|
|
60
|
-
.option('
|
|
62
|
+
.option('config-dir', {
|
|
61
63
|
describe: 'Path to config directory',
|
|
62
64
|
type: 'string',
|
|
63
65
|
default: config_1.defaultDir,
|
|
64
66
|
})
|
|
65
67
|
.middleware(config_1.ensureConfigDir)
|
|
66
68
|
// Auth flow
|
|
67
|
-
.
|
|
68
|
-
.option('oauthHost', {
|
|
69
|
+
.option('oauth-host', {
|
|
69
70
|
description: 'URL to Neon OAUTH host',
|
|
70
71
|
default: 'https://oauth2.neon.tech',
|
|
71
72
|
})
|
|
72
|
-
.option('
|
|
73
|
+
.option('client-id', {
|
|
73
74
|
description: 'OAuth client id',
|
|
74
75
|
type: 'string',
|
|
75
|
-
|
|
76
|
-
})
|
|
76
|
+
default: 'neonctl',
|
|
77
|
+
})
|
|
78
|
+
.command('auth', 'Authenticate user', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
79
|
(yield Promise.resolve().then(() => __importStar(require('./commands/auth')))).authFlow(args);
|
|
78
80
|
}))
|
|
79
81
|
// Ensure auth token
|
|
@@ -86,14 +88,23 @@ const builder = yargs
|
|
|
86
88
|
.command('me', 'Get user info', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
89
|
yield (yield Promise.resolve().then(() => __importStar(require('./commands/users')))).me(args);
|
|
88
90
|
}))
|
|
89
|
-
.command('projects', 'Manage projects', (yargs) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
.command('projects', 'Manage projects', (yargs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
yargs
|
|
93
|
+
.usage('usage: $0 projects <cmd> [args]')
|
|
94
|
+
// .command(
|
|
95
|
+
// 'list',
|
|
96
|
+
// 'List projects',
|
|
97
|
+
// (yargs) => yargs,
|
|
98
|
+
// async (args) => {
|
|
99
|
+
// await (await import('./commands/projects')).list(args);
|
|
100
|
+
// }
|
|
101
|
+
// )
|
|
102
|
+
.command('create', 'Create a project', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).create(args);
|
|
104
|
+
}))
|
|
105
|
+
.middleware(showHelpMiddleware);
|
|
93
106
|
}))
|
|
94
|
-
.
|
|
95
|
-
yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).create(args);
|
|
96
|
-
}))))
|
|
107
|
+
.strict()
|
|
97
108
|
.fail((msg, err) => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
109
|
if (err instanceof gateway_1.ApiError) {
|
|
99
110
|
log_1.log.error(yield err.getApiError());
|
|
@@ -104,7 +115,8 @@ const builder = yargs
|
|
|
104
115
|
process.exit(1);
|
|
105
116
|
}));
|
|
106
117
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
-
|
|
118
|
+
const args = yield builder.argv;
|
|
119
|
+
if (args._.length === 0) {
|
|
108
120
|
yargs.showHelp();
|
|
109
121
|
}
|
|
110
122
|
}))();
|