-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: add ability to load database connectors from plugins
- v2.3.0
- v2.2.0
- v2.2.0-rc.3
- v2.2.0-rc.2
- v2.2.0-rc.1
- v2.2.0-pre.1
- v2.2.0-pre.0
- v2.1.2
- v2.1.1
- v2.1.0
- v2.1.0-pre.2
- v2.1.0-pre.1
- v2.1.0-pre.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.11.10
- v1.11.9
- v1.11.8
- v1.11.7
- v1.11.6
- v1.11.5
- v1.11.4
- v1.11.3
- v1.11.2
- v1.11.1
- v1.11.0
- v1.10.7
- v1.10.6
- v1.10.5
- v1.10.3
- v1.10.2
- v1.10.1
- v1.9.2
- v1.9.1
- v1.9.0
- v1.9.0-rc.0
- v1.9.0-alpha.4.pre.0
- v1.9.0-alpha.3
- v1.9.0-alpha.2
- v1.9.0-alpha.1
- v1.8.5
- v1.8.0-pre.1
- v1.8.0-pre.0
- v1.7.4
- v1.7.3
- v1.7.1
- v1.7.0
- v1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.5.0-beta.5
- v1.5.0-beta.3
- v1.5.0-beta.2
- v1.5.0-beta.1
- v1.4.10
- v1.4.9
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.2.0-alpha.3
- v1.2.0-alpha.2
- v1.2.0-alpha.1
- v1.1.1
- v1.1.0
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v1.0.0-rc.16
- v1.0.0-rc.15
- v1.0.0-rc.14
- v1.0.0-rc.12
- v1.0.0-rc.11
- v1.0.0-rc.10
- v1.0.0-rc.9+oryOS.10
- v1.0.0-rc.8+oryOS.10
- v1.0.0-rc.7+oryOS.10
- v1.0.0-rc.6+oryOS.10
- v1.0.0-rc.5+oryOS.10
- v1.0.0-rc.4+oryOS.9
- v1.0.0-rc.3+oryOS.9
- v1.0.0-rc.2+oryOS.9
- v1.0.0-rc.1+oryOS.9
- v1.0.0-beta.9
- v1.0.0-beta.8
- v1.0.0-beta.7
- v1.0.0-beta.6
- v1.0.0-beta.5
- v1.0.0-beta.4
- v1.0.0-beta.3
- v1.0.0-beta.2
- v1.0.0-beta.1
- v0.11.14
- v0.11.12
- v0.11.10
- v0.11.9
- v0.11.7
- v0.11.6
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.10
- v0.10.9
- v0.10.8
- v0.10.7
- v0.10.6
- v0.10.5
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.10.0-alpha.21
- v0.10.0-alpha.20
- v0.10.0-alpha.19
- v0.10.0-alpha.18
- v0.10.0-alpha.17
- v0.10.0-alpha.16
- v0.10.0-alpha.15
- v0.10.0-alpha.14
- v0.10.0-alpha.13
- v0.10.0-alpha.12
- v0.10.0-alpha.11
- v0.10.0-alpha.10
- v0.10.0-alpha.9
- v0.10.0-alpha.8
- v0.10.0-alpha.7
- v0.10.0-alpha.6
- v0.10.0-alpha.5
- v0.10.0-alpha.4
- v0.10.0-alpha.3
- v0.10.0-alpha.2
- v0.10.0-alpha.1
- v0.9.16
- v0.9.15
- v0.9.14
- v0.9.13
- v0.9.12
- v0.9.11
- v0.9.10
- v0.9.9
- v0.9.8
- v0.9.7
- v0.9.6
- v0.0.1
- sdk/go/hydra/v0.0.1
- 1.4.8
Showing
17 changed files
with
221 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,6 @@ output/ | |
_book/ | ||
dist/ | ||
coverage.* | ||
docs/api.swagger.json | ||
docs/api.swagger.json | ||
Dockerfile-plugin-* | ||
plugin-*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package config | ||
|
||
type MemoryConnection struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package config | ||
|
||
import ( | ||
"plugin" | ||
"github.com/ory/ladon" | ||
"github.com/ory/hydra/client" | ||
"github.com/ory/hydra/warden/group" | ||
"github.com/ory/hydra/jwk" | ||
"github.com/ory/hydra/pkg" | ||
"github.com/pkg/errors" | ||
"github.com/Sirupsen/logrus" | ||
"github.com/ory/fosite" | ||
"github.com/jmoiron/sqlx" | ||
) | ||
|
||
type PluginConnection struct { | ||
Config *Config | ||
plugin *plugin.Plugin | ||
didConnect bool | ||
Logger logrus.FieldLogger | ||
db *sqlx.DB | ||
} | ||
|
||
func (c *PluginConnection) load() error { | ||
if c.plugin != nil { | ||
return nil | ||
} | ||
|
||
cf := c.Config | ||
p, err := plugin.Open(cf.DatabasePlugin) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
||
c.plugin = p | ||
return nil | ||
} | ||
|
||
func (c *PluginConnection) Connect() error { | ||
cf := c.Config | ||
if c.didConnect { | ||
return nil | ||
} | ||
|
||
if err := c.load(); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
||
if l, err := c.plugin.Lookup("Connect"); err != nil { | ||
return errors.Wrap(err, "Unable to look up `Connect`") | ||
} else if con, ok := l.(func(url string) (*sqlx.DB, error)); !ok { | ||
return errors.New("Unable to type assert `Connect`") | ||
} else { | ||
if db, err := con(cf.DatabaseURL); err != nil { | ||
return errors.Wrap(err, "Could not connect to database") | ||
} else { | ||
cf.GetLogger().Info("Successfully connected through database plugin") | ||
c.db = db | ||
cf.GetLogger().Debugf("Address of database plugin is: %s", c.db) | ||
if err := db.Ping(); err != nil { | ||
cf.GetLogger().WithError(err).Fatal("Could not ping database connection from plugin") | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c *PluginConnection) NewClientManager() (client.Manager, error) { | ||
if err := c.load(); err != nil { | ||
return nil, errors.WithStack(err) | ||
} | ||
|
||
ctx := c.Config.Context() | ||
if l, err := c.plugin.Lookup("NewClientManager"); err != nil { | ||
return nil, errors.Wrap(err, "Unable to look up `NewClientManager`") | ||
} else if m, ok := l.(func(*sqlx.DB, fosite.Hasher) client.Manager); !ok { | ||
return nil, errors.New("Unable to type assert `NewClientManager`") | ||
} else { | ||
return m(c.db, ctx.Hasher), nil | ||
} | ||
} | ||
|
||
func (c *PluginConnection) NewGroupManager() (group.Manager, error) { | ||
if err := c.load(); err != nil { | ||
return nil, errors.WithStack(err) | ||
} | ||
|
||
if l, err := c.plugin.Lookup("NewGroupManager"); err != nil { | ||
return nil, errors.Wrap(err, "Unable to look up `NewGroupManager`") | ||
} else if m, ok := l.(func(*sqlx.DB) group.Manager); !ok { | ||
return nil, errors.New("Unable to type assert `NewGroupManager`") | ||
} else { | ||
return m(c.db), nil | ||
} | ||
} | ||
|
||
func (c *PluginConnection) NewJWKManager() (jwk.Manager, error) { | ||
if err := c.load(); err != nil { | ||
return nil, errors.WithStack(err) | ||
} | ||
|
||
if l, err := c.plugin.Lookup("NewJWKManager"); err != nil { | ||
return nil, errors.Wrap(err, "Unable to look up `NewJWKManager`") | ||
} else if m, ok := l.(func(*sqlx.DB, *jwk.AEAD) jwk.Manager); !ok { | ||
return nil, errors.New("Unable to type assert `NewJWKManager`") | ||
} else { | ||
return m(c.db, &jwk.AEAD{ | ||
Key: c.Config.GetSystemSecret(), | ||
}), nil | ||
} | ||
} | ||
|
||
func (c *PluginConnection) NewOAuth2Manager(clientManager client.Manager) (pkg.FositeStorer, error) { | ||
if err := c.load(); err != nil { | ||
return nil, errors.WithStack(err) | ||
} | ||
|
||
if l, err := c.plugin.Lookup("NewOAuth2Manager"); err != nil { | ||
return nil, errors.Wrap(err, "Unable to look up `NewOAuth2Manager`") | ||
} else if m, ok := l.(func(*sqlx.DB, client.Manager, logrus.FieldLogger) pkg.FositeStorer); !ok { | ||
return nil, errors.New("Unable to type assert `NewOAuth2Manager`") | ||
} else { | ||
return m(c.db, clientManager, c.Config.GetLogger()), nil | ||
} | ||
} | ||
|
||
func (c *PluginConnection) NewPolicyManager() (ladon.Manager, error) { | ||
if err := c.load(); err != nil { | ||
return nil, errors.WithStack(err) | ||
} | ||
|
||
if l, err := c.plugin.Lookup("NewPolicyManager"); err != nil { | ||
return nil, errors.Wrap(err, "Unable to look up `NewPolicyManager`") | ||
} else if m, ok := l.(func(*sqlx.DB) ladon.Manager); !ok { | ||
return nil, errors.Errorf("Unable to type assert `NewPolicyManager`, got %v", l) | ||
} else { | ||
return m(c.db), nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.