mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-06-05 22:44:17 +00:00
Refactor codebase for clarity and consistency.
This commit is contained in:
+61
-5
@@ -1,10 +1,13 @@
|
||||
package traefikoidc
|
||||
|
||||
import "os"
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// constants
|
||||
const (
|
||||
cookie_name = "_raczylo_oidc"
|
||||
cookieName = "_raczylo_oidc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -19,6 +22,59 @@ type Config struct {
|
||||
}
|
||||
|
||||
func CreateConfig() *Config {
|
||||
infoLogger.SetOutput(os.Stdout)
|
||||
return &Config{}
|
||||
return &Config{
|
||||
Scopes: []string{"openid", "profile", "email"},
|
||||
LogLevel: "info",
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
if c.ProviderURL == "" {
|
||||
return fmt.Errorf("providerURL is required")
|
||||
}
|
||||
if c.CallbackURL == "" {
|
||||
return fmt.Errorf("callbackURL is required")
|
||||
}
|
||||
if c.ClientID == "" {
|
||||
return fmt.Errorf("clientID is required")
|
||||
}
|
||||
if c.ClientSecret == "" {
|
||||
return fmt.Errorf("clientSecret is required")
|
||||
}
|
||||
if c.SessionEncryptionKey == "" {
|
||||
return fmt.Errorf("sessionEncryptionKey is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type defaultLogger struct {
|
||||
level string
|
||||
}
|
||||
|
||||
func NewLogger(level string) Logger {
|
||||
return &defaultLogger{level: level}
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Infof(format string, args ...interface{}) {
|
||||
if l.level == "info" || l.level == "debug" {
|
||||
fmt.Printf("INFO: "+format+"\n", args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Errorf(format string, args ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: "+format+"\n", args...)
|
||||
}
|
||||
|
||||
type HTTPClient interface {
|
||||
Get(url string) (*http.Response, error)
|
||||
Do(req *http.Request) (*http.Response, error)
|
||||
}
|
||||
|
||||
type Logger interface {
|
||||
Infof(format string, args ...interface{})
|
||||
Errorf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
func handleError(w http.ResponseWriter, message string, code int) {
|
||||
http.Error(w, message, code)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user