forked from baron/baron-sso
fix: 환경변수 내 큰따옴표(")로 인한 URL 파싱 에러 수정 (utils.GetEnv 도입) #239
This commit is contained in:
@@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"baron-sso-backend/internal/domain"
|
"baron-sso-backend/internal/domain"
|
||||||
|
"baron-sso-backend/internal/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -27,8 +28,8 @@ type HydraAdminService struct {
|
|||||||
|
|
||||||
func NewHydraAdminService() *HydraAdminService {
|
func NewHydraAdminService() *HydraAdminService {
|
||||||
return &HydraAdminService{
|
return &HydraAdminService{
|
||||||
AdminURL: getenv("HYDRA_ADMIN_URL", "http://hydra:4445"),
|
AdminURL: utils.GetEnv("HYDRA_ADMIN_URL", "http://hydra:4445"),
|
||||||
PublicURL: getenv("HYDRA_PUBLIC_URL", "http://hydra:4444"),
|
PublicURL: utils.GetEnv("HYDRA_PUBLIC_URL", "http://hydra:4444"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"baron-sso-backend/internal/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,14 +28,8 @@ type ketoService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewKetoService() KetoService {
|
func NewKetoService() KetoService {
|
||||||
readURL := os.Getenv("KETO_READ_URL")
|
readURL := utils.GetEnv("KETO_READ_URL", "http://keto:4466")
|
||||||
if readURL == "" {
|
writeURL := utils.GetEnv("KETO_WRITE_URL", "http://keto:4467")
|
||||||
readURL = "http://keto:4466"
|
|
||||||
}
|
|
||||||
writeURL := os.Getenv("KETO_WRITE_URL")
|
|
||||||
if writeURL == "" {
|
|
||||||
writeURL = "http://keto:4467"
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ketoService{
|
return &ketoService{
|
||||||
readURL: readURL,
|
readURL: readURL,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"baron-sso-backend/internal/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -28,7 +29,7 @@ type KratosAdminService struct {
|
|||||||
|
|
||||||
func NewKratosAdminService() *KratosAdminService {
|
func NewKratosAdminService() *KratosAdminService {
|
||||||
return &KratosAdminService{
|
return &KratosAdminService{
|
||||||
AdminURL: getenvKratos("KRATOS_ADMIN_URL", "http://kratos:4434"),
|
AdminURL: utils.GetEnv("KRATOS_ADMIN_URL", "http://kratos:4434"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,8 +228,9 @@ func (s *KratosAdminService) httpClient() *http.Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getenvKratos(key, fallback string) string {
|
func getenvKratos(key, fallback string) string {
|
||||||
if v := os.Getenv(key); v != "" {
|
v := os.Getenv(key)
|
||||||
return v
|
if v == "" {
|
||||||
|
return fallback
|
||||||
}
|
}
|
||||||
return fallback
|
return strings.Trim(v, "\"")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"baron-sso-backend/internal/domain"
|
"baron-sso-backend/internal/domain"
|
||||||
|
"baron-sso-backend/internal/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -27,9 +28,9 @@ type OryProvider struct {
|
|||||||
|
|
||||||
func NewOryProvider() *OryProvider {
|
func NewOryProvider() *OryProvider {
|
||||||
return &OryProvider{
|
return &OryProvider{
|
||||||
KratosAdminURL: getenv("KRATOS_ADMIN_URL", "http://kratos:4434"),
|
KratosAdminURL: utils.GetEnv("KRATOS_ADMIN_URL", "http://kratos:4434"),
|
||||||
KratosPublicURL: getenv("KRATOS_PUBLIC_URL", "http://kratos:4433"),
|
KratosPublicURL: utils.GetEnv("KRATOS_PUBLIC_URL", "http://kratos:4433"),
|
||||||
HydraAdminURL: getenv("HYDRA_ADMIN_URL", "http://hydra:4445"),
|
HydraAdminURL: utils.GetEnv("HYDRA_ADMIN_URL", "http://hydra:4445"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -727,10 +728,12 @@ func (o *OryProvider) UpdateUserPassword(loginID, newPassword string, r *http.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getenv(key, fallback string) string {
|
func getenv(key, fallback string) string {
|
||||||
if v := os.Getenv(key); v != "" {
|
v := os.Getenv(key)
|
||||||
return v
|
if v == "" {
|
||||||
|
return fallback
|
||||||
}
|
}
|
||||||
return fallback
|
// Strip surrounding double quotes if present
|
||||||
|
return strings.Trim(v, "\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
// findIdentityID: Kratos Admin API에서 credentials_identifier로 검색 후 첫 번째 identity id 반환
|
// findIdentityID: Kratos Admin API에서 credentials_identifier로 검색 후 첫 번째 identity id 반환
|
||||||
|
|||||||
22
backend/internal/utils/env.go
Normal file
22
backend/internal/utils/env.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetEnv retrieves the value of the environment variable named by the key.
|
||||||
|
// It returns the value if it exists, otherwise it returns the fallback value.
|
||||||
|
// It automatically strips surrounding double quotes from the value.
|
||||||
|
func GetEnv(key, fallback string) string {
|
||||||
|
v := os.Getenv(key)
|
||||||
|
if v == "" {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
// Strip surrounding double quotes if present
|
||||||
|
v = strings.TrimSpace(v)
|
||||||
|
if len(v) >= 2 && v[0] == '"' && v[len(v)-1] == '"' {
|
||||||
|
return v[1 : len(v)-1]
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user