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
562eae3f
Commit
562eae3f
authored
Mar 23, 2017
by
rithu john
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/grpc-client: clean up the example and add tlsClientCA to ConfigMap.
parent
b112aa2e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
27 deletions
+34
-27
client.go
examples/grpc-client/client.go
+33
-27
config.yaml
examples/grpc-client/config.yaml
+1
-0
No files found.
examples/grpc-client/client.go
View file @
562eae3f
...
@@ -42,21 +42,7 @@ func newDexClient(hostAndPort, caPath, clientCrt, clientKey string) (api.DexClie
...
@@ -42,21 +42,7 @@ func newDexClient(hostAndPort, caPath, clientCrt, clientKey string) (api.DexClie
return
api
.
NewDexClient
(
conn
),
nil
return
api
.
NewDexClient
(
conn
),
nil
}
}
func
main
()
{
func
createPassword
(
cli
api
.
DexClient
)
error
{
caCrt
:=
flag
.
String
(
"ca-crt"
,
""
,
"CA certificate"
)
clientCrt
:=
flag
.
String
(
"client-crt"
,
""
,
"Client certificate"
)
clientKey
:=
flag
.
String
(
"client-key"
,
""
,
"Client key"
)
flag
.
Parse
()
if
*
clientCrt
==
""
||
*
caCrt
==
""
||
*
clientKey
==
""
{
log
.
Fatal
(
"Please provide CA & client certificates and client key. Usage: ./client --ca-crt=<path ca.crt> --client-crt=<path client.crt> --client-key=<path client key>"
)
}
client
,
err
:=
newDexClient
(
"127.0.0.1:5557"
,
*
caCrt
,
*
clientCrt
,
*
clientKey
)
if
err
!=
nil
{
log
.
Fatalf
(
"failed creating dex client: %v "
,
err
)
}
p
:=
api
.
Password
{
p
:=
api
.
Password
{
Email
:
"test@example.com"
,
Email
:
"test@example.com"
,
// bcrypt hash of the value "test1" with cost 10
// bcrypt hash of the value "test1" with cost 10
...
@@ -70,19 +56,18 @@ func main() {
...
@@ -70,19 +56,18 @@ func main() {
}
}
// Create password.
// Create password.
if
resp
,
err
:=
cli
ent
.
CreatePassword
(
context
.
TODO
(),
createReq
);
err
!=
nil
||
resp
.
AlreadyExists
{
if
resp
,
err
:=
cli
.
CreatePassword
(
context
.
TODO
(),
createReq
);
err
!=
nil
||
resp
.
AlreadyExists
{
if
resp
.
AlreadyExists
{
if
resp
.
AlreadyExists
{
log
.
Fatal
f
(
"Password %s already exists"
,
createReq
.
Password
.
Email
)
return
fmt
.
Error
f
(
"Password %s already exists"
,
createReq
.
Password
.
Email
)
}
}
log
.
Fatalf
(
"failed to create password: %v"
,
err
)
return
fmt
.
Errorf
(
"failed to create password: %v"
,
err
)
}
else
{
log
.
Printf
(
"Created password with email %s"
,
createReq
.
Password
.
Email
)
}
}
log
.
Printf
(
"Created password with email %s"
,
createReq
.
Password
.
Email
)
// List all passwords.
// List all passwords.
resp
,
err
:=
cli
ent
.
ListPasswords
(
context
.
TODO
(),
&
api
.
ListPasswordReq
{})
resp
,
err
:=
cli
.
ListPasswords
(
context
.
TODO
(),
&
api
.
ListPasswordReq
{})
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
f
(
"failed to list password: %v"
,
err
)
return
fmt
.
Error
f
(
"failed to list password: %v"
,
err
)
}
}
log
.
Print
(
"Listing Passwords:
\n
"
)
log
.
Print
(
"Listing Passwords:
\n
"
)
...
@@ -95,12 +80,33 @@ func main() {
...
@@ -95,12 +80,33 @@ func main() {
}
}
// Delete password with email = test@example.com.
// Delete password with email = test@example.com.
if
resp
,
err
:=
cli
ent
.
DeletePassword
(
context
.
TODO
(),
deleteReq
);
err
!=
nil
||
resp
.
NotFound
{
if
resp
,
err
:=
cli
.
DeletePassword
(
context
.
TODO
(),
deleteReq
);
err
!=
nil
||
resp
.
NotFound
{
if
resp
.
NotFound
{
if
resp
.
NotFound
{
log
.
Fatal
f
(
"Password %s not found"
,
deleteReq
.
Email
)
return
fmt
.
Error
f
(
"Password %s not found"
,
deleteReq
.
Email
)
}
}
log
.
Fatalf
(
"failed to delete password: %v"
,
err
)
return
fmt
.
Errorf
(
"failed to delete password: %v"
,
err
)
}
else
{
}
log
.
Printf
(
"Deleted password with email %s"
,
deleteReq
.
Email
)
log
.
Printf
(
"Deleted password with email %s"
,
deleteReq
.
Email
)
return
nil
}
func
main
()
{
caCrt
:=
flag
.
String
(
"ca-crt"
,
""
,
"CA certificate"
)
clientCrt
:=
flag
.
String
(
"client-crt"
,
""
,
"Client certificate"
)
clientKey
:=
flag
.
String
(
"client-key"
,
""
,
"Client key"
)
flag
.
Parse
()
if
*
clientCrt
==
""
||
*
caCrt
==
""
||
*
clientKey
==
""
{
log
.
Fatal
(
"Please provide CA & client certificates and client key. Usage: ./client --ca-crt=<path ca.crt> --client-crt=<path client.crt> --client-key=<path client key>"
)
}
client
,
err
:=
newDexClient
(
"127.0.0.1:5557"
,
*
caCrt
,
*
clientCrt
,
*
clientKey
)
if
err
!=
nil
{
log
.
Fatalf
(
"failed creating dex client: %v "
,
err
)
}
if
err
:=
createPassword
(
client
);
err
!=
nil
{
log
.
Fatalf
(
"testPassword failed: %v"
,
err
)
}
}
}
}
examples/grpc-client/config.yaml
View file @
562eae3f
...
@@ -13,6 +13,7 @@ grpc:
...
@@ -13,6 +13,7 @@ grpc:
addr
:
127.0.0.1:5557
addr
:
127.0.0.1:5557
tlsCert
:
server.crt
tlsCert
:
server.crt
tlsKey
:
server.key
tlsKey
:
server.key
tlsClientCA
:
ca.crt
connectors
:
connectors
:
-
type
:
mockCallback
-
type
:
mockCallback
...
...
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