fix: allow setting the issuer from environment variables
This commit is contained in:
parent
c8958a8f44
commit
088f4faf82
3 changed files with 15 additions and 0 deletions
|
@ -51,6 +51,8 @@ The rest of the configuration is handled through environment variables
|
|||
# Can be debug,info,warning,error
|
||||
LOG_LEVEL = "info"
|
||||
|
||||
ISSUER = "http://localhost"
|
||||
|
||||
# Can be net,unix
|
||||
SERVER_MODE = "net"
|
||||
SERVER_HOST = "0.0.0.0"
|
||||
|
|
|
@ -22,6 +22,8 @@ const (
|
|||
varServerPort envVar = "SERVER_PORT"
|
||||
varServerSocket envVar = "SERVER_SOCK_PATH"
|
||||
|
||||
varIssuer envVar = "ISSUER"
|
||||
|
||||
varStorageType envVar = "STORAGE_TYPE"
|
||||
varStorageFile envVar = "STORAGE_FILEPATH"
|
||||
varStorageHost envVar = "STORAGE_HOST"
|
||||
|
@ -55,6 +57,8 @@ const (
|
|||
defaultServerPort = 5000
|
||||
defaultServerSocket = ""
|
||||
|
||||
defaultIssuer = "locahost"
|
||||
|
||||
defaultStorageType = Memory
|
||||
defaultStorageFile = "./polyculeconnect.db"
|
||||
defaultStorageHost = "127.0.0.1"
|
||||
|
@ -125,6 +129,9 @@ func (ac *AppConfig) UnmarshalJSON(data []byte) error {
|
|||
return fmt.Errorf("failed to read JSON: %w", err)
|
||||
}
|
||||
ac.OpenConnectConfig = jsonConf.OpenConnectConfig
|
||||
if ac.OpenConnectConfig == nil {
|
||||
ac.OpenConnectConfig = &OpenConnectConfig{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -145,6 +152,8 @@ func (ac *AppConfig) getConfFromEnv() {
|
|||
ac.StorageConfig.Password = getStringFromEnv(varStoragePassword, defaultStoragePassword)
|
||||
ac.StorageConfig.Ssl.CaFile = getStringFromEnv(varStorageSSLCaFile, defaultStorageSSLCaFile)
|
||||
ac.StorageConfig.Ssl.Mode = getStringFromEnv(varStorageSSLMode, defaultStorageSSLMode)
|
||||
|
||||
ac.OpenConnectConfig.Issuer = getStringFromEnv(varIssuer, defaultIssuer)
|
||||
}
|
||||
|
||||
func (ac *AppConfig) RedirectURI() string {
|
||||
|
@ -154,6 +163,7 @@ func (ac *AppConfig) RedirectURI() string {
|
|||
func New(filepath string) (*AppConfig, error) {
|
||||
var conf AppConfig
|
||||
conf.StorageConfig = &StorageConfig{}
|
||||
conf.OpenConnectConfig = &OpenConnectConfig{}
|
||||
content, err := os.ReadFile(filepath)
|
||||
if err != nil {
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
|
|
|
@ -29,6 +29,9 @@ var defaultConfig = AppConfig{
|
|||
CaFile string
|
||||
}{Mode: defaultStorageSSLMode, CaFile: defaultStorageSSLCaFile},
|
||||
},
|
||||
OpenConnectConfig: &OpenConnectConfig{
|
||||
Issuer: defaultIssuer,
|
||||
},
|
||||
}
|
||||
|
||||
func initJson(t *testing.T, content string) string {
|
||||
|
|
Loading…
Reference in a new issue