Skip to content

Commit

Permalink
Merge pull request #14 from ECFMP/public-key-from-env
Browse files Browse the repository at this point in the history
feat: get public key directly from environment
  • Loading branch information
AndyTWF authored Dec 18, 2023
2 parents e1ec34c + 0628d85 commit 8e6417c
Showing 1 changed file with 17 additions and 10 deletions.
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

0 comments on commit 8e6417c

Please sign in to comment.