feat #31: add mock connector #2
2 changed files with 39 additions and 2 deletions
25
polyculeconnect/connector/refuse_all.go
Normal file
25
polyculeconnect/connector/refuse_all.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package connector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/dexidp/dex/connector"
|
||||||
|
"github.com/dexidp/dex/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RefuseAllConfig struct{}
|
||||||
|
|
||||||
|
func (c *RefuseAllConfig) Open(id string, logger log.Logger) (connector.Connector, error) {
|
||||||
|
return &RefuseAllConnector{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type RefuseAllConnector struct{}
|
||||||
|
|
||||||
|
func (m *RefuseAllConnector) LoginURL(s connector.Scopes, callbackURL, state string) (string, error) {
|
||||||
|
return "", fmt.Errorf("you shouldn't use this function")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *RefuseAllConnector) HandleCallback(s connector.Scopes, r *http.Request) (identity connector.Identity, err error) {
|
||||||
faercol marked this conversation as resolved
Outdated
|
|||||||
|
return connector.Identity{}, fmt.Errorf("you shouldn't use this function")
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/config"
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/config"
|
||||||
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/connector"
|
||||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/logger"
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/logger"
|
||||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/server"
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/server"
|
||||||
dex_server "github.com/dexidp/dex/server"
|
dex_server "github.com/dexidp/dex/server"
|
||||||
|
@ -61,10 +62,21 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.L.Info("Initializing authentication backends")
|
logger.L.Info("Initializing authentication backends")
|
||||||
|
|
||||||
|
dex_server.ConnectorsConfig["refuseAll"] = func() dex_server.ConnectorConfig { return new(connector.RefuseAllConfig) }
|
||||||
|
if err := dexConf.Storage.CreateConnector(storage.Connector{
|
||||||
|
ID: "null",
|
||||||
|
Name: "RefuseAll",
|
||||||
|
Type: "refuseAll",
|
||||||
|
Config: nil,
|
||||||
|
}); err != nil {
|
||||||
|
logger.L.Errorf("Failed to add connector for backend RefuseAll to stage: %s", err.Error())
|
||||||
faercol marked this conversation as resolved
Outdated
faercol
commented
err c'est l'objet. Ici comme on veut le message d'erreur, c'est err c'est l'objet. Ici comme on veut le message d'erreur, c'est `err.Error()` qu'il faut mettre dans le message de log
chapoline
commented
J'ai copié collé ton code juste en dessous :D J'ai copié collé ton code juste en dessous :D
faercol
commented
~~bah du coup t'as gagné une ligne de plus à corriger 😇~~
|
|||||||
|
}
|
||||||
|
|
||||||
for _, backend := range conf.OpenConnectConfig.BackendConfigs {
|
for _, backend := range conf.OpenConnectConfig.BackendConfigs {
|
||||||
backendConfJson, err := json.Marshal(backend.Config)
|
backendConfJson, err := json.Marshal(backend.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.L.Errorf("Failed to serialize oidc config for backend %q: %s", backend.Name, err)
|
logger.L.Errorf("Failed to serialize oidc config for backend %q: %s", backend.Name, err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := dexConf.Storage.CreateConnector(storage.Connector{
|
if err := dexConf.Storage.CreateConnector(storage.Connector{
|
||||||
|
@ -73,7 +85,7 @@ func main() {
|
||||||
Type: backend.Type,
|
Type: backend.Type,
|
||||||
Config: backendConfJson,
|
Config: backendConfJson,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
logger.L.Errorf("Failed to add connector for backend %q to stage: %s", backend.Name, err)
|
logger.L.Errorf("Failed to add connector for backend %q to stage: %s", backend.Name, err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue
C'est une petite convention de code en Go, mais les messages d'erreurs doivent normalement commencer par une minuscule, du coup "you shouldn't use this function"