mirror of
https://github.com/PretendoNetwork/super-mario-maker.git
synced 2026-08-01 16:04:45 -05:00
Initialize grpc, check for env vars
This commit is contained in:
parent
05707d9d47
commit
67c2f856ac
85
init.go
85
init.go
|
|
@ -1,15 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
pb "github.com/PretendoNetwork/grpc-go/account"
|
||||
"github.com/PretendoNetwork/super-mario-maker-secure/database"
|
||||
"github.com/PretendoNetwork/super-mario-maker-secure/globals"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -25,6 +32,84 @@ func init() {
|
|||
s3AccessKey := os.Getenv("PN_SMM_CONFIG_S3_ACCESS_KEY")
|
||||
s3AccessSecret := os.Getenv("PN_SMM_CONFIG_S3_ACCESS_SECRET")
|
||||
|
||||
kerberosPassword := os.Getenv("PN_SMM_KERBEROS_PASSWORD")
|
||||
authenticationServerPort := os.Getenv("PN_SMM_AUTHENTICATION_SERVER_PORT")
|
||||
secureServerHost := os.Getenv("PN_SMM_SECURE_SERVER_HOST")
|
||||
secureServerPort := os.Getenv("PN_SMM_SECURE_SERVER_PORT")
|
||||
accountGRPCHost := os.Getenv("PN_SMM_ACCOUNT_GRPC_HOST")
|
||||
accountGRPCPort := os.Getenv("PN_SMM_ACCOUNT_GRPC_PORT")
|
||||
accountGRPCAPIKey := os.Getenv("PN_SMM_ACCOUNT_GRPC_API_KEY")
|
||||
|
||||
if strings.TrimSpace(kerberosPassword) == "" {
|
||||
globals.Logger.Warningf("PN_SMM_KERBEROS_PASSWORD environment variable not set. Using default password: %q", globals.KerberosPassword)
|
||||
} else {
|
||||
globals.KerberosPassword = kerberosPassword
|
||||
}
|
||||
|
||||
if strings.TrimSpace(authenticationServerPort) == "" {
|
||||
globals.Logger.Error("PN_SMM_AUTHENTICATION_SERVER_PORT environment variable not set")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if port, err := strconv.Atoi(authenticationServerPort); err != nil {
|
||||
globals.Logger.Errorf("PN_SMM_AUTHENTICATION_SERVER_PORT is not a valid port. Expected 0-65535, got %s", authenticationServerPort)
|
||||
os.Exit(0)
|
||||
} else if port < 0 || port > 65535 {
|
||||
globals.Logger.Errorf("PN_SMM_AUTHENTICATION_SERVER_PORT is not a valid port. Expected 0-65535, got %s", authenticationServerPort)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(secureServerHost) == "" {
|
||||
globals.Logger.Error("PN_SMM_SECURE_SERVER_HOST environment variable not set")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(secureServerPort) == "" {
|
||||
globals.Logger.Error("PN_SMM_SECURE_SERVER_PORT environment variable not set")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if port, err := strconv.Atoi(secureServerPort); err != nil {
|
||||
globals.Logger.Errorf("PN_SMM_SECURE_SERVER_PORT is not a valid port. Expected 0-65535, got %s", secureServerPort)
|
||||
os.Exit(0)
|
||||
} else if port < 0 || port > 65535 {
|
||||
globals.Logger.Errorf("PN_SMM_SECURE_SERVER_PORT is not a valid port. Expected 0-65535, got %s", secureServerPort)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(accountGRPCHost) == "" {
|
||||
globals.Logger.Error("PN_SMM_ACCOUNT_GRPC_HOST environment variable not set")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(accountGRPCPort) == "" {
|
||||
globals.Logger.Error("PN_SMM_ACCOUNT_GRPC_PORT environment variable not set")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if port, err := strconv.Atoi(accountGRPCPort); err != nil {
|
||||
globals.Logger.Errorf("PN_SMM_ACCOUNT_GRPC_PORT is not a valid port. Expected 0-65535, got %s", accountGRPCPort)
|
||||
os.Exit(0)
|
||||
} else if port < 0 || port > 65535 {
|
||||
globals.Logger.Errorf("PN_SMM_ACCOUNT_GRPC_PORT is not a valid port. Expected 0-65535, got %s", accountGRPCPort)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(accountGRPCAPIKey) == "" {
|
||||
globals.Logger.Warning("Insecure gRPC server detected. PN_SMM_ACCOUNT_GRPC_API_KEY environment variable not set")
|
||||
}
|
||||
|
||||
globals.GRPCAccountClientConnection, err = grpc.Dial(fmt.Sprintf("%s:%s", accountGRPCHost, accountGRPCPort), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
globals.Logger.Criticalf("Failed to connect to account gRPC server: %v", err)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
globals.GRPCAccountClient = pb.NewAccountClient(globals.GRPCAccountClientConnection)
|
||||
globals.GRPCAccountCommonMetadata = metadata.Pairs(
|
||||
"X-API-Key", accountGRPCAPIKey,
|
||||
)
|
||||
|
||||
staticCredentials := credentials.NewStaticV4(s3AccessKey, s3AccessSecret, "")
|
||||
|
||||
minIOClient, err := minio.New(s3Endpoint, &minio.Options{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user