Skip to content

Commit

Permalink
add log to config load
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmatthis committed May 16, 2024
1 parent a90b7de commit 8c52d96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/discord/discord.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import { DiscordConfigureChannelService } from './commands/server-config-command

@Module({
imports: [
GcpModule,
NecordModule.forRootAsync({
imports: [GcpModule],
useClass: DiscordConfigService,
}),
GcpModule,
UsersModule,
ChatbotModule,
AiChatsModule,
Expand Down
8 changes: 6 additions & 2 deletions src/interfaces/discord/services/discord-config.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { NecordModuleOptions } from 'necord';
import { IntentsBitField } from 'discord.js';
import { ConfigService } from '@nestjs/config';
import { GcpSecretsService } from '../../../core/gcp/gcp-secrets.service';

@Injectable()
export class DiscordConfigService {
private readonly _logger = new Logger(DiscordConfigService.name);
private _tokenMap = {
DISCORD_BOT_TOKEN:
'projects/588063171007/secrets/DISCORD_BOT_TOKEN/versions/latest',
Expand Down Expand Up @@ -33,13 +34,16 @@ export class DiscordConfigService {

private async _createTokenByNodeEnv() {
if (process.env.NODE_ENV === 'production') {
this._logger.log('Production environment detected - using GCP secrets');
const secretName = this._tokenMap.DISCORD_BOT_TOKEN;
const [secret] = await this.sms.getSecretsManager().accessSecretVersion({
name: secretName,
});
return secret.payload.data.toString();
}

this._logger.log(
'Development environment detected - using local .env files',
);
return this._cfgService.getOrThrow('DISCORD_BOT_TOKEN');
}

Expand Down

0 comments on commit 8c52d96

Please sign in to comment.