mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix: adjust docker and any file for starting project
This commit is contained in:
+70
-62
@@ -1,7 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
|
||||
@@ -9,32 +10,28 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
IsProd bool
|
||||
AppHost string
|
||||
Version string
|
||||
LogLevel string
|
||||
AppPort int
|
||||
DBHost string
|
||||
DBUser string
|
||||
DBPassword string
|
||||
DBName string
|
||||
DBPort int
|
||||
JWTSecret string
|
||||
JWTAccessExp int
|
||||
JWTRefreshExp int
|
||||
JWTResetPasswordExp int
|
||||
JWTVerifyEmailExp int
|
||||
PostgresDSN string
|
||||
RedisURL string
|
||||
Issuer string
|
||||
SMTPHost string
|
||||
SMTPPort int
|
||||
SMTPUsername string
|
||||
SMTPPassword string
|
||||
EmailFrom string
|
||||
GoogleClientID string
|
||||
GoogleClientSecret string
|
||||
RedirectURL string
|
||||
IsProd bool
|
||||
AppHost string
|
||||
Version string
|
||||
LogLevel string
|
||||
AppPort int
|
||||
DBHost string
|
||||
DBUser string
|
||||
DBPassword string
|
||||
DBName string
|
||||
DBPort int
|
||||
JWTSecret string
|
||||
JWTAccessExp int
|
||||
JWTRefreshExp int
|
||||
JWTResetPasswordExp int
|
||||
JWTVerifyEmailExp int
|
||||
RedisURL string
|
||||
CORSAllowOrigins []string
|
||||
CORSAllowMethods []string
|
||||
CORSAllowHeaders []string
|
||||
CORSExposeHeaders []string
|
||||
CORSAllowCredentials bool
|
||||
CORSMaxAge int
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -42,16 +39,8 @@ func init() {
|
||||
|
||||
// server configuration
|
||||
IsProd = viper.GetString("APP_ENV") == "prod"
|
||||
// AppHost = viper.GetString("APP_HOST")
|
||||
// AppPort = viper.GetInt("APP_PORT")
|
||||
AppHost = viper.GetString("APP_HOST")
|
||||
if AppHost == "" {
|
||||
AppHost = "0.0.0.0"
|
||||
}
|
||||
AppPort = viper.GetInt("APP_PORT")
|
||||
if AppPort == 0 {
|
||||
AppPort = 8080
|
||||
}
|
||||
Version = viper.GetString("VERSION")
|
||||
LogLevel = viper.GetString("LOG_LEVEL")
|
||||
|
||||
@@ -61,13 +50,6 @@ func init() {
|
||||
DBPassword = viper.GetString("DB_PASSWORD")
|
||||
DBName = viper.GetString("DB_NAME")
|
||||
DBPort = viper.GetInt("DB_PORT")
|
||||
PostgresDSN = viper.GetString("POSTGRES_DSN")
|
||||
if PostgresDSN == "" {
|
||||
PostgresDSN = fmt.Sprintf(
|
||||
"postgres://%s:%s@%s:%d/%s?sslmode=disable",
|
||||
DBUser, DBPassword, DBHost, DBPort, DBName,
|
||||
)
|
||||
}
|
||||
|
||||
// jwt configuration
|
||||
JWTSecret = viper.GetString("JWT_SECRET")
|
||||
@@ -76,27 +58,16 @@ func init() {
|
||||
JWTResetPasswordExp = viper.GetInt("JWT_RESET_PASSWORD_EXP_MINUTES")
|
||||
JWTVerifyEmailExp = viper.GetInt("JWT_VERIFY_EMAIL_EXP_MINUTES")
|
||||
|
||||
// Redis / OIDC
|
||||
RedisURL = viper.GetString("REDIS_URL")
|
||||
if RedisURL == "" {
|
||||
RedisURL = "redis://redis:6379/0"
|
||||
}
|
||||
Issuer = viper.GetString("ISSUER")
|
||||
if Issuer == "" {
|
||||
// fallback ke SSO_ISSUER jika kamu sudah pakai itu sebelumnya
|
||||
Issuer = viper.GetString("SSO_ISSUER")
|
||||
}
|
||||
// SMTP configuration
|
||||
SMTPHost = viper.GetString("SMTP_HOST")
|
||||
SMTPPort = viper.GetInt("SMTP_PORT")
|
||||
SMTPUsername = viper.GetString("SMTP_USERNAME")
|
||||
SMTPPassword = viper.GetString("SMTP_PASSWORD")
|
||||
EmailFrom = viper.GetString("EMAIL_FROM")
|
||||
//Cors
|
||||
CORSAllowOrigins = parseList("CORS_ALLOW_ORIGINS")
|
||||
CORSAllowMethods = parseListWithDefault("CORS_ALLOW_METHODS", "GET,POST,PUT,PATCH,DELETE,OPTIONS")
|
||||
CORSAllowHeaders = parseListWithDefault("CORS_ALLOW_HEADERS", "Content-Type,Authorization,X-Requested-With")
|
||||
CORSExposeHeaders = parseList("CORS_EXPOSE_HEADERS")
|
||||
CORSAllowCredentials = viper.GetBool("CORS_ALLOW_CREDENTIALS")
|
||||
CORSMaxAge = viper.GetInt("CORS_MAX_AGE")
|
||||
|
||||
// oauth2 configuration
|
||||
GoogleClientID = viper.GetString("GOOGLE_CLIENT_ID")
|
||||
GoogleClientSecret = viper.GetString("GOOGLE_CLIENT_SECRET")
|
||||
RedirectURL = viper.GetString("REDIRECT_URL")
|
||||
// Redis
|
||||
RedisURL = viper.GetString("REDIS_URL")
|
||||
}
|
||||
|
||||
func loadConfig() {
|
||||
@@ -109,3 +80,40 @@ func loadConfig() {
|
||||
utils.Log.Warn("No .env file found, using environment variables only")
|
||||
}
|
||||
}
|
||||
|
||||
func parseList(key string) []string {
|
||||
raw := strings.TrimSpace(viper.GetString(key))
|
||||
if raw == "" {
|
||||
return nil
|
||||
}
|
||||
if strings.HasPrefix(raw, "[") {
|
||||
var arr []string
|
||||
if json.Unmarshal([]byte(raw), &arr) == nil {
|
||||
for i := range arr {
|
||||
arr[i] = strings.TrimSpace(arr[i])
|
||||
}
|
||||
return arr
|
||||
}
|
||||
}
|
||||
parts := strings.Split(raw, ",")
|
||||
out := make([]string, 0, len(parts))
|
||||
for _, p := range parts {
|
||||
p = strings.TrimSpace(p)
|
||||
if p != "" {
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func parseListWithDefault(key, def string) []string {
|
||||
if v := parseList(key); len(v) > 0 {
|
||||
return v
|
||||
}
|
||||
// fallback ke default CSV
|
||||
parts := strings.Split(def, ",")
|
||||
for i := range parts {
|
||||
parts[i] = strings.TrimSpace(parts[i])
|
||||
}
|
||||
return parts
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEArf9cLsf3m4TituVqDwvM
|
||||
yaUwQ0rzDfOcmF/N+rHvgMMv1yyR4FcozoGk1NFfL/4jDIVm9FLUS68foPDo0iu5
|
||||
shNY0pwSsps9lcyWxQVhUVJzh489S53hU799PiDrUPBxYTcpy3EO/jX0HOZJs5dl
|
||||
N/4C54LYrVdXyleG82NLNjcMnNGr3VGc6zE7B3YYd9/daPyr+QBpeUL5BIzUZbeu
|
||||
sI0NMIxucaqxMKWF62CDWTrwfSSoFOubI9FZ9tkkWro01wVFK35GseQCsDtEmJ9v
|
||||
kb81LvfM2AcPLr+g1kN8dVeZLNNQTMrmxaWXFiwwEgayJ8q01pHfgAxg42ariKEK
|
||||
fX9kFx/3Rs80qsXhQNEkoCOwQBRNwrRxRzNfVkvuE0aRVoO6PVFE1gDOLUV2fJJs
|
||||
QUpAWMzZ/+e/N+1gKMtbaCbz2dLqnA6KkdMdHe79dMFVGx2ZnRFbyALzM3S5XgNV
|
||||
QtVvTri2PW/6ZH41T6MpLUANzuwaIEys1Az+8VLxOgBugb63xoORB2JDsebxEfsS
|
||||
HBllECnBJVuBndkJRSnbqGjCKq4sl2xXo83nZ+2eNmZO/vkTxREl8aVp3DgaHWxp
|
||||
OQIlZwbP9lsruTqSnQfH3/hLemrOhSh/hXfFguw3oOQjfeFwJBD8u7vGOl2vBi3C
|
||||
hvb8hFdjzoUXAJLxWPl5+E0CAwEAAQ==
|
||||
-----END PUBLIC KEY-----
|
||||
@@ -1,27 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
GoogleLoginConfig oauth2.Config
|
||||
}
|
||||
|
||||
var AppConfig Config
|
||||
|
||||
func GoogleConfig() oauth2.Config {
|
||||
AppConfig.GoogleLoginConfig = oauth2.Config{
|
||||
RedirectURL: RedirectURL,
|
||||
ClientID: GoogleClientID,
|
||||
ClientSecret: GoogleClientSecret,
|
||||
Scopes: []string{
|
||||
"https://www.googleapis.com/auth/userinfo.email",
|
||||
"https://www.googleapis.com/auth/userinfo.profile",
|
||||
},
|
||||
Endpoint: google.Endpoint,
|
||||
}
|
||||
|
||||
return AppConfig.GoogleLoginConfig
|
||||
}
|
||||
Reference in New Issue
Block a user