Commit 5d49e184 authored by rithu leena john's avatar rithu leena john Committed by GitHub

Merge pull request #873 from rithujohn191/client-example

examples/grpc-client: clean up the example and add tlsClientCA to ConfigMap.
parents 6146e233 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 := client.CreatePassword(context.TODO(), createReq); err != nil || resp.AlreadyExists {
if resp, err := cli.CreatePassword(context.TODO(), createReq); err != nil || resp.AlreadyExists {
if resp.AlreadyExists {
log.Fatalf("Password %s already exists", createReq.Password.Email)
return fmt.Errorf("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 := client.ListPasswords(context.TODO(), &api.ListPasswordReq{})
resp, err := cli.ListPasswords(context.TODO(), &api.ListPasswordReq{})
if err != nil {
log.Fatalf("failed to list password: %v", err)
return fmt.Errorf("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 := client.DeletePassword(context.TODO(), deleteReq); err != nil || resp.NotFound {
if resp, err := cli.DeletePassword(context.TODO(), deleteReq); err != nil || resp.NotFound {
if resp.NotFound {
log.Fatalf("Password %s not found", deleteReq.Email)
return fmt.Errorf("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)
}
}
......@@ -13,6 +13,7 @@ grpc:
addr: 127.0.0.1:5557
tlsCert: server.crt
tlsKey: server.key
tlsClientCA: ca.crt
connectors:
- type: mockCallback
......
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