Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow loading of connectors from .so files #1302

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions connector/plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package plugin

import (
plug "plugin"

"github.com/dexidp/dex/connector"
"github.com/sirupsen/logrus"
amdonov marked this conversation as resolved.
Show resolved Hide resolved
)

// Config holds configuration for loading a plugin
//
// An example config:
// id: sample
// name: sample
// type: plugin
// config:
// plugin: sample.so
// config:
// name: sample
// options: limitless
type Config struct {
Plugin string
Config interface{}
}

type pluginConfig interface {
Open(interface{}, string, logrus.FieldLogger) (connector.Connector, error)
}

// Open returns a connector loaded as a plugin
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) {
plug, err := plug.Open(c.Plugin)
if err != nil {
return nil, err
}
symConnector, err := plug.Lookup("Open")
if err != nil {
return nil, err
}
var connector pluginConfig
connector, ok := symConnector.(pluginConfig)
if !ok {
return nil, err
}
return connector.Open(c.Config, id, logger)
}
20 changes: 20 additions & 0 deletions connector/sample-plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"github.com/dexidp/dex/connector"
"github.com/dexidp/dex/connector/mock"
"github.com/sirupsen/logrus"
)

func main() {}

type plugin struct{}

// Open prints provided config and returns a mock CallbackConnector
func (plugin) Open(config interface{}, id string, logger logrus.FieldLogger) (connector.Connector, error) {
logger.Println("loading connector with configuration ", config)
return mock.NewCallbackConnector(logger), nil
}

// Open exports the plugin for loading
var Open plugin
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/dexidp/dex/connector/microsoft"
"github.com/dexidp/dex/connector/mock"
"github.com/dexidp/dex/connector/oidc"
"github.com/dexidp/dex/connector/plugin"
"github.com/dexidp/dex/connector/saml"
"github.com/dexidp/dex/storage"
)
Expand Down Expand Up @@ -429,6 +430,7 @@ type ConnectorConfig interface {
// ConnectorsConfig variable provides an easy way to return a config struct
// depending on the connector type.
var ConnectorsConfig = map[string]func() ConnectorConfig{
"plugin": func() ConnectorConfig { return new(plugin.Config) },
"mockCallback": func() ConnectorConfig { return new(mock.CallbackConfig) },
"mockPassword": func() ConnectorConfig { return new(mock.PasswordConfig) },
"ldap": func() ConnectorConfig { return new(ldap.Config) },
Expand Down