Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
562eae3f
Commit
562eae3f
authored
8 years ago
by
rithu john
Browse files
Options
Downloads
Patches
Plain Diff
examples/grpc-client: clean up the example and add tlsClientCA to ConfigMap.
parent
b112aa2e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/grpc-client/client.go
+33
-27
33 additions, 27 deletions
examples/grpc-client/client.go
examples/grpc-client/config.yaml
+1
-0
1 addition, 0 deletions
examples/grpc-client/config.yaml
with
34 additions
and
27 deletions
examples/grpc-client/client.go
+
33
−
27
View file @
562eae3f
...
...
@@ -42,21 +42,7 @@ func newDexClient(hostAndPort, caPath, clientCrt, clientKey string) (api.DexClie
return
api
.
NewDexClient
(
conn
),
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
)
}
func
createPassword
(
cli
api
.
DexClient
)
error
{
p
:=
api
.
Password
{
Email
:
"test@example.com"
,
// bcrypt hash of the value "test1" with cost 10
...
...
@@ -70,19 +56,18 @@ func main() {
}
// 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
{
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
)
}
else
{
log
.
Printf
(
"Created password with email %s"
,
createReq
.
Password
.
Email
)
return
fmt
.
Errorf
(
"failed to create password: %v"
,
err
)
}
log
.
Printf
(
"Created password with email %s"
,
createReq
.
Password
.
Email
)
// List all passwords.
resp
,
err
:=
cli
ent
.
ListPasswords
(
context
.
TODO
(),
&
api
.
ListPasswordReq
{})
resp
,
err
:=
cli
.
ListPasswords
(
context
.
TODO
(),
&
api
.
ListPasswordReq
{})
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
"
)
...
...
@@ -95,12 +80,33 @@ func main() {
}
// 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
{
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
)
}
else
{
log
.
Printf
(
"Deleted password with email %s"
,
deleteReq
.
Email
)
return
fmt
.
Errorf
(
"failed to delete password: %v"
,
err
)
}
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
)
}
}
This diff is collapsed.
Click to expand it.
examples/grpc-client/config.yaml
+
1
−
0
View file @
562eae3f
...
...
@@ -13,6 +13,7 @@ grpc:
addr
:
127.0.0.1:5557
tlsCert
:
server.crt
tlsKey
:
server.key
tlsClientCA
:
ca.crt
connectors
:
-
type
:
mockCallback
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment