Skip to content

Commit 5d023c4

Browse files
committed
app specific token, and longer lifetime tokens
1 parent 8a6521d commit 5d023c4

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/bdcli/commands/account/bdcli-account-tap-master-secret.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function show(options: any, _command: cmd.Command): Promise<void> {
2222
updateSpinnerText(`Getting BoilingData Master TAP secret`);
2323
if (!region) throw new Error("Pass --region parameter or set AWS_REGION env");
2424
const bdAccount = new BDAccount({ logger, authToken: token });
25-
const { bdTapMasterSecret, cached: tapCached, ...rest } = await bdAccount.getTapMasterSecret();
25+
const { bdTapMasterSecret, cached: tapCached, ...rest } = await bdAccount.getTapMasterSecret(options?.application);
2626
updateSpinnerText(`Getting BoilingData Master TAP secret: ${tapCached ? "cached" : "success"}`);
2727
spinnerSuccess();
2828
await outputResults({ bdTapMasterSecret, cached: tapCached, ...rest }, options.disableSpinner);
@@ -38,6 +38,7 @@ const program = new cmd.Command("bdcli account tap-master-secret")
3838
"A user has shared Tap for you so that you can write to it.",
3939
),
4040
)
41+
.addOption(new cmd.Option("--application <application>", "Data Taps supported application name, like 'github'"))
4142
.action(async (options, command) => await show(options, command));
4243

4344
(async () => {

src/bdcli/utils/auth_util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export async function authSpinnerWithConfigCheck(): Promise<boolean> {
2323
export async function validateTokenLifetime(lifetime: string, logger?: ILogger): Promise<void> {
2424
const lifetimeInMs = ms(`${lifetime}`);
2525
logger?.debug({ lifetimeInMs });
26-
if (!lifetimeInMs || lifetimeInMs < ms("10min") || lifetimeInMs > ms("24h")) {
26+
if (!lifetimeInMs || lifetimeInMs < ms("10min")) {
2727
throw new Error(
2828
"Invalid token expiration time span, " +
2929
"please see https://github.com/vercel/ms for the format of the period. " +
30-
"Lifetime must be between 10min - 24h",
30+
"Lifetime must be at min. 10min. Free tier max is 24h.",
3131
);
3232
}
3333
}

src/integration/boilingdata/account.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class BDAccount {
4646
private bdStsToken: string | undefined;
4747
private bdTapToken: string | undefined;
4848
private bdTapMasterSecret: string | undefined;
49+
private bdTapMasterSecretApplication: string | undefined;
4950
private sharedTokens: IDecodedSession[];
5051
private selectedToken: string | undefined;
5152
private decodedToken!: jwt.JwtPayload | null;
@@ -335,11 +336,15 @@ export class BDAccount {
335336
throw new Error(`Failed to get fresh TAP token from BD API`);
336337
}
337338

338-
public async getTapMasterSecret(): Promise<{ bdTapMasterSecret: string; cached: boolean }> {
339-
if (this.bdTapMasterSecret) return { bdTapMasterSecret: this.bdTapMasterSecret, cached: true };
339+
public async getTapMasterSecret(
340+
application = "default",
341+
): Promise<{ bdTapMasterSecret: string; cached: boolean; application: string }> {
342+
if (this.bdTapMasterSecret && this.bdTapMasterSecretApplication === application) {
343+
return { bdTapMasterSecret: this.bdTapMasterSecret, cached: true, application };
344+
}
340345
const headers = await getReqHeaders(this.cognitoIdToken); // , { tokenLifetime, vendingSchedule, shareId });
341346
const method = "POST";
342-
const body = JSON.stringify({});
347+
const body = JSON.stringify({ application });
343348
this.logger.debug({ method, tapMasterSecretUrl, headers, body });
344349
const res = await fetch(tapMasterSecretUrl, { method, headers, body });
345350
const resBody = await res.json();
@@ -355,7 +360,12 @@ export class BDAccount {
355360
throw new Error("Missing bdTapMasterSecret in BD API Response");
356361
}
357362
this.bdTapMasterSecret = resBody.bdTapMasterSecret;
358-
return { bdTapMasterSecret: resBody.bdTapMasterSecret, cached: false };
363+
this.bdTapMasterSecretApplication = resBody?.application ?? "default";
364+
return {
365+
bdTapMasterSecret: resBody.bdTapMasterSecret,
366+
cached: false,
367+
application: resBody?.application ?? "default",
368+
};
359369
}
360370

361371
public async getStsToken(tokenLifetime: string, shareId?: string): Promise<{ bdStsToken: string; cached: boolean }> {

0 commit comments

Comments
 (0)