Skip to content

Commit d40847c

Browse files
committed
add auth_token to other events after auth_token_configured
1 parent 55f9011 commit d40847c

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

src/plugins/setup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
checkIsAuthenticated,
66
requestAuthentication,
77
saveAuthToken,
8+
readAuthToken,
89
} from "../utils/authenticate.ts";
910
import { configureAwsProfiles } from "../utils/configure-aws.ts";
1011
import { runInstallProcess } from "../utils/install.ts";
@@ -100,6 +101,7 @@ export default createPlugin(
100101
namespace: "onboarding",
101102
steps: [1, 2, 3],
102103
status: "CANCELLED",
104+
auth_token: await readAuthToken(),
103105
},
104106
});
105107
return;
@@ -236,6 +238,7 @@ export default createPlugin(
236238
namespace: "onboarding",
237239
steps: [1, 2, 3],
238240
status: "COMPLETED",
241+
auth_token: await readAuthToken(),
239242
},
240243
});
241244
},

src/utils/authenticate.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export async function checkIsAuthenticated() {
131131
return false;
132132
}
133133
return true;
134-
} catch (error) {
134+
} catch {
135135
return false;
136136
}
137137
}
@@ -143,3 +143,21 @@ function isAuthTokenPresent(authObject: unknown) {
143143
AUTH_TOKEN_KEY in authObject
144144
);
145145
}
146+
147+
// Reads the auth token from the auth.json file for logging in the user
148+
export async function readAuthToken(): Promise<string> {
149+
try {
150+
const authJson = await fs.readFile(LOCALSTACK_AUTH_FILENAME, "utf-8");
151+
const authObject = JSON.parse(authJson) as unknown;
152+
if (!isAuthTokenPresent(authObject)) {
153+
return "";
154+
}
155+
const authToken = authObject[AUTH_TOKEN_KEY];
156+
if (typeof authToken !== "string") {
157+
return "";
158+
}
159+
return authToken;
160+
} catch {
161+
return "";
162+
}
163+
}

src/utils/configure-aws.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from "node:path";
55

66
import { window } from "vscode";
77

8+
import { readAuthToken } from "./authenticate.ts";
89
import { parseIni, serializeIni, updateIniSection } from "./ini-parser.ts";
910
import type { IniFile, IniSection } from "./ini-parser.ts";
1011
import type { Telemetry } from "./telemetry.ts";
@@ -296,6 +297,8 @@ export async function configureAwsProfiles(options: {
296297
const credentialsNeedsOverride =
297298
checkIfCredentialsNeedsOverride(credentialsSection);
298299

300+
const authToken = await readAuthToken();
301+
299302
// means sections exist, but we need to check what's inside
300303
if (credentialsSection && configSection) {
301304
if (!configNeedsOverride && !credentialsNeedsOverride) {
@@ -314,6 +317,7 @@ export async function configureAwsProfiles(options: {
314317
started_at: startedAt,
315318
ended_at: new Date().toISOString(),
316319
status: "COMPLETED",
320+
auth_token: authToken,
317321
},
318322
});
319323
return;
@@ -347,6 +351,7 @@ export async function configureAwsProfiles(options: {
347351
started_at: startedAt,
348352
ended_at: new Date().toISOString(),
349353
status: "SKIPPED",
354+
auth_token: authToken,
350355
},
351356
});
352357
return;
@@ -380,6 +385,7 @@ export async function configureAwsProfiles(options: {
380385
started_at: startedAt,
381386
ended_at: new Date().toISOString(),
382387
status: "COMPLETED",
388+
auth_token: authToken,
383389
},
384390
});
385391
} else if (configNeedsOverride) {
@@ -402,6 +408,7 @@ export async function configureAwsProfiles(options: {
402408
started_at: startedAt,
403409
ended_at: new Date().toISOString(),
404410
status: "COMPLETED",
411+
auth_token: authToken,
405412
},
406413
});
407414
} else if (credentialsNeedsOverride) {
@@ -424,6 +431,7 @@ export async function configureAwsProfiles(options: {
424431
started_at: startedAt,
425432
ended_at: new Date().toISOString(),
426433
status: "COMPLETED",
434+
auth_token: authToken,
427435
},
428436
});
429437
}

src/utils/manage.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ExtensionContext, LogOutputChannel, MessageItem } from "vscode";
44
import { commands, env, Uri, window } from "vscode";
55
import { tr } from "zod/v4/locales";
66

7+
import { readAuthToken } from "./authenticate.ts";
78
import { spawnLocalStack } from "./cli.ts";
89
import { exec } from "./exec.ts";
910
import { checkIsLicenseValid } from "./license.ts";
@@ -94,6 +95,7 @@ export async function startLocalStack(
9495
command: "localstack.viewLogs",
9596
});
9697

98+
const authToken = await readAuthToken();
9799
try {
98100
await spawnLocalStack(
99101
[
@@ -132,6 +134,7 @@ export async function startLocalStack(
132134
namespace: "emulator",
133135
status: "COMPLETED",
134136
emulator_session_id: emulatorSessionId,
137+
auth_token: authToken,
135138
},
136139
});
137140
} catch (error) {
@@ -155,6 +158,7 @@ export async function startLocalStack(
155158
namespace: "emulator",
156159
status: "FAILED",
157160
errors: [String(error)],
161+
auth_token: authToken,
158162
},
159163
});
160164
}
@@ -166,6 +170,7 @@ export async function stopLocalStack(
166170
) {
167171
void showInformationMessage("Stopping LocalStack.");
168172

173+
const authToken = await readAuthToken();
169174
try {
170175
// get session id before killing container
171176
const emulatorSessionId = await fetchLocalStackSessionId();
@@ -180,6 +185,7 @@ export async function stopLocalStack(
180185
namespace: "emulator",
181186
status: "COMPLETED",
182187
emulator_session_id: emulatorSessionId,
188+
auth_token: authToken,
183189
},
184190
});
185191
} catch (error) {
@@ -194,6 +200,7 @@ export async function stopLocalStack(
194200
namespace: "emulator",
195201
status: "FAILED",
196202
errors: [String(error)],
203+
auth_token: authToken,
197204
},
198205
});
199206
}

src/utils/telemetry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Events =
6262
ended_at: string;
6363
status: "COMPLETED" | "FAILED" | "SKIPPED" | "CANCELLED";
6464
errors?: string[];
65+
auth_token: string;
6566
};
6667
}
6768
| {
@@ -70,6 +71,7 @@ type Events =
7071
namespace: "onboarding";
7172
steps: number[];
7273
status: "COMPLETED" | "FAILED" | "CANCELLED";
74+
auth_token: string;
7375
};
7476
}
7577
| {
@@ -79,6 +81,7 @@ type Events =
7981
status: "COMPLETED" | "FAILED";
8082
emulator_session_id?: string;
8183
errors?: string[];
84+
auth_token: string;
8285
};
8386
}
8487
| {
@@ -88,6 +91,7 @@ type Events =
8891
status: "COMPLETED" | "FAILED";
8992
emulator_session_id?: string;
9093
errors?: string[];
94+
auth_token: string;
9195
};
9296
};
9397

0 commit comments

Comments
 (0)