-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsandbox.ts
More file actions
93 lines (80 loc) · 2.58 KB
/
Copy pathsandbox.ts
File metadata and controls
93 lines (80 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import got, { Delays } from 'got';
import { configuration } from '@podman-desktop/api';
// eslint-disable-next-line no-shadow
export enum SBAPIEndpoint {
SIGNUP = '/api/v1/signup',
VERIFICATION = '/api/v1/signup/verification',
}
export interface SBStatus {
ready: boolean;
reason: 'Provisioned' | 'PendingApproval';
verificationRequired: boolean;
}
export interface SBSignupResponse {
apiEndpoint: string;
cheDashboardURL: string;
clusterName: string;
company: string;
compliantUsername: string;
consoleURL: string;
familyName: string;
givenName: string;
status: SBStatus;
username: string;
proxyURL: string;
}
export interface SBResponseData {
status: string;
code: number;
message: string;
details: string;
}
export interface VerificationCodeResponse {
ok: boolean;
json: SBResponseData;
}
export const OAUTH_SERVER_INFO_PATH = '.well-known/oauth-authorization-server';
export interface OauthServerInfo {
issuer: string;
authorization_endpoint: string;
token_endpoint: string;
scopes_supported: string[];
response_types_supported: string[];
grant_types_supported: string[];
code_challenge_methods_supported: string[];
}
export function getSandboxAPIUrl(): string | undefined {
return configuration.getConfiguration('redhat').get('sandbox.registrationServiceUrl');
}
export function getRegistrationServiceTimeout(): number {
return configuration.getConfiguration('redhat').get<number>('sandbox.registrationServiceTimeout', 30) * 1000;
}
function createSandboxAPITimeout(): Delays {
return {
response: getRegistrationServiceTimeout(),
request: getRegistrationServiceTimeout(),
};
}
export async function getSignUpStatus(token: string): Promise<SBSignupResponse | undefined> {
const signupResponse = await got(`${getSandboxAPIUrl()}${SBAPIEndpoint.SIGNUP}`, {
headers: {
Authorization: `Bearer ${token}`,
},
responseType: 'json',
timeout: createSandboxAPITimeout(),
});
return signupResponse.body as Promise<SBSignupResponse>;
}
export async function signUp(token: string): Promise<void> {
await got(`${getSandboxAPIUrl()}${SBAPIEndpoint.SIGNUP}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
},
timeout: createSandboxAPITimeout(),
});
}