Skip to content

Commit

Permalink
samples: update grpc example to support no authentication (#272)
Browse files Browse the repository at this point in the history
* samples: update grpc example to support no authentication

* add insecure flag back

Co-authored-by: Emma Haruka Iwao <yuryu@google.com>
  • Loading branch information
hongalex and yuryu authored Jul 20, 2021
1 parent 0b93c1e commit 3ad77e3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/grpc-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"bytes"
"context"
"crypto/x509"
"flag"
"fmt"
"log"
Expand All @@ -25,13 +26,15 @@ import (
"google.golang.org/api/option"
gtransport "google.golang.org/api/transport/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

pb "github.com/googleforgames/open-saves/api"
)

var (
address = flag.String("address", "localhost:6000", "Address of Open Saves server")
insecure = flag.Bool("insecure", false, "Dial grpc server insecurely")
address = flag.String("address", "localhost:6000", "Address of Open Saves server")
insecure = flag.Bool("insecure", false, "Dial grpc server insecurely")
authenticate = flag.Bool("authenticate", false, "Dial grpc server with default authentication")
)

func defaultClientOptions() []option.ClientOption {
Expand All @@ -45,6 +48,11 @@ func main() {
ctx := context.Background()

opts := defaultClientOptions()
if !*authenticate {
pool, _ := x509.SystemCertPool()
creds := credentials.NewClientTLSFromCert(pool, "")
opts = append(opts, option.WithGRPCDialOption(grpc.WithTransportCredentials(creds)), option.WithoutAuthentication())
}
if *insecure {
opts = append(opts, option.WithGRPCDialOption(grpc.WithInsecure()), option.WithoutAuthentication())
}
Expand Down

0 comments on commit 3ad77e3

Please sign in to comment.