neonctl 1.32.1 → 1.34.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.
- package/auth.js +7 -3
- package/commands/auth.js +3 -2
- package/commands/auth.test.js +5 -7
- package/commands/bootstrap/authjs-secret.js +6 -0
- package/commands/bootstrap/index.js +459 -196
- package/commands/bootstrap/index.test.js +5 -16
- package/commands/bootstrap/is-folder-empty.js +1 -1
- package/commands/branches.js +27 -20
- package/commands/branches.test.js +106 -195
- package/commands/connection_string.test.js +48 -105
- package/commands/databases.js +4 -4
- package/commands/databases.test.js +10 -22
- package/commands/help.test.js +4 -6
- package/commands/ip_allow.test.js +39 -63
- package/commands/operations.js +1 -1
- package/commands/operations.test.js +3 -7
- package/commands/orgs.test.js +3 -7
- package/commands/projects.test.js +80 -124
- package/commands/roles.js +3 -3
- package/commands/roles.test.js +16 -21
- package/commands/set_context.js +1 -1
- package/commands/set_context.test.js +65 -62
- package/config.js +1 -1
- package/context.js +2 -2
- package/help.js +1 -1
- package/index.js +7 -3
- package/package.json +9 -7
- package/parameters.gen.js +4 -4
- package/test_utils/fixtures.js +84 -0
- package/writer.js +1 -1
- package/test_utils/mock_server.js +0 -16
- package/test_utils/test_cli_command.js +0 -80
package/auth.js
CHANGED
|
@@ -63,7 +63,7 @@ export const auth = async ({ oauthHost, clientId }) => {
|
|
|
63
63
|
const timer = setTimeout(() => {
|
|
64
64
|
reject(new Error(`Authentication timed out after ${AUTH_TIMEOUT_SECONDS} seconds`));
|
|
65
65
|
}, AUTH_TIMEOUT_SECONDS * 1000);
|
|
66
|
-
|
|
66
|
+
const onRequest = async (request, response) => {
|
|
67
67
|
//
|
|
68
68
|
// Wait for callback and follow oauth flow.
|
|
69
69
|
//
|
|
@@ -93,6 +93,9 @@ export const auth = async ({ oauthHost, clientId }) => {
|
|
|
93
93
|
clearTimeout(timer);
|
|
94
94
|
resolve(tokenSet);
|
|
95
95
|
server.close();
|
|
96
|
+
};
|
|
97
|
+
server.on('request', (req, res) => {
|
|
98
|
+
void onRequest(req, res);
|
|
96
99
|
});
|
|
97
100
|
//
|
|
98
101
|
// Open browser to let user authenticate
|
|
@@ -108,8 +111,9 @@ export const auth = async ({ oauthHost, clientId }) => {
|
|
|
108
111
|
log.info(`Auth Url: ${authUrl}`);
|
|
109
112
|
open(authUrl).catch((err) => {
|
|
110
113
|
const msg = `Failed to open web browser. Please copy & paste auth url to authenticate in browser.`;
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
const typedErr = err && err instanceof Error ? err : undefined;
|
|
115
|
+
sendError(typedErr || new Error(msg), matchErrorCode(msg));
|
|
116
|
+
log.error(msg);
|
|
113
117
|
});
|
|
114
118
|
});
|
|
115
119
|
};
|
package/commands/auth.js
CHANGED
|
@@ -64,8 +64,9 @@ export const ensureAuth = async (props) => {
|
|
|
64
64
|
const refreshedTokenSet = await refreshToken({
|
|
65
65
|
oauthHost: props.oauthHost,
|
|
66
66
|
clientId: props.clientId,
|
|
67
|
-
}, tokenSet).catch((
|
|
68
|
-
|
|
67
|
+
}, tokenSet).catch((err) => {
|
|
68
|
+
const typedErr = err && err instanceof Error ? err : undefined;
|
|
69
|
+
log.error('failed to refresh token\n%s', typedErr?.message);
|
|
69
70
|
process.exit(1);
|
|
70
71
|
});
|
|
71
72
|
props.apiKey = refreshedTokenSet.access_token || 'UNKNOWN';
|
package/commands/auth.test.js
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { vi, beforeAll, describe,
|
|
2
|
+
import { vi, beforeAll, describe, afterAll, expect } from 'vitest';
|
|
3
3
|
import { mkdtempSync, rmSync, readFileSync } from 'node:fs';
|
|
4
4
|
import { startOauthServer } from '../test_utils/oauth_server';
|
|
5
|
-
import {
|
|
5
|
+
import { test } from '../test_utils/fixtures';
|
|
6
6
|
import { authFlow } from './auth';
|
|
7
7
|
vi.mock('open', () => ({ default: vi.fn((url) => axios.get(url)) }));
|
|
8
8
|
vi.mock('../pkg.ts', () => ({ default: { version: '0.0.0' } }));
|
|
9
9
|
describe('auth', () => {
|
|
10
10
|
let configDir = '';
|
|
11
11
|
let oauthServer;
|
|
12
|
-
let mockServer;
|
|
13
12
|
beforeAll(async () => {
|
|
14
13
|
configDir = mkdtempSync('test-config');
|
|
15
14
|
oauthServer = await startOauthServer();
|
|
16
|
-
mockServer = await runMockServer('main');
|
|
17
15
|
});
|
|
18
16
|
afterAll(async () => {
|
|
19
17
|
rmSync(configDir, { recursive: true });
|
|
20
18
|
await oauthServer.stop();
|
|
21
|
-
await new Promise((resolve) => mockServer.close(resolve));
|
|
22
19
|
});
|
|
23
|
-
test('should auth', async () => {
|
|
20
|
+
test('should auth', async ({ runMockServer }) => {
|
|
21
|
+
const server = await runMockServer('main');
|
|
24
22
|
await authFlow({
|
|
25
23
|
_: ['auth'],
|
|
26
|
-
apiHost: `http://localhost:${
|
|
24
|
+
apiHost: `http://localhost:${server.address().port}`,
|
|
27
25
|
clientId: 'test-client-id',
|
|
28
26
|
configDir,
|
|
29
27
|
forceAuth: true,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// See https://github.com/nextauthjs/cli/blob/8443988fe7e7f078ead32288dcd1b01b9443f13a/commands/secret.js#L9
|
|
2
|
+
// for reference.
|
|
3
|
+
export function getAuthjsSecret() {
|
|
4
|
+
const bytes = crypto.getRandomValues(new Uint8Array(32));
|
|
5
|
+
return Buffer.from(bytes.toString(), 'base64').toString('base64');
|
|
6
|
+
}
|