Skip to content

Commit 92bf7b3

Browse files
committed
Fixed bugs:
- Check for login expiration was in milliseconds (should be seconds) - The proper node binary was not used by connect handlers - Lack of refresh command name + Deploy script
1 parent b24f2a9 commit 92bf7b3

File tree

9 files changed

+30
-33
lines changed

9 files changed

+30
-33
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@
139139
"test": "vitest",
140140
"version": "oclif readme && git add README.md",
141141
"start:dev": "./bin/dev.js",
142-
"start:vm": "npm run build && npm run pack:macos && npm run start:vm"
142+
"start:vm": "npm run build && npm run pack:macos && npm run start:vm",
143+
"deploy": "npm run pkg && npm run notarize && npm run upload"
143144
},
144145
"version": "1.0.0",
145146
"bugs": "https://github.com/kevinwang5658/codify/issues",

src/connect/http-routes/handlers/apply-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function applyHandler() {
2929

3030
session.additionalData.filePath = filePath;
3131

32-
return spawn('zsh', ['-c', `${ConnectOrchestrator.rootCommand} apply -p ${filePath}`], {
32+
return spawn('zsh', ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} apply -p ${filePath}`], {
3333
name: 'xterm-color',
3434
cols: 80,
3535
rows: 30,

src/connect/http-routes/handlers/import-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function importHandler() {
5555
}
5656
}
5757

58-
return spawn('zsh', ['-c', `${ConnectOrchestrator.rootCommand} import ${args} -p ${filePath}`], {
58+
return spawn('zsh', ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} import ${args} -p ${filePath}`], {
5959
name: 'xterm-color',
6060
cols: 80,
6161
rows: 30,

src/connect/http-routes/handlers/plan-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function planHandler() {
2929

3030
session.additionalData.filePath = filePath;
3131

32-
return spawn('zsh', ['-c', `${ConnectOrchestrator.rootCommand} plan -p ${filePath}`], {
32+
return spawn('zsh', ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} plan -p ${filePath}`], {
3333
name: 'xterm-color',
3434
cols: 80,
3535
rows: 30,

src/connect/http-routes/handlers/refresh-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function refreshHandler() {
5555
}
5656
}
5757

58-
return spawn('zsh', ['-c', `${ConnectOrchestrator.rootCommand} refresh ${args} -p ${filePath}`], {
58+
return spawn('zsh', ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} refresh ${args} -p ${filePath}`], {
5959
name: 'xterm-color',
6060
cols: 80,
6161
rows: 30,

src/connect/login-helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export class LoginHelper {
3535
return LoginHelper.instance;
3636
}
3737

38-
if (new Date(credentials.expiry).getTime() < Date.now()) {
38+
// Expiry dates are in seconds, Date.now() is in milliseconds
39+
if (new Date(credentials.expiry).getTime() < (Date.now() / 1000)) {
3940
LoginHelper.instance = new LoginHelper(false);
4041
return LoginHelper.instance;
4142
}

src/orchestrators/connect.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { LoginOrchestrator } from './login.js';
1212

1313
export class ConnectOrchestrator {
1414
static rootCommand: string;
15+
static nodeBinary: string;
1516

1617
static async run(oclifConfig: Config, openBrowser = true, onOpen?: (connectionCode: string) => void) {
1718
const login = LoginHelper.get()?.isLoggedIn;
@@ -21,14 +22,15 @@ export class ConnectOrchestrator {
2122
}
2223

2324
this.rootCommand = oclifConfig.options.root;
25+
this.nodeBinary = process.execPath;
2426

2527
const connectionSecret = ConnectOrchestrator.tokenGenerate()
2628
const app = express();
27-
29+
2830
app.use(cors({ origin: config.corsAllowedOrigins }))
2931
app.use(json())
3032
app.use(router);
31-
33+
3234
const server = app.listen(config.connectServerPort, (error) => {
3335
if (error) {
3436
if (error.message.includes('EADDRINUSE')) {

src/orchestrators/login.ts

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,28 @@ Manually open it here: ${config.dashboardUrl}/auth/cli`
4545
open(`${config.dashboardUrl}/auth/cli`);
4646
})
4747

48-
await Promise.race([
49-
new Promise<void>((resolve, reject) => {
50-
app.post('/', async (req, res) => {
51-
try {
52-
const body = req.body as Credentials;
48+
await new Promise<void>((resolve, reject) => {
49+
app.post('/', async (req, res) => {
50+
try {
51+
const body = req.body as Credentials;
5352

54-
if (!ajv.validate(schema, body)) {
55-
console.error(chalk.red('Received invalid credentials. Please submit a support ticket'))
56-
return res.status(400).send({ message: ajv.errorsText() })
57-
}
53+
if (!ajv.validate(schema, body)) {
54+
console.error(chalk.red('Received invalid credentials. Please submit a support ticket'))
55+
return res.status(400).send({ message: ajv.errorsText() })
56+
}
5857

59-
console.log(chalk.green('\nSuccessfully received sign-in credentials...'))
58+
console.log(chalk.green('\nSuccessfully received sign-in credentials...'))
6059

61-
await LoginHelper.save(body.accessToken);
62-
res.sendStatus(200);
60+
await LoginHelper.save(body.accessToken);
61+
res.sendStatus(200);
6362

64-
resolve();
65-
} catch (error) {
66-
console.error(error);
67-
reject(error);
68-
}
69-
});
70-
}),
71-
new Promise<void>((resolve) => {
72-
setTimeout(() => {
73-
console.error(chalk.red('Did not receive sign-in credentials in 5 minutes, please re-run the command'));
7463
resolve();
75-
}, 5 * 60 * 1000);
76-
})
77-
])
64+
} catch (error) {
65+
console.error(error);
66+
reject(error);
67+
}
68+
});
69+
})
7870

7971
server.close(() => {});
8072
}

src/ui/reporters/default-reporter.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const ProgressLabelMapping = {
2222
[ProcessName.APPLY]: 'Codify apply',
2323
[ProcessName.PLAN]: 'Codify plan',
2424
[ProcessName.DESTROY]: 'Codify destroy',
25+
[ProcessName.REFRESH]: 'Codify refresh',
2526
[ProcessName.IMPORT]: 'Codify import',
2627
[ProcessName.INIT]: 'Codify init',
2728
[SubProcessName.APPLYING_RESOURCE]: 'Applying resource',

0 commit comments

Comments
 (0)