Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
67c1bd6a
Commit
67c1bd6a
authored
Jan 19, 2016
by
bobbyrullo
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #277 from ericchiang/cmd_stdin
*: allow dexctl set-connector-configs to read from stdin
parents
b5c7f197
ec3bc7f2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
26 deletions
+37
-26
command_config.go
cmd/dexctl/command_config.go
+15
-7
config_repo.go
connector/config_repo.go
+1
-17
dexctl_test.go
functional/dexctl_test.go
+13
-0
config.go
server/config.go
+8
-2
No files found.
cmd/dexctl/command_config.go
View file @
67c1bd6a
...
...
@@ -2,6 +2,8 @@ package main
import
(
"fmt"
"io"
"os"
"github.com/coreos/dex/connector"
"github.com/spf13/cobra"
...
...
@@ -18,8 +20,8 @@ var (
cmdSetConnectorConfigs
=
&
cobra
.
Command
{
Use
:
"set-connector-configs"
,
Short
:
"Overwrite the current IdP connector configs with those from a local file."
,
Long
:
"Overwrite the current IdP connector configs with those from a local file."
,
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.
"
,
Example
:
` dexctl set-connector-configs --db-url=${DB_URL} ./static/conn_conf.json`
,
Run
:
wrapRun
(
runSetConnectorConfigs
),
}
...
...
@@ -36,15 +38,22 @@ func runSetConnectorConfigs(cmd *cobra.Command, args []string) int {
return
2
}
rf
,
err
:=
connector
.
NewConnectorConfigRepoFromFile
(
args
[
0
])
var
r
io
.
Reader
if
from
:=
args
[
0
];
from
==
"-"
{
r
=
os
.
Stdin
}
else
{
f
,
err
:=
os
.
Open
(
from
)
if
err
!=
nil
{
stderr
(
"Unable to retrieve connector configs from
file: %v"
,
err
)
stderr
(
"Unable to open specified
file: %v"
,
err
)
return
1
}
defer
f
.
Close
()
r
=
f
}
cfgs
,
err
:=
rf
.
All
(
)
cfgs
,
err
:=
connector
.
ReadConfigs
(
r
)
if
err
!=
nil
{
stderr
(
"Unable to
retrieve connector configs from file
: %v"
,
err
)
stderr
(
"Unable to
decode connector configs
: %v"
,
err
)
return
1
}
...
...
@@ -54,7 +63,6 @@ func runSetConnectorConfigs(cmd *cobra.Command, args []string) int {
}
fmt
.
Printf
(
"Saved %d connector config(s)
\n
"
,
len
(
cfgs
))
return
0
}
...
...
connector/config_repo.go
View file @
67c1bd6a
...
...
@@ -3,12 +3,11 @@ package connector
import
(
"encoding/json"
"io"
"os"
"github.com/coreos/dex/repo"
)
func
newConnectorConfigsFromReader
(
r
io
.
Reader
)
([]
ConnectorConfig
,
error
)
{
func
ReadConfigs
(
r
io
.
Reader
)
([]
ConnectorConfig
,
error
)
{
var
ms
[]
map
[
string
]
interface
{}
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
ms
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -24,21 +23,6 @@ func newConnectorConfigsFromReader(r io.Reader) ([]ConnectorConfig, error) {
return
cfgs
,
nil
}
func
NewConnectorConfigRepoFromFile
(
loc
string
)
(
ConnectorConfigRepo
,
error
)
{
cf
,
err
:=
os
.
Open
(
loc
)
if
err
!=
nil
{
return
nil
,
err
}
defer
cf
.
Close
()
cfgs
,
err
:=
newConnectorConfigsFromReader
(
cf
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
memConnectorConfigRepo
{
configs
:
cfgs
},
nil
}
type
memConnectorConfigRepo
struct
{
configs
[]
ConnectorConfig
}
...
...
functional/dexctl_test.go
View file @
67c1bd6a
package
functional
import
(
"bytes"
"io"
"io/ioutil"
"os"
"os/exec"
...
...
@@ -42,6 +44,7 @@ func TestDexctlCommands(t *testing.T) {
args
[]
string
env
[]
string
expErr
bool
stdin
io
.
Reader
}{
{
args
:
[]
string
{
"new-client"
,
"https://example.com/callback"
},
...
...
@@ -57,10 +60,20 @@ func TestDexctlCommands(t *testing.T) {
{
args
:
[]
string
{
"set-connector-configs"
,
"--db-url"
,
dsn
,
connConfig
},
},
{
args
:
[]
string
{
"set-connector-configs"
,
"--db-url"
,
dsn
,
"-"
},
stdin
:
bytes
.
NewReader
(
connConfigExample
),
},
{
args
:
[]
string
{
"set-connector-configs"
,
"-"
},
env
:
[]
string
{
"DEXCTL_DB_URL="
+
dsn
},
stdin
:
bytes
.
NewReader
(
connConfigExample
),
},
}
for
_
,
tt
:=
range
tests
{
cmd
:=
exec
.
Command
(
"../bin/dexctl"
,
tt
.
args
...
)
cmd
.
Stdin
=
tt
.
stdin
cmd
.
Env
=
tt
.
env
out
,
err
:=
cmd
.
CombinedOutput
()
if
!
tt
.
expErr
&&
err
!=
nil
{
...
...
server/config.go
View file @
67c1bd6a
...
...
@@ -115,10 +115,16 @@ func (cfg *SingleServerConfig) Configure(srv *Server) error {
return
fmt
.
Errorf
(
"unable to read client identities from file %s: %v"
,
cfg
.
ClientsFile
,
err
)
}
cfgRepo
,
err
:=
connector
.
NewConnectorConfigRepoFromFile
(
cfg
.
ConnectorsFile
)
f
,
err
:=
os
.
Open
(
cfg
.
ConnectorsFile
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"
unable to create ConnectorConfigRepo
: %v"
,
err
)
return
fmt
.
Errorf
(
"
opening connectors file
: %v"
,
err
)
}
defer
f
.
Close
()
cfgs
,
err
:=
connector
.
ReadConfigs
(
f
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"decoding connector configs: %v"
,
err
)
}
cfgRepo
:=
connector
.
NewConnectorConfigRepoFromConfigs
(
cfgs
)
sRepo
:=
session
.
NewSessionRepo
()
skRepo
:=
session
.
NewSessionKeyRepo
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment