@metaplay/metaplay-auth 1.4.2 → 1.6.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/.prettierignore +2 -0
- package/CHANGELOG.md +69 -28
- package/dist/index.cjs +292 -0
- package/dist/sshcrypto-OMBCGRSN.node +0 -0
- package/eslint.config.js +3 -0
- package/index.ts +763 -437
- package/package.json +22 -21
- package/prettier.config.js +3 -0
- package/src/auth.ts +121 -80
- package/src/buildCommand.ts +267 -0
- package/src/config.ts +12 -0
- package/src/deployment.ts +285 -52
- package/src/logging.ts +4 -4
- package/src/secret_store.ts +10 -7
- package/src/stackapi.ts +5 -381
- package/src/targetenvironment.ts +311 -0
- package/src/utils.ts +162 -31
- package/src/version.ts +1 -0
- package/dist/index.js +0 -644
- package/dist/index.js.map +0 -1
- package/dist/src/auth.js +0 -373
- package/dist/src/auth.js.map +0 -1
- package/dist/src/deployment.js +0 -250
- package/dist/src/deployment.js.map +0 -1
- package/dist/src/logging.js +0 -18
- package/dist/src/logging.js.map +0 -1
- package/dist/src/secret_store.js +0 -79
- package/dist/src/secret_store.js.map +0 -1
- package/dist/src/stackapi.js +0 -302
- package/dist/src/stackapi.js.map +0 -1
- package/dist/src/utils.js +0 -62
- package/dist/src/utils.js.map +0 -1
- package/dist/tests/utils.spec.js +0 -18
- package/dist/tests/utils.spec.js.map +0 -1
- package/tests/utils.spec.ts +0 -20
- package/vitest.config.ts +0 -7
package/dist/src/deployment.js
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { KubeConfig, CoreV1Api, V1Pod } from '@kubernetes/client-node';
|
|
2
|
-
import { logger } from './logging.js';
|
|
3
|
-
var GameServerPodPhase;
|
|
4
|
-
(function (GameServerPodPhase) {
|
|
5
|
-
GameServerPodPhase["Ready"] = "Ready";
|
|
6
|
-
GameServerPodPhase["Running"] = "Running";
|
|
7
|
-
GameServerPodPhase["Pending"] = "Pending";
|
|
8
|
-
GameServerPodPhase["Unknown"] = "Unknown";
|
|
9
|
-
GameServerPodPhase["Failed"] = "Failed";
|
|
10
|
-
})(GameServerPodPhase || (GameServerPodPhase = {}));
|
|
11
|
-
async function fetchGameServerPods(k8sApi, namespace) {
|
|
12
|
-
// Define label selector for gameserver
|
|
13
|
-
logger.debug(`Fetching game server pods from Kubernetes: namespace=${namespace}`);
|
|
14
|
-
const param = {
|
|
15
|
-
namespace,
|
|
16
|
-
labelSelector: 'app=metaplay-server'
|
|
17
|
-
};
|
|
18
|
-
try {
|
|
19
|
-
// Get gameserver pods in the namespace
|
|
20
|
-
const response = await k8sApi.listNamespacedPod(param);
|
|
21
|
-
// Return pod statuses
|
|
22
|
-
return response.items;
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
// \todo Better error handling ..
|
|
26
|
-
console.log('Failed to fetch pods from Kubernetes:', error);
|
|
27
|
-
throw new Error('Failed to fetch pods from Kubernetes');
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function resolvePodContainersConditions(pod) {
|
|
31
|
-
const containerStatuses = pod.status?.containerStatuses;
|
|
32
|
-
if (!containerStatuses || containerStatuses.length === 0) {
|
|
33
|
-
return { phase: GameServerPodPhase.Unknown, message: 'Unable to determine pod container statuses: pod.status.containerStatuses is empty' };
|
|
34
|
-
}
|
|
35
|
-
// Find the shard-server container from the pod (ignore others)
|
|
36
|
-
const containerStatus = containerStatuses.find(status => status.name === 'shard-server');
|
|
37
|
-
if (!containerStatus) {
|
|
38
|
-
return { phase: GameServerPodPhase.Unknown, message: 'Unable to find container shard-server from the pod' };
|
|
39
|
-
}
|
|
40
|
-
// Handle missing container state
|
|
41
|
-
logger.debug(`Container status for pod ${pod.metadata?.name ?? '<unnamed>'}: ${JSON.stringify(containerStatus, undefined, 2)}`);
|
|
42
|
-
const containerState = containerStatus.state;
|
|
43
|
-
if (!containerState) {
|
|
44
|
-
return { phase: GameServerPodPhase.Unknown, message: 'Unable to get container state' };
|
|
45
|
-
}
|
|
46
|
-
// Check if container running & ready
|
|
47
|
-
const containerName = containerStatus.name;
|
|
48
|
-
if (containerState.running) {
|
|
49
|
-
if (containerStatus.ready) {
|
|
50
|
-
return { phase: GameServerPodPhase.Ready, message: `Container ${containerName} is in ready phase`, details: containerState.running };
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return { phase: GameServerPodPhase.Running, message: `Container ${containerName} is in running phase`, details: containerState.running };
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// \note these may not be complete (or completely accurate)
|
|
57
|
-
const knownContainerFailureReasons = ['CrashLoopBackOff', 'Error', 'ImagePullBackOff', 'CreateContainerConfigError', 'OOMKilled', 'ContainerCannotRun', 'BackOff', 'InvalidImageName'];
|
|
58
|
-
const knownContainerPendingReasons = ['Init', 'Pending', 'PodInitializing'];
|
|
59
|
-
// Check if there's a previous terminated state (usually indicates a crash during server initialization)
|
|
60
|
-
const lastState = containerStatus.lastState;
|
|
61
|
-
if (lastState) {
|
|
62
|
-
if (lastState.terminated) {
|
|
63
|
-
// Try to detecth why the previous launch failed
|
|
64
|
-
if (containerState.waiting) {
|
|
65
|
-
const reason = containerState.waiting.reason;
|
|
66
|
-
if (knownContainerFailureReasons.includes(reason)) {
|
|
67
|
-
return { phase: GameServerPodPhase.Failed, message: `Container ${containerName} is in waiting state, reason=${reason}`, details: containerState.waiting };
|
|
68
|
-
}
|
|
69
|
-
else if (knownContainerPendingReasons.includes(reason)) {
|
|
70
|
-
return { phase: GameServerPodPhase.Pending, message: `Container ${containerName} is in waiting state, reason=${reason}`, details: containerState.waiting };
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return { phase: GameServerPodPhase.Unknown, message: `Container ${containerName} is in waiting state, reason=${reason}`, details: containerState.waiting };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else if (containerState.running) {
|
|
77
|
-
// This happens when the container is still initializing
|
|
78
|
-
return { phase: GameServerPodPhase.Pending, message: `Container ${containerName} is in running state`, details: containerState.running };
|
|
79
|
-
}
|
|
80
|
-
else if (containerState.terminated) {
|
|
81
|
-
return { phase: GameServerPodPhase.Failed, message: `Container ${containerName} is in terminated state`, details: containerState.terminated };
|
|
82
|
-
}
|
|
83
|
-
// Unable to determine launch failure reason, just return previous launch
|
|
84
|
-
return { phase: GameServerPodPhase.Failed, message: `Container ${containerName} previous launch failed with exitCode=${lastState.terminated.exitCode} and reason=${lastState.terminated.reason}`, details: lastState.terminated };
|
|
85
|
-
}
|
|
86
|
-
// \todo handle containerState.running states (including various initialization states)
|
|
87
|
-
// \todo handle containerState.terminated states (what do these even mean)
|
|
88
|
-
}
|
|
89
|
-
logger.debug('Game server pod container in unknown state:', containerState);
|
|
90
|
-
return { phase: GameServerPodPhase.Unknown, message: 'Container in unknown state', details: containerState };
|
|
91
|
-
}
|
|
92
|
-
function resolvePodStatusConditions(pod) {
|
|
93
|
-
const conditions = pod.status?.conditions;
|
|
94
|
-
if (!conditions || conditions.length === 0) {
|
|
95
|
-
return { phase: GameServerPodPhase.Unknown, message: 'Unable to determine pod status: pod.status.conditions is empty', details: pod.status };
|
|
96
|
-
}
|
|
97
|
-
// Bail if 'PodScheduled' is not yet true
|
|
98
|
-
const condPodScheduled = conditions.find(cond => cond.type === 'PodScheduled');
|
|
99
|
-
if (condPodScheduled?.status !== 'True') {
|
|
100
|
-
return { phase: GameServerPodPhase.Pending, message: `Pod has not yet been scheduled on a node: ${condPodScheduled?.message}`, details: condPodScheduled };
|
|
101
|
-
}
|
|
102
|
-
// Bail if 'Initialized' not is yet true
|
|
103
|
-
const condInitialized = conditions.find(cond => cond.type === 'Initialized');
|
|
104
|
-
if (condInitialized?.status !== 'True') {
|
|
105
|
-
return { phase: GameServerPodPhase.Pending, message: `Pod has not yet been initialized: ${condInitialized?.message}`, details: condInitialized };
|
|
106
|
-
}
|
|
107
|
-
// Bail if 'ContainersReady' is not yet true
|
|
108
|
-
const condContainersReady = conditions.find(cond => cond.type === 'ContainersReady');
|
|
109
|
-
if (condContainersReady?.status !== 'True') {
|
|
110
|
-
if (condContainersReady?.reason === 'ContainersNotReady') {
|
|
111
|
-
return resolvePodContainersConditions(pod);
|
|
112
|
-
}
|
|
113
|
-
return { phase: GameServerPodPhase.Pending, message: `Pod containers are not yet ready: ${condContainersReady?.message}`, details: condContainersReady };
|
|
114
|
-
}
|
|
115
|
-
// Bail if 'Ready' is not yet true
|
|
116
|
-
const condReady = conditions.find(cond => cond.type === 'Ready');
|
|
117
|
-
if (condReady?.status !== 'True') {
|
|
118
|
-
return { phase: GameServerPodPhase.Pending, message: `Pod is not yet ready: ${condReady?.message}`, details: condReady };
|
|
119
|
-
}
|
|
120
|
-
// resolvePodContainersConditions(pod) // DEBUG DEBUG enable to print container state for running pods
|
|
121
|
-
return { phase: GameServerPodPhase.Ready, message: 'Pod is ready to serve traffic' };
|
|
122
|
-
}
|
|
123
|
-
function resolvePodStatus(pod) {
|
|
124
|
-
// logger.debug('resolvePodStatus(): pod =', JSON.stringify(pod, undefined, 2))
|
|
125
|
-
if (!pod) {
|
|
126
|
-
return { phase: GameServerPodPhase.Unknown, message: 'Received empty pod from Kubernetes' };
|
|
127
|
-
}
|
|
128
|
-
if (!pod.status) {
|
|
129
|
-
return { phase: GameServerPodPhase.Unknown, message: 'Unable to access pod.status from Kubernetes' };
|
|
130
|
-
}
|
|
131
|
-
// Handle status.phase
|
|
132
|
-
const podPhase = pod.status?.phase;
|
|
133
|
-
switch (podPhase) {
|
|
134
|
-
case 'Pending':
|
|
135
|
-
// Pod not yet scheduled
|
|
136
|
-
return { phase: GameServerPodPhase.Pending, message: 'Pod is still in Pending phase' };
|
|
137
|
-
case 'Running':
|
|
138
|
-
// Pod has been scheduled and start -- note that the containers may have failed!
|
|
139
|
-
return resolvePodStatusConditions(pod);
|
|
140
|
-
case 'Succeeded': // Should not happen, the game server pods should never stop
|
|
141
|
-
case 'Failed': // Should not happen, the game server pods should never stop
|
|
142
|
-
case 'Unknown':
|
|
143
|
-
default:
|
|
144
|
-
return { phase: GameServerPodPhase.Unknown, message: `Invalid pod.status.phase: ${podPhase}` };
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
async function fetchPodLogs(k8sApi, pod) {
|
|
148
|
-
const podName = pod.metadata?.name;
|
|
149
|
-
logger.debug(`Fetching logs for pod '${podName}'..`);
|
|
150
|
-
const namespace = pod.metadata?.namespace;
|
|
151
|
-
const containerName = pod.spec?.containers[0].name; // \todo Handle multiple containers?
|
|
152
|
-
if (!podName || !namespace || !containerName) {
|
|
153
|
-
throw new Error('Unable to determine pod and container metadata');
|
|
154
|
-
}
|
|
155
|
-
const params = {
|
|
156
|
-
name: podName,
|
|
157
|
-
namespace,
|
|
158
|
-
container: containerName,
|
|
159
|
-
pretty: 'true',
|
|
160
|
-
previous: false,
|
|
161
|
-
tailLines: 100,
|
|
162
|
-
timestamps: true
|
|
163
|
-
};
|
|
164
|
-
try {
|
|
165
|
-
const response = await k8sApi.readNamespacedPodLog(params);
|
|
166
|
-
return response;
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
// \todo Better error handling ..
|
|
170
|
-
console.log('Failed to fetch pod logs from Kubernetes:', error);
|
|
171
|
-
throw new Error('Failed to fetch pod logs from Kubernetes');
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
async function checkGameServerPod(k8sApi, pod) {
|
|
175
|
-
// console.log('Pod:', JSON.stringify(pod, undefined, 2))
|
|
176
|
-
// Classify game server status
|
|
177
|
-
const podStatus = resolvePodStatus(pod);
|
|
178
|
-
const podName = pod.metadata?.name ?? '<unable to resolve name>';
|
|
179
|
-
// If game server launch failed, get the error logs
|
|
180
|
-
if (podStatus.phase === GameServerPodPhase.Failed) {
|
|
181
|
-
const logs = await fetchPodLogs(k8sApi, pod);
|
|
182
|
-
console.log(`Logs from pod '${podName}':\n${logs}`);
|
|
183
|
-
}
|
|
184
|
-
logger.debug(`Pod ${podName} status: ${JSON.stringify(podStatus, undefined, 2)}`);
|
|
185
|
-
return podStatus;
|
|
186
|
-
}
|
|
187
|
-
async function delay(ms) {
|
|
188
|
-
return await new Promise(resolve => setTimeout(resolve, ms));
|
|
189
|
-
}
|
|
190
|
-
function anyPodsInPhase(podStatuses, phase) {
|
|
191
|
-
return podStatuses.some(status => status.phase === phase);
|
|
192
|
-
}
|
|
193
|
-
function allPodsInPhase(podStatuses, phase) {
|
|
194
|
-
return podStatuses.every(status => status.phase === phase);
|
|
195
|
-
}
|
|
196
|
-
export async function checkGameServerDeployment(namespace, kubeconfig) {
|
|
197
|
-
const k8sApi = kubeconfig.makeApiClient(CoreV1Api);
|
|
198
|
-
// Figure out when to stop
|
|
199
|
-
const startTime = Date.now();
|
|
200
|
-
const timeoutAt = startTime + 1 * 60 * 1000; // 5min
|
|
201
|
-
while (true) {
|
|
202
|
-
// Check pod states
|
|
203
|
-
const pods = await fetchGameServerPods(k8sApi, namespace);
|
|
204
|
-
logger.debug(`Found ${pods?.length} pod(s) deployed in Kubernetes`);
|
|
205
|
-
if (pods.length > 0) {
|
|
206
|
-
// Resolve status for all pods
|
|
207
|
-
const podStatuses = await Promise.all(pods.map(async (pod) => await checkGameServerPod(k8sApi, pod)));
|
|
208
|
-
logger.debug(`Pod phases: ${podStatuses.map(status => status.phase)}`);
|
|
209
|
-
// Handle state of the deployment
|
|
210
|
-
if (anyPodsInPhase(podStatuses, GameServerPodPhase.Failed)) {
|
|
211
|
-
logger.error(`Gameserver start failed with pod statuses: ${JSON.stringify(podStatuses, undefined, 2)}`);
|
|
212
|
-
console.log('Gameserver failed to start due to the pods not starting properly! See above for details.');
|
|
213
|
-
for (let ndx = 0; ndx < pods.length; ndx += 1) {
|
|
214
|
-
const status = podStatuses[ndx];
|
|
215
|
-
const suffix = (status.phase !== GameServerPodPhase.Ready) ? ` -- ${status.message}` : '';
|
|
216
|
-
console.log(` ${pods[ndx].metadata?.name}: ${status.phase}${suffix}`);
|
|
217
|
-
}
|
|
218
|
-
return 1;
|
|
219
|
-
}
|
|
220
|
-
else if (anyPodsInPhase(podStatuses, GameServerPodPhase.Unknown) || anyPodsInPhase(podStatuses, GameServerPodPhase.Pending) || anyPodsInPhase(podStatuses, GameServerPodPhase.Running)) {
|
|
221
|
-
console.log('Waiting for gameserver(s) to be ready...');
|
|
222
|
-
for (let ndx = 0; ndx < pods.length; ndx += 1) {
|
|
223
|
-
const status = podStatuses[ndx];
|
|
224
|
-
const suffix = (status.phase !== GameServerPodPhase.Ready) ? ` -- ${status.message}` : '';
|
|
225
|
-
console.log(` ${pods[ndx].metadata?.name}: ${status.phase}${suffix}`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
else if (allPodsInPhase(podStatuses, GameServerPodPhase.Ready)) {
|
|
229
|
-
console.log('Gameserver is up and ready to serve!');
|
|
230
|
-
// \todo add further readiness checks -- ping endpoint, ping dashboard, other checks?
|
|
231
|
-
return 0;
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
console.log('Deployment in inconsistent state, waiting...');
|
|
235
|
-
for (let ndx = 0; ndx < pods.length; ndx += 1) {
|
|
236
|
-
const status = podStatuses[ndx];
|
|
237
|
-
const suffix = (status.phase !== GameServerPodPhase.Ready) ? ` -- ${status.message}` : '';
|
|
238
|
-
console.log(` ${pods[ndx].metadata?.name}: ${status.phase}${suffix}`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (Date.now() >= timeoutAt) {
|
|
243
|
-
console.log('Deployment failed! Timeout while waiting for gameserver to initialize.');
|
|
244
|
-
return 124; // timeout
|
|
245
|
-
}
|
|
246
|
-
// Sleep a bit to avoid spamming the log
|
|
247
|
-
await delay(2000);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
//# sourceMappingURL=deployment.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deployment.js","sourceRoot":"","sources":["../../src/deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,E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AAC,sCAAsC,CAAC,CAAA;gBACnD,qFAAqF;gBACrF,OAAO,CAAC,CAAA;aACT;iBAAM;gBACL,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAA;gBAC3D,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE;oBAC7C,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;oBAC/B,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,KAAK,KAAK,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;oBACzF,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,IAAI,KAAK,MAAM,CAAC,KAAK,GAAG,MAAM,EAAE,CAAC,CAAA;iBACvE;aACF;SACF;QAED,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,SAAS,EAAE;YAC3B,OAAO,CAAC,GAAG,CAAC,wEAAwE,CAAC,CAAA;YACrF,OAAO,GAAG,CAAA,CAAC,UAAU;SACtB;QAED,wCAAwC;QACxC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA;KAClB;AACH,CAAC"}
|
package/dist/src/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
|
package/dist/src/logging.js.map
DELETED
|
@@ -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"}
|
package/dist/src/secret_store.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { randomBytes, createCipheriv, createDecipheriv, scryptSync } from 'crypto';
|
|
4
|
-
import { homedir } from 'os';
|
|
5
|
-
import { logger } from './logging.js';
|
|
6
|
-
const filePath = process.env.METAPLAY_AUTH_FILE ?? join(homedir(), '.metaplay_auth.json');
|
|
7
|
-
const algorithm = 'aes-256-cbc';
|
|
8
|
-
const password = process.env.METAPLAY_AUTH_PASSWORD ?? '';
|
|
9
|
-
const salt = process.env.METAPLAY_AUTH_SALT ?? 'saltysalt';
|
|
10
|
-
async function loadSecrets() {
|
|
11
|
-
try {
|
|
12
|
-
logger.debug(`Loading secrets from ${filePath}...`);
|
|
13
|
-
await fs.access(filePath);
|
|
14
|
-
const data = await fs.readFile(filePath, 'utf8');
|
|
15
|
-
// if password is not provided, treat as unencrypted
|
|
16
|
-
if (password.length === 0) {
|
|
17
|
-
logger.debug('No password provided. Treating as unencrypted.');
|
|
18
|
-
return JSON.parse(data);
|
|
19
|
-
}
|
|
20
|
-
logger.debug('Decrypting data...');
|
|
21
|
-
const decryptedData = decrypt(data);
|
|
22
|
-
return JSON.parse(decryptedData);
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
const nodeError = error;
|
|
26
|
-
if (nodeError.code === 'ENOENT') {
|
|
27
|
-
// file does not exist, just revert to an empty object
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
if (password.length === 0) {
|
|
31
|
-
throw new Error('The file is encrypted. Please set the METAPLAY_AUTH_PASSWORD environment variable.');
|
|
32
|
-
}
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function encrypt(text) {
|
|
37
|
-
const key = scryptSync(password, salt, 32);
|
|
38
|
-
const iv = randomBytes(16); // Generate a 16-byte IV
|
|
39
|
-
const cipher = createCipheriv(algorithm, key, iv);
|
|
40
|
-
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
|
41
|
-
return iv.toString('hex') + ':' + encrypted.toString('hex'); // Store IV with the encrypted data
|
|
42
|
-
}
|
|
43
|
-
function decrypt(text) {
|
|
44
|
-
const textParts = text.split(':');
|
|
45
|
-
if (textParts.length !== 2) {
|
|
46
|
-
throw new Error('Invalid encrypted data format.');
|
|
47
|
-
}
|
|
48
|
-
const iv = Buffer.from(textParts[0], 'hex');
|
|
49
|
-
if (iv.length !== 16) { // Ensure the IV is 16 bytes
|
|
50
|
-
throw new Error('Invalid IV length.');
|
|
51
|
-
}
|
|
52
|
-
const encryptedText = Buffer.from(textParts[1], 'hex');
|
|
53
|
-
const key = scryptSync(password, salt, 32);
|
|
54
|
-
const decipher = createDecipheriv(algorithm, key, iv);
|
|
55
|
-
const decrypted = Buffer.concat([decipher.update(encryptedText), decipher.final()]);
|
|
56
|
-
return decrypted.toString();
|
|
57
|
-
}
|
|
58
|
-
export async function setSecret(key, value) {
|
|
59
|
-
logger.debug(`Setting secret ${key}...`);
|
|
60
|
-
const secrets = await loadSecrets();
|
|
61
|
-
secrets[key] = value;
|
|
62
|
-
const secretJson = JSON.stringify(secrets);
|
|
63
|
-
const content = password.length !== 0 ? encrypt(secretJson) : secretJson;
|
|
64
|
-
await fs.writeFile(filePath, content);
|
|
65
|
-
}
|
|
66
|
-
export async function getSecret(key) {
|
|
67
|
-
logger.debug(`Getting secret ${key}...`);
|
|
68
|
-
const secrets = await loadSecrets();
|
|
69
|
-
return secrets[key];
|
|
70
|
-
}
|
|
71
|
-
export async function removeSecret(key) {
|
|
72
|
-
logger.debug(`Removing secret ${key}...`);
|
|
73
|
-
const currentSecrets = await loadSecrets();
|
|
74
|
-
const { [key]: _, ...secrets } = currentSecrets; // remove key from secrets
|
|
75
|
-
const secretJson = JSON.stringify(secrets);
|
|
76
|
-
const content = password.length !== 0 ? encrypt(secretJson) : secretJson;
|
|
77
|
-
await fs.writeFile(filePath, content);
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=secret_store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"secret_store.js","sourceRoot":"","sources":["../../src/secret_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,QAAQ,GAAW,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI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