Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get public key directly from environment #14

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions cmd/ecfmp-discord/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,25 @@ func main() {
// Create the discord scheduler
scheduler := discord.NewDiscordScheduler(mongo, publisher)

// Get the public key from the environment
publicKeyFile := os.Getenv("AUTH_JWT_PUBLIC_KEY_FILE")
if publicKeyFile == "" {
log.Fatalf("AUTH_JWT_PUBLIC_KEY_FILE is not set")
}
// Try the public key from the environment directly
publicKey := os.Getenv("AUTH_JWT_PUBLIC_KEY")

// Get the public key by reading the file, throw error if file doesnt exist
publicKey, err := os.ReadFile(publicKeyFile)
if err != nil {
log.Fatalf("failed to read public key file: %v", err)
// If the public key is empty, try to get it from a file
if publicKey == "" {
publicKeyFile := os.Getenv("AUTH_JWT_PUBLIC_KEY_FILE")
if publicKeyFile == "" {
log.Fatalf("AUTH_JWT_PUBLIC_KEY_FILE is not set")
}

// Get the public key by reading the file, throw error if file doesnt exist
fromFile, err := os.ReadFile(publicKeyFile)
if err != nil {
log.Fatalf("failed to read public key file: %v", err)
}

publicKey = string(fromFile)
}
interceptor := grpc.NewJwtAuthInterceptor(publicKey, os.Getenv("AUTH_JWT_AUDIENCE"))
interceptor := grpc.NewJwtAuthInterceptor([]byte(publicKey), os.Getenv("AUTH_JWT_AUDIENCE"))

grpcServer := grpc.NewServer(mongo, scheduler, interceptor)
log.Info("Discord server starting...")
Expand Down