2015-08-18 05:57:27 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-01-19 22:29:34 +05:30
|
|
|
"io"
|
|
|
|
"os"
|
2015-08-18 05:57:27 +05:30
|
|
|
|
|
|
|
"github.com/coreos/dex/connector"
|
2015-12-29 05:25:11 +05:30
|
|
|
"github.com/spf13/cobra"
|
2015-08-18 05:57:27 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-12-29 05:25:11 +05:30
|
|
|
cmdGetConnectorConfigs = &cobra.Command{
|
|
|
|
Use: "get-connector-configs",
|
|
|
|
Short: "Enumerate current IdP connector configs.",
|
|
|
|
Long: "Enumerate current IdP connector configs.",
|
|
|
|
Example: ` dexctl get-connector-configs --db-url=${DB_URL}`,
|
|
|
|
Run: wrapRun(runGetConnectorConfigs),
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
2015-12-29 05:25:11 +05:30
|
|
|
cmdSetConnectorConfigs = &cobra.Command{
|
|
|
|
Use: "set-connector-configs",
|
2016-01-19 22:29:34 +05:30
|
|
|
Short: "Overwrite the current IdP connector configs with those from a local file. Provide the argument '-' to read from stdin.",
|
|
|
|
Long: "Overwrite the current IdP connector configs with those from a local file. Provide the argument '-' to read from stdin.",
|
2015-12-29 05:25:11 +05:30
|
|
|
Example: ` dexctl set-connector-configs --db-url=${DB_URL} ./static/conn_conf.json`,
|
|
|
|
Run: wrapRun(runSetConnectorConfigs),
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-12-29 05:25:11 +05:30
|
|
|
rootCmd.AddCommand(cmdGetConnectorConfigs)
|
|
|
|
rootCmd.AddCommand(cmdSetConnectorConfigs)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
2015-12-29 05:25:11 +05:30
|
|
|
func runSetConnectorConfigs(cmd *cobra.Command, args []string) int {
|
2015-08-18 05:57:27 +05:30
|
|
|
if len(args) != 1 {
|
|
|
|
stderr("Provide a single argument.")
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2016-01-19 22:29:34 +05:30
|
|
|
var r io.Reader
|
|
|
|
if from := args[0]; from == "-" {
|
|
|
|
r = os.Stdin
|
|
|
|
} else {
|
|
|
|
f, err := os.Open(from)
|
|
|
|
if err != nil {
|
|
|
|
stderr("Unable to open specified file: %v", err)
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
r = f
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
2016-01-19 22:29:34 +05:30
|
|
|
cfgs, err := connector.ReadConfigs(r)
|
2015-08-18 05:57:27 +05:30
|
|
|
if err != nil {
|
2016-01-19 22:29:34 +05:30
|
|
|
stderr("Unable to decode connector configs: %v", err)
|
2015-08-18 05:57:27 +05:30
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := getDriver().SetConnectorConfigs(cfgs); err != nil {
|
|
|
|
stderr(err.Error())
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Saved %d connector config(s)\n", len(cfgs))
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2015-12-29 05:25:11 +05:30
|
|
|
func runGetConnectorConfigs(cmd *cobra.Command, args []string) int {
|
2015-08-18 05:57:27 +05:30
|
|
|
if len(args) != 0 {
|
|
|
|
stderr("Provide zero arguments.")
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
cfgs, err := getDriver().ConnectorConfigs()
|
|
|
|
if err != nil {
|
|
|
|
stderr("Unable to retrieve connector configs: %v", err)
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Found %d connector config(s)\n", len(cfgs))
|
|
|
|
|
|
|
|
for _, cfg := range cfgs {
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Printf("ID: %v\n", cfg.ConnectorID())
|
|
|
|
fmt.Printf("Type: %v\n", cfg.ConnectorType())
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|