|
|
|
|
@ -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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|