mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-07-19 09:12:13 -05:00
feat: use same config variables for CLI as BOSS itself + load .env into CLI
This commit is contained in:
parent
da6ace244f
commit
6d7bab5536
|
|
@ -1,26 +1,33 @@
|
|||
import { BOSSDefinition } from '@pretendonetwork/grpc/boss/boss_service';
|
||||
import { createChannel, createClient, Metadata } from 'nice-grpc';
|
||||
import dotenv from 'dotenv';
|
||||
import type { BOSSClient } from '@pretendonetwork/grpc/boss/boss_service';
|
||||
|
||||
export type WiiUKeys = { aesKey: string; hmacKey: string };
|
||||
|
||||
export type CliContext = {
|
||||
grpc: BOSSClient;
|
||||
npdiDomain: string;
|
||||
getWiiUKeys: () => WiiUKeys;
|
||||
};
|
||||
|
||||
export function getCliContext(): CliContext {
|
||||
const grpcHost = process.env.PN_BOSS_CLI_GRPC_HOST ?? '';
|
||||
const grpcKey = process.env.PN_BOSS_CLI_GRPC_APIKEY ?? '';
|
||||
dotenv.config();
|
||||
const grpcAddress = process.env.PN_BOSS_CONFIG_GRPC_BOSS_SERVER_ADDRESS ?? '';
|
||||
const grpcPort = process.env.PN_BOSS_CONFIG_GRPC_BOSS_SERVER_PORT ?? '';
|
||||
const grpcKey = process.env.PN_BOSS_CONFIG_GRPC_BOSS_SERVER_API_KEY ?? '';
|
||||
|
||||
if (!grpcHost) {
|
||||
throw new Error('Missing env variable PN_BOSS_CLI_GRPC_HOST');
|
||||
if (!grpcAddress) {
|
||||
throw new Error('Missing env variable PN_BOSS_CONFIG_GRPC_BOSS_SERVER_ADDRESS');
|
||||
}
|
||||
if (!grpcPort) {
|
||||
throw new Error('Missing env variable PN_BOSS_CONFIG_GRPC_BOSS_SERVER_PORT');
|
||||
}
|
||||
if (!grpcKey) {
|
||||
throw new Error('Missing env variable PN_BOSS_CLI_GRPC_APIKEY');
|
||||
throw new Error('Missing env variable PN_BOSS_CONFIG_GRPC_BOSS_SERVER_API_KEY');
|
||||
}
|
||||
|
||||
const channel = createChannel(grpcHost);
|
||||
const channel = createChannel(grpcAddress + ':' + grpcPort);
|
||||
const client: BOSSClient = createClient(BOSSDefinition, channel, {
|
||||
'*': {
|
||||
metadata: new Metadata({
|
||||
|
|
@ -31,15 +38,16 @@ export function getCliContext(): CliContext {
|
|||
|
||||
return {
|
||||
grpc: client,
|
||||
npdiDomain: (process.env.PN_BOSS_CONFIG_DOMAINS_NPDI ?? 'npdi.cdn.pretendo.cc').split(',')[0],
|
||||
getWiiUKeys(): WiiUKeys {
|
||||
const aesKey = process.env.PN_BOSS_CLI_WIIU_AES_KEY ?? '';
|
||||
const hmacKey = process.env.PN_BOSS_CLI_WIIU_HMAC_KEY ?? '';
|
||||
const aesKey = process.env.PN_BOSS_CONFIG_BOSS_WIIU_AES_KEY ?? '';
|
||||
const hmacKey = process.env.PN_BOSS_CONFIG_BOSS_WIIU_HMAC_KEY ?? '';
|
||||
|
||||
if (!aesKey) {
|
||||
throw new Error('Missing env variable PN_BOSS_CLI_WIIU_AES_KEY - needed for decryption');
|
||||
throw new Error('Missing env variable PN_BOSS_CONFIG_BOSS_WIIU_AES_KEY - needed for decryption');
|
||||
}
|
||||
if (!hmacKey) {
|
||||
throw new Error('Missing env variable PN_BOSS_CLI_WIIU_HMAC_KEY - needed for decryption');
|
||||
throw new Error('Missing env variable PN_BOSS_CONFIG_BOSS_WIIU_HMAC_KEY - needed for decryption');
|
||||
}
|
||||
return {
|
||||
aesKey,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user