@metaplay/metaplay-auth 1.1.7 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/auth.js DELETED
@@ -1,335 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-misused-promises */
2
- import { createServer } from 'node:http';
3
- import { toNodeListener, createApp, defineEventHandler, getQuery, sendError } from 'h3';
4
- import open from 'open';
5
- import { randomBytes, createHash } from 'node:crypto';
6
- import jwt from 'jsonwebtoken';
7
- import jwkToPem from 'jwk-to-pem';
8
- import { Configuration, WellknownApi } from '@ory/client';
9
- import { setSecret, getSecret, removeSecret } from './secret_store.js';
10
- import { logger } from './logging.js';
11
- // oauth2 client details (maybe move these to be discovered from some online location to make changes easier to manage?)
12
- const clientId = 'c16ea663-ced3-46c6-8f85-38c9681fe1f0';
13
- const baseURL = 'https://auth.metaplay.dev';
14
- const authorizationEndpoint = `${baseURL}/oauth2/auth`;
15
- const tokenEndpoint = `${baseURL}/oauth2/token`;
16
- const wellknownApi = new WellknownApi(new Configuration({
17
- basePath: baseURL,
18
- }));
19
- /**
20
- * A helper function which generates a code verifier and challenge for exchaning code from Ory server.
21
- * @returns
22
- */
23
- function generateCodeVerifierAndChallenge() {
24
- const verifier = randomBytes(32).toString('hex');
25
- const challenge = createHash('sha256').update(verifier).digest('base64url');
26
- return { verifier, challenge };
27
- }
28
- /**
29
- * A helper function which finds an local available port to listen on.
30
- * @returns A promise that resolves to an available port.
31
- */
32
- async function findAvailablePort() {
33
- return await new Promise((resolve, reject) => {
34
- // Ports need to be in sync with oauth2 client callbacks.
35
- const portsToCheck = [5000, 5001, 5002, 5003, 5004];
36
- let index = 0;
37
- // Test ports by opening a server on them.
38
- function tryNextPort() {
39
- if (index >= portsToCheck.length) {
40
- reject(new Error('Could not find an available port.'));
41
- }
42
- const port = portsToCheck[index];
43
- const server = createServer();
44
- logger.debug(`Trying port ${port}...`);
45
- server.listen(port, () => {
46
- server.once('close', () => {
47
- resolve(port);
48
- });
49
- server.close();
50
- logger.debug(`Port ${port} is available.`);
51
- });
52
- server.on('error', () => {
53
- logger.debug(`Port ${port} is not available.`);
54
- index++;
55
- tryNextPort();
56
- });
57
- }
58
- tryNextPort();
59
- });
60
- }
61
- /**
62
- * Log in and save tokens to the local secret store.
63
- */
64
- export async function loginAndSaveTokens() {
65
- // Find an available port to listen on.
66
- const availablePort = await findAvailablePort();
67
- const app = createApp();
68
- const redirectUri = `http://localhost:${availablePort}/callback`;
69
- const { verifier, challenge } = generateCodeVerifierAndChallenge();
70
- const state = randomBytes(16).toString('hex');
71
- // Create a /callback endpoint that exchanges the code for tokens.
72
- app.use('/callback', defineEventHandler(async (event) => {
73
- // Read the query parameters.
74
- const { error, error_description: errorDescription, code } = getQuery(event);
75
- // Raise an error if the query parameters contain an error message.
76
- if (error) {
77
- console.error(`Error logging in. Received the following error:\n\n${String(error)}: ${String(errorDescription)}`);
78
- sendError(event, new Error(`Authentication failed: ${String(error)}: ${String(errorDescription)}`));
79
- server.close();
80
- process.exit(1);
81
- }
82
- // Raise an error if the query parameters do not contain a code.
83
- if (typeof code !== 'string') {
84
- console.error('Error logging in. No code received.');
85
- sendError(event, new Error('Authentication failed: No code received.'));
86
- server.close();
87
- process.exit(1);
88
- }
89
- // Exchange the code for tokens.
90
- try {
91
- logger.debug(`Received callback request with code ${code}. Preparing to exchange for tokens...`);
92
- const tokens = await getTokensWithAuthorizationCode(state, redirectUri, verifier, code);
93
- // Only save access_token, id_token, and refresh_token
94
- await saveTokens({ access_token: tokens.access_token, id_token: tokens.id_token, refresh_token: tokens.refresh_token });
95
- console.log('You are now logged in and can call the other commands.');
96
- // TODO: Could return a pre-generated HTML page instead of text?
97
- return 'Authentication successful! You can close this window.';
98
- }
99
- catch (error) {
100
- if (error instanceof Error) {
101
- console.error(`Error: ${error.message}`);
102
- }
103
- }
104
- finally {
105
- server.close();
106
- }
107
- process.exit(0);
108
- }));
109
- // Start the server.
110
- // We use use H3 and adapt it to Node.js's http server.
111
- const server = createServer(toNodeListener(app)).listen(availablePort);
112
- logger.debug(`Listening on port ${availablePort} and waiting for callback...`);
113
- // Open the browser to log in.
114
- const authorizationUrl = `${authorizationEndpoint}?response_type=code&client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&code_challenge=${challenge}&code_challenge_method=S256&scope=${encodeURIComponent('openid offline_access')}&state=${encodeURIComponent(state)}`;
115
- console.log(`Attempting to open a browser to log in. If a browser did not open up, you can copy-paste the following URL to authenticate:\n\n${authorizationUrl}\n`);
116
- void open(authorizationUrl);
117
- }
118
- export async function machineLoginAndSaveTokens(clientId, clientSecret) {
119
- // Get a fresh access token from Metaplay Auth.
120
- const params = new URLSearchParams();
121
- params.set('grant_type', 'client_credentials');
122
- params.set('client_id', clientId);
123
- params.set('client_secret', clientSecret);
124
- params.set('scope', 'openid email profile offline_access');
125
- const res = await fetch(tokenEndpoint, {
126
- method: 'POST',
127
- headers: {
128
- 'Content-Type': 'application/x-www-form-urlencoded',
129
- },
130
- body: params.toString(),
131
- });
132
- // Return type checked manually by Teemu on 2024-3-7.
133
- const tokens = await res.json();
134
- logger.debug('Received machine authentication tokens, saving them for future use...');
135
- await saveTokens({ access_token: tokens.access_token });
136
- const userInfoResponse = await fetch('https://portal.metaplay.dev/api/external/userinfo', {
137
- headers: {
138
- Authorization: `Bearer ${tokens.access_token}`
139
- },
140
- });
141
- const userInfo = await userInfoResponse.json();
142
- console.log(`You are now logged in with machine user ${userInfo.given_name} ${userInfo.family_name} (clientId=${clientId}) and can execute the other commands.`);
143
- }
144
- /**
145
- * Refresh access and ID token with a refresh token.
146
- */
147
- export async function extendCurrentSession() {
148
- try {
149
- const tokens = await loadTokens();
150
- logger.debug('Check if access token still valid...');
151
- if (await validateToken(tokens.access_token)) {
152
- // Access token is not expired, return to the caller
153
- logger.debug('Access token is valid, no need to refresh.');
154
- return;
155
- }
156
- // Check that the refresh_token exists (machine users don't have it)
157
- if (!tokens.refresh_token) {
158
- throw new Error('Cannot refresh an access_token without a refresh_token. With machine users, should just login again instead.');
159
- }
160
- logger.debug('Access token is no longer valid, trying to extend the current session with a refresh token.');
161
- const refreshedTokens = await extendCurrentSessionWithRefreshToken(tokens.refresh_token);
162
- await saveTokens({ access_token: refreshedTokens.access_token, id_token: refreshedTokens.id_token, refresh_token: refreshedTokens.refresh_token });
163
- }
164
- catch (error) {
165
- if (error instanceof Error) {
166
- console.error(error.message);
167
- }
168
- process.exit(1);
169
- }
170
- }
171
- /**
172
- * Make HTTP request to the token endpoint for a new set of tokens using the refresh token.
173
- * @param refreshToken: The refresh token to use to get a new set of tokens.
174
- * @returns A promise that resolves to a new set of tokens.
175
- */
176
- async function extendCurrentSessionWithRefreshToken(refreshToken) {
177
- // TODO: similar to the todo task in getTokensWithAuthorizationCode, http request can be handled by ory/client.
178
- const params = new URLSearchParams({
179
- grant_type: 'refresh_token',
180
- refresh_token: refreshToken,
181
- scope: 'openid offline_access',
182
- client_id: clientId
183
- });
184
- logger.debug('Refreshing tokens...');
185
- // Send a POST request to refresh tokens
186
- const response = await fetch(tokenEndpoint, {
187
- method: 'POST',
188
- headers: {
189
- 'Content-Type': 'application/x-www-form-urlencoded',
190
- },
191
- body: params.toString(),
192
- });
193
- // Check if the response is OK
194
- if (!response.ok) {
195
- const responseJSON = await response.json();
196
- logger.error('Failed to refresh tokens.');
197
- logger.error(`Error Type: ${responseJSON.error}`);
198
- logger.error(`Error Description: ${responseJSON.error_description}`);
199
- logger.debug('Attempt to clear local state and remove any dangling tokens...');
200
- await removeTokens();
201
- logger.debug('Local state cleared and tokens removed.');
202
- throw new Error('Failed extending current session, exiting. Please log in again.');
203
- }
204
- return await response.json();
205
- }
206
- /**
207
- * Make HTTP request to the token endpoint for a new set of tokens (Authorization Code Flow).
208
- * @param state
209
- * @param redirectUri
210
- * @param verifier
211
- * @param code
212
- * @returns
213
- */
214
- async function getTokensWithAuthorizationCode(state, redirectUri, verifier, code) {
215
- // TODO: the authorication code exchange flow might be better to be handled by ory/client, could check if there's any useful toosl there.
216
- try {
217
- const response = await fetch(tokenEndpoint, {
218
- method: 'POST',
219
- headers: {
220
- 'Content-Type': 'application/x-www-form-urlencoded'
221
- },
222
- body: `grant_type=authorization_code&code=${code}&redirect_uri=${encodeURIComponent(redirectUri)}&client_id=${clientId}&code_verifier=${verifier}&state=${encodeURIComponent(state)}`
223
- });
224
- return await response.json();
225
- }
226
- catch (error) {
227
- if (error instanceof Error) {
228
- logger.error(`Error exchanging code for tokens: ${error.message}`);
229
- }
230
- throw error;
231
- }
232
- }
233
- /**
234
- * Load tokens from the local secret store.
235
- */
236
- export async function loadTokens() {
237
- try {
238
- const tokens = await getSecret('tokens');
239
- if (!tokens) {
240
- throw new Error('Unable to load tokens. You need to login first.');
241
- }
242
- return tokens;
243
- }
244
- catch (error) {
245
- if (error instanceof Error) {
246
- throw new Error(`Error loading tokens: ${error.message}`);
247
- }
248
- throw error;
249
- }
250
- }
251
- /**
252
- * Save tokens to the local secret store.
253
- * @param tokens The tokens to save.
254
- */
255
- export async function saveTokens(tokens) {
256
- try {
257
- logger.debug('Received new tokens, verifying...');
258
- // All tokens must have an access_token (machine users only have it)
259
- if (!tokens.access_token) {
260
- throw new Error('Metaplay token has no access_token. Please log in again and make sure all checkboxes of permissions are selected before proceeding.');
261
- }
262
- logger.debug('Token verification completed, storing tokens...');
263
- await setSecret('tokens', tokens);
264
- logger.debug('Tokens successfully stored.');
265
- await showTokenInfo(tokens.access_token);
266
- }
267
- catch (error) {
268
- if (error instanceof Error) {
269
- throw new Error(`Failed to save tokens: ${error.message}`);
270
- }
271
- throw error;
272
- }
273
- }
274
- /**
275
- * Remove tokens from the local secret store.
276
- */
277
- export async function removeTokens() {
278
- try {
279
- await removeSecret('tokens');
280
- logger.debug('Removed tokens.');
281
- }
282
- catch (error) {
283
- if (error instanceof Error) {
284
- throw new Error(`Error removing tokens: ${error.message}`);
285
- }
286
- throw error;
287
- }
288
- }
289
- /**
290
- * This function validates a token by checking its signature, expiration and issuer.
291
- * @param token The token being validated
292
- * @returns return if token is valid, throw errors otherwise
293
- */
294
- async function validateToken(token) {
295
- try {
296
- // Decode the token
297
- const completeTokenData = jwt.decode(token, { complete: true });
298
- // Handle junk data.
299
- if (!completeTokenData) {
300
- throw new Error('Invalid token');
301
- }
302
- // Get the JSON web keys from the wellknown API.
303
- const res = await wellknownApi.discoverJsonWebKeys();
304
- const jwk = res.data.keys?.find((key) => key.kid === completeTokenData.header.kid);
305
- if (!jwk) {
306
- throw new Error('No public key found for token signature');
307
- }
308
- // Convert to PEM format.
309
- const pem = jwkToPem(jwk);
310
- // Verify the token signature, expiration and decode it.
311
- jwt.verify(token, pem, { issuer: baseURL, ignoreExpiration: false });
312
- return true;
313
- }
314
- catch (error) {
315
- if (error instanceof Error) {
316
- logger.info(`Token not valid: ${error.message}`);
317
- }
318
- return false;
319
- }
320
- }
321
- /**
322
- * A helper function which shows token info after being fully decoded.
323
- * @param token The token to show info for.
324
- */
325
- async function showTokenInfo(token) {
326
- logger.debug('Showing access token info...');
327
- // Decode the token
328
- const completeTokenData = jwt.decode(token, { complete: true });
329
- // Handle junk data.
330
- if (!completeTokenData) {
331
- throw new Error('Token is corrupted');
332
- }
333
- logger.debug(JSON.stringify(completeTokenData));
334
- }
335
- //# sourceMappingURL=auth.js.map
package/dist/auth.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,kBAAkB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAEvF,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,GAAG,MAAM,cAAc,CAAA;AAC9B,OAAO,QAAQ,MAAM,Y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B,EAAE,CAAA;QACpD,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAClF,IAAI,CAAC,GAAG,EAAE;YACR,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;SAC3D;QACD,yBAAyB;QACzB,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAmB,CAAC,CAAA;QAEzC,wDAAwD;QACxD,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAAA;QAEpE,OAAO,IAAI,CAAA;KACZ;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,KAAK,YAAY,KAAK,EAAE;YAC1B,MAAM,CAAC,IAAI,CAAC,oBAAoB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;SACjD;QACD,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,aAAa,CAAE,KAAa;IACzC,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAA;IAC5C,mBAAmB;IACnB,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAE/D,oBAAoB;IACpB,IAAI,CAAC,iBAAiB,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;KACtC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAA;AACjD,CAAC"}
@@ -1,218 +0,0 @@
1
- import { promises as fs, existsSync } from 'fs';
2
- import { KubeConfig, CoreV1Api, V1Pod } from '@kubernetes/client-node';
3
- import { logger } from './logging.js';
4
- import { error } from 'console';
5
- var GameServerPodPhase;
6
- (function (GameServerPodPhase) {
7
- GameServerPodPhase["Pending"] = "Pending";
8
- GameServerPodPhase["Ready"] = "Ready";
9
- GameServerPodPhase["Failed"] = "Failed";
10
- GameServerPodPhase["Unknown"] = "Unknown";
11
- })(GameServerPodPhase || (GameServerPodPhase = {}));
12
- async function fetchGameServerPods(k8sApi, namespace) {
13
- // Define label selector for gameserver
14
- const labelSelector = 'app=metaplay-server';
15
- try {
16
- // Get gameserver pods in the namespace
17
- const response = await k8sApi.listNamespacedPod(namespace, undefined, undefined, undefined, undefined, labelSelector);
18
- // Return pod statuses
19
- return response.body.items;
20
- }
21
- catch (error) {
22
- // \todo Better error handling ..
23
- console.log('Failed to fetch pods from Kubernetes:', error);
24
- throw new Error('Failed to fetch pods from Kubernetes');
25
- }
26
- }
27
- function resolvePodContainersConditions(pod) {
28
- const containerStatuses = pod.status?.containerStatuses;
29
- if (!containerStatuses || containerStatuses.length === 0) {
30
- return { phase: GameServerPodPhase.Unknown, message: 'Unable to determine pod container statuses: pod.status.containerStatuses is empty' };
31
- }
32
- // Only one container allowed in the game server pod
33
- if (containerStatuses.length !== 1) {
34
- throw new Error(`Internal error: Expecting only one container in the game server pod, got ${containerStatuses.length}`);
35
- }
36
- // Handle missing container state
37
- const containerStatus = containerStatuses[0];
38
- console.log('Container status:', containerStatus);
39
- const containerState = containerStatus.state;
40
- if (!containerState) {
41
- return { phase: GameServerPodPhase.Unknown, message: 'Unable to get container state' };
42
- }
43
- // Check if container running & ready
44
- const containerName = containerStatus.name;
45
- if (containerStatus.ready && containerState.running) {
46
- return { phase: GameServerPodPhase.Ready, message: `Container ${containerName} is in ready phase and was started at ${containerState.running.startedAt}`, details: containerState.running };
47
- }
48
- // \note these may not be complete (or completely accurate)
49
- const knownContainerFailureReasons = ['CrashLoopBackOff', 'Error', 'ImagePullBackOff', 'CreateContainerConfigError', 'OOMKilled', 'ContainerCannotRun', 'BackOff', 'InvalidImageName'];
50
- const knownContainerPendingReasons = ['Init', 'Pending', 'PodInitializing'];
51
- // Check if there's a previous terminated state (usually indicates a crash during server initialization)
52
- const lastState = containerStatus.lastState;
53
- if (lastState) {
54
- if (lastState.terminated) {
55
- // Try to detecth why the previous launch failed
56
- if (containerState.waiting) {
57
- const reason = containerState.waiting.reason;
58
- if (knownContainerFailureReasons.includes(reason)) {
59
- return { phase: GameServerPodPhase.Failed, message: `Container ${containerName} is in waiting state, reason=${reason}`, details: containerState.waiting };
60
- }
61
- else if (knownContainerPendingReasons.includes(reason)) {
62
- return { phase: GameServerPodPhase.Pending, message: `Container ${containerName} is in waiting state, reason=${reason}`, details: containerState.waiting };
63
- }
64
- else {
65
- return { phase: GameServerPodPhase.Unknown, message: `Container ${containerName} is in waiting state, reason=${reason}`, details: containerState.waiting };
66
- }
67
- }
68
- else if (containerState.running) {
69
- // This happens when the container is still initializing
70
- return { phase: GameServerPodPhase.Pending, message: `Container ${containerName} is in running state`, details: containerState.running };
71
- }
72
- else if (containerState.terminated) {
73
- return { phase: GameServerPodPhase.Failed, message: `Container ${containerName} is in terminated state`, details: containerState.terminated };
74
- }
75
- // Unable to determine launch failure reason, just return previous launch
76
- return { phase: GameServerPodPhase.Failed, message: `Container ${containerName} previous launch failed with exitCode=${lastState.terminated.exitCode} and reason=${lastState.terminated.reason}`, details: lastState.terminated };
77
- }
78
- // \todo handle containerState.running states (including various initialization states)
79
- // \todo handle containerState.terminated states (what do these even mean)
80
- }
81
- console.log('Game server pod container in unknown state:', containerState);
82
- return { phase: GameServerPodPhase.Unknown, message: 'Container in unknown state', details: containerState };
83
- }
84
- function resolvePodStatusConditions(pod) {
85
- const conditions = pod.status?.conditions;
86
- if (!conditions || conditions.length === 0) {
87
- return { phase: GameServerPodPhase.Unknown, message: 'Unable to determine pod status: pod.status.conditions is empty', details: pod.status };
88
- }
89
- // Bail if 'PodScheduled' is not yet true
90
- const condPodScheduled = conditions.find(cond => cond.type === 'PodScheduled');
91
- if (condPodScheduled?.status !== 'True') {
92
- return { phase: GameServerPodPhase.Pending, message: `Pod has not yet been scheduled on a node: ${condPodScheduled?.message}`, details: condPodScheduled };
93
- }
94
- // Bail if 'Initialized' not is yet true
95
- const condInitialized = conditions.find(cond => cond.type === 'Initialized');
96
- if (condInitialized?.status !== 'True') {
97
- return { phase: GameServerPodPhase.Pending, message: `Pod has not yet been initialized: ${condInitialized?.message}`, details: condInitialized };
98
- }
99
- // Bail if 'ContainersReady' is not yet true
100
- const condContainersReady = conditions.find(cond => cond.type === 'ContainersReady');
101
- if (condContainersReady?.status !== 'True') {
102
- if (condContainersReady?.reason === 'ContainersNotReady') {
103
- return resolvePodContainersConditions(pod);
104
- }
105
- return { phase: GameServerPodPhase.Pending, message: `Pod containers are not yet ready: ${condContainersReady?.message}`, details: condContainersReady };
106
- }
107
- // Bail if 'Ready' is not yet true
108
- const condReady = conditions.find(cond => cond.type === 'Ready');
109
- if (condReady?.status !== 'True') {
110
- return { phase: GameServerPodPhase.Pending, message: `Pod is not yet ready: ${condReady?.message}`, details: condReady };
111
- }
112
- // resolvePodContainersConditions(pod) // DEBUG DEBUG enable to print container state for running pods
113
- return { phase: GameServerPodPhase.Ready, message: 'Pod is ready to serve traffic' };
114
- }
115
- function resolvePodStatus(pod) {
116
- // console.log('Pod.status:', JSON.stringify(pod.status, undefined, 2))
117
- if (!pod.status) {
118
- return { phase: GameServerPodPhase.Unknown, message: 'Unable to access pod.status from Kubernetes' };
119
- }
120
- // Handle status.phase
121
- const podPhase = pod.status?.phase;
122
- switch (podPhase) {
123
- case 'Pending':
124
- // Pod not yet scheduled
125
- return { phase: GameServerPodPhase.Pending, message: 'Pod is still in Pending phase' };
126
- case 'Running':
127
- // Pod has been scheduled and start -- note that the containers may have failed!
128
- return resolvePodStatusConditions(pod);
129
- case 'Succeeded': // Should not happen, the game server pods should never stop
130
- case 'Failed': // Should not happen, the game server pods should never stop
131
- case 'Unknown':
132
- default:
133
- return { phase: GameServerPodPhase.Unknown, message: `Invalid pod.status.phase: ${podPhase}` };
134
- }
135
- }
136
- async function fetchPodLogs(k8sApi, pod) {
137
- console.log('Fetching logs for pod..');
138
- const podName = pod.metadata?.name;
139
- const namespace = pod.metadata?.namespace;
140
- const containerName = pod.spec?.containers[0].name; // \todo Handle multiple containers?
141
- if (!podName || !namespace || !containerName) {
142
- throw new Error('Unable to determine pod metadata');
143
- }
144
- const pretty = 'True';
145
- const previous = false;
146
- const tailLines = 100;
147
- const timestamps = true;
148
- try {
149
- const response = await k8sApi.readNamespacedPodLog(podName, namespace, containerName, undefined, undefined, undefined, pretty, previous, undefined, tailLines, timestamps);
150
- return response.body;
151
- }
152
- catch (error) {
153
- // \todo Better error handling ..
154
- console.log('Failed to fetch pod logs from Kubernetes:', error);
155
- throw new Error('Failed to fetch pod logs from Kubernetes');
156
- }
157
- }
158
- async function checkGameServerPod(k8sApi, pod) {
159
- // console.log('Pod:', JSON.stringify(pod, undefined, 2))
160
- // Classify game server status
161
- const podStatus = resolvePodStatus(pod);
162
- // If game server launch failed, get the error logs
163
- if (podStatus.phase === GameServerPodPhase.Failed) {
164
- const logs = await fetchPodLogs(k8sApi, pod);
165
- console.log('Pod logs:\n' + logs);
166
- }
167
- console.log(`Pod ${pod.metadata?.name} status:`, podStatus);
168
- return podStatus;
169
- }
170
- async function delay(ms) {
171
- return await new Promise(resolve => setTimeout(resolve, ms));
172
- }
173
- export async function checkGameServerDeployment(namespace) {
174
- logger.info(`Validating game server deployment in namespace ${namespace}`);
175
- // Check that the KUBECONFIG environment variable exists
176
- const kubeconfigPath = process.env.KUBECONFIG;
177
- if (!kubeconfigPath) {
178
- throw new Error('The KUBECONFIG environment variable must be specified');
179
- }
180
- // Check that the kubeconfig file exists
181
- if (!await existsSync(kubeconfigPath)) {
182
- throw new Error(`The environment variable KUBECONFIG points to a file '${kubeconfigPath}' that doesn't exist`);
183
- }
184
- // Create Kubernetes API instance (with default kubeconfig)
185
- const kc = new KubeConfig();
186
- kc.loadFromFile(kubeconfigPath);
187
- const k8sApi = kc.makeApiClient(CoreV1Api);
188
- // Figure out when to stop
189
- const startTime = Date.now();
190
- const timeoutAt = startTime + 1 * 60 * 1000; // 5min
191
- while (true) {
192
- // Check pod states
193
- const pods = await fetchGameServerPods(k8sApi, namespace);
194
- const podStatus = await checkGameServerPod(k8sApi, pods[0]); // \todo Handle all pods
195
- switch (podStatus.phase) {
196
- case GameServerPodPhase.Ready:
197
- console.log('Gameserver successfully started');
198
- // \todo add further readiness checks -- ping endpoint, ping dashboard, other checks?
199
- return 0;
200
- case GameServerPodPhase.Failed:
201
- console.log('Gameserver failed to start');
202
- return 1;
203
- case GameServerPodPhase.Pending:
204
- console.log('Gameserver still starting');
205
- break;
206
- case GameServerPodPhase.Unknown:
207
- default:
208
- console.log('Gameserver in unknown state');
209
- break;
210
- }
211
- if (Date.now() >= timeoutAt) {
212
- logger.error('Timeout while waiting for gameserver to initialize');
213
- return 124; // timeout
214
- }
215
- await delay(1000);
216
- }
217
- }
218
- //# sourceMappingURL=deployment.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deployment.js","sourceRoot":"","sources":["../src/deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,IAAK,kBAKJ;AALD,WAAK,kBAAkB;IACrB,yCAAmB,CAAA;IACnB,qCAAe,CAAA;IACf,uCAAiB,CAAA;IACjB,yCAAmB,CAAA;AACrB,CAAC,EALI,kBAAkB,KAAlB,kBAAkB,QAKtB;AAQD,KAAK,UAAU,mBAAmB,CAAE,MAAiB,EAAE,SAAiB;IACtE,uCAAuC;IACvC,MAAM,aAAa,GAAG,qBAAqB,CAAA;IAE3C,IAAI;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FAAqF;gBACrF,OAAO,CAAC,CAAA;YAEV,KAAK,kBAAkB,CAAC,MAAM;gBAC5B,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;gBACzC,OAAO,CAAC,CAAA;YAEV,KAAK,kBAAkB,CAAC,OAAO;gBAC7B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;gBACxC,MAAK;YAEP,KAAK,kBAAkB,CAAC,OAAO,CAAC;YAChC;gBACE,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAA;gBAC1C,MAAK;SACR;QAED,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,SAAS,EAAE;YAC3B,MAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAA;YAClE,OAAO,GAAG,CAAA,CAAC,UAAU;SACtB;QAED,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA;KAClB;AACH,CAAC"}
package/dist/logging.js DELETED
@@ -1,18 +0,0 @@
1
- import { Logger } from 'tslog';
2
- /**
3
- * The logger instance. Use this to log messages.
4
- */
5
- export const logger = new Logger({
6
- overwrite: {
7
- transportFormatted(logMetaMarkup, logArgs, logErrors, settings) {
8
- console.error(`${logMetaMarkup} ${logArgs.join('')} ${logErrors.join('')}`);
9
- }
10
- }
11
- });
12
- /**
13
- * Set the log level. We use 0 and 10.
14
- */
15
- export function setLogLevel(level) {
16
- logger.settings.minLevel = level;
17
- }
18
- //# sourceMappingURL=logging.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAE9B;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;IAC/B,SAAS,EAAE;QACT,kBAAkB,CAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ;YAC7D,OAAO,CAAC,KAAK,CAAC,GAAG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;QAC7E,CAAC;KACF;CACF,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,UAAU,WAAW,CAAE,KAAa;IACxC,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAG,KAAK,CAAA;AAClC,CAAC"}