Skip to content

Commit ba5c454

Browse files
committed
requests: Keep types generic
Commit 845736e updated the generic Request type to include an AWS SSM-specific entry. This commit restores the generic nature of the request type, and moves anything AWS-specific to an AWS-specific type.
1 parent a529f98 commit ba5c454

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/commands/ssh.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
DENIED_STATUSES,
99
DONE_STATUSES,
1010
ERROR_STATUSES,
11+
PluginRequest,
1112
Request,
1213
} from "../types/request";
1314
import { request } from "./request";
@@ -34,14 +35,14 @@ export const sshCommand = (yargs: yargs.Argv) =>
3435

3536
// TODO: Move this to a shared utility
3637
/** Waits until P0 grants access for a request */
37-
const waitForProvisioning = async <T extends object>(
38+
const waitForProvisioning = async <P extends PluginRequest>(
3839
authn: Authn,
3940
requestId: string
4041
) => {
4142
let cancel: NodeJS.Timeout | undefined = undefined;
42-
const result = await new Promise<Request<T>>((resolve, reject) => {
43+
const result = await new Promise<Request<P>>((resolve, reject) => {
4344
let isResolved = false;
44-
const unsubscribe = onSnapshot<Request<T>, object>(
45+
const unsubscribe = onSnapshot<Request<P>, object>(
4546
doc(`o/${authn.identity.org.tenantId}/permission-requests/${requestId}`),
4647
(snap) => {
4748
const data = snap.data();

src/plugins/aws/types.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ export type AwsConfig = {
3434
// -- Specific AWS permission types
3535

3636
export type AwsSsh = {
37-
spec: {
38-
arn: string;
37+
permission: {
38+
spec: {
39+
arn: string;
40+
};
41+
type: "session";
42+
};
43+
generated: {
44+
documentName: string;
3945
};
40-
type: "session";
4146
};

src/types/request.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ export const ERROR_STATUSES = [
66
"ERRORED_NOTIFIED",
77
] as const;
88

9-
export type Request<T = object> = {
9+
export type PluginRequest = {
10+
permission: object;
11+
generated?: object;
12+
};
13+
14+
export type Request<P extends PluginRequest = { permission: object }> = {
1015
status: string;
1116
generatedRoles: {
1217
role: string;
1318
}[];
14-
generated: {
15-
documentName: string;
16-
};
17-
permission: T;
19+
generated: P["generated"];
20+
permission: P["permission"];
1821
principal: string;
1922
};
2023

0 commit comments

Comments
 (0)