Commit 59dc4a94 authored by Bobby Rullo's avatar Bobby Rullo

dexctl: remove api driver

API Driver is dead: This API turns out to not be super useful, requiring
an existing client to create other clients is weird.

Long live API Driver? Let's use Dynamic Client API and the bootstrap API
to create a better API Driver! LONG LIVE API DRIVER.
parent 8942a497
package main
import (
"errors"
"net/http"
"github.com/coreos/dex/connector"
schema "github.com/coreos/dex/schema/workerschema"
"github.com/coreos/go-oidc/oidc"
)
func newAPIDriver(pcfg oidc.ProviderConfig, creds oidc.ClientCredentials) (driver, error) {
ccfg := oidc.ClientConfig{
ProviderConfig: pcfg,
Credentials: creds,
}
oc, err := oidc.NewClient(ccfg)
if err != nil {
return nil, err
}
trans := &oidc.AuthenticatedTransport{
TokenRefresher: &oidc.ClientCredsTokenRefresher{
Issuer: pcfg.Issuer.String(),
OIDCClient: oc,
},
RoundTripper: http.DefaultTransport,
}
hc := &http.Client{Transport: trans}
svc, err := schema.NewWithBasePath(hc, pcfg.Issuer.String())
if err != nil {
return nil, err
}
return &apiDriver{svc: svc}, nil
}
type apiDriver struct {
svc *schema.Service
}
func (d *apiDriver) NewClient(meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) {
sc := &schema.Client{
RedirectURIs: make([]string, len(meta.RedirectURIs)),
}
for i, u := range meta.RedirectURIs {
sc.RedirectURIs[i] = u.String()
}
call := d.svc.Clients.Create(sc)
scs, err := call.Do()
if err != nil {
return nil, err
}
creds := &oidc.ClientCredentials{
ID: scs.Id,
Secret: scs.Secret,
}
return creds, nil
}
func (d *apiDriver) ConnectorConfigs() ([]connector.ConnectorConfig, error) {
return nil, errors.New("unable to get connector configs from HTTP API")
}
func (d *apiDriver) SetConnectorConfigs(cfgs []connector.ConnectorConfig) error {
return errors.New("unable to set connector configs through HTTP API")
}
......@@ -2,7 +2,6 @@ package main
import (
"errors"
"net/http"
"os"
"strings"
......@@ -44,7 +43,6 @@ var (
}
global struct {
endpoint string
creds oidc.ClientCredentials
dbURL string
help bool
......@@ -55,9 +53,6 @@ var (
func init() {
log.EnableTimestamps()
rootCmd.PersistentFlags().StringVar(&global.endpoint, "endpoint", "", "URL of dex API")
rootCmd.PersistentFlags().StringVar(&global.creds.ID, "client-id", "", "dex API user ID")
rootCmd.PersistentFlags().StringVar(&global.creds.Secret, "client-secret", "", "dex API user password")
rootCmd.PersistentFlags().StringVar(&global.dbURL, "db-url", "", "DSN-formatted database connection string")
rootCmd.PersistentFlags().BoolVar(&global.logDebug, "log-debug", false, "Log debug-level information")
}
......@@ -79,19 +74,8 @@ func getDriver() (drv driver) {
switch {
case len(global.dbURL) > 0:
drv, err = newDBDriver(global.dbURL)
case len(global.endpoint) > 0:
if len(global.creds.ID) == 0 || len(global.creds.Secret) == 0 {
err = errors.New("--client-id/--client-secret flags unset")
break
}
pcfg, err := oidc.FetchProviderConfig(http.DefaultClient, global.endpoint)
if err != nil {
stderr("Unable to fetch provider config: %v", err)
os.Exit(1)
}
drv, err = newAPIDriver(pcfg, global.creds)
default:
err = errors.New("--endpoint/--db-url flags unset")
err = errors.New("--db-url flag unset")
}
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment