Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions grpc/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"crypto/x509"
"encoding/json"
"fmt"
"log"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/gorilla/mux"
ec "github.com/qu1queee/CodeEngine/grpc/ecommerce"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

Expand Down Expand Up @@ -98,10 +100,28 @@ func BuyHandler(w http.ResponseWriter, r *http.Request, groceryClient ec.Grocery
}

func main() {
localEndpoint := os.Getenv("LOCAL_ENDPOINT_WITH_PORT")
endpoint := os.Getenv("ENDPOINT_WITH_PORT")
if endpoint == "" {
log.Fatalf("no endpoint set: %s", endpoint)
}
certPool, err := x509.SystemCertPool()
if err != nil {
log.Fatalf("failed to get cert pool: %v", err)
}
creds := credentials.NewClientTLSFromCert(certPool, "")
insArg := os.Getenv("INSECURE")
if insArg != "" {
unencrypted, err := strconv.ParseBool(insArg)
if err != nil {
log.Fatalf("could not parse %v: ", err)
}
if unencrypted {
creds = insecure.NewCredentials()
}
}

fmt.Printf("using local endpoint: %s\n", localEndpoint)
conn, err := grpc.Dial(localEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
fmt.Printf("using endpoint: %s\n", endpoint)
conn, err := grpc.Dial(endpoint, grpc.WithTransportCredentials(creds))
if err != nil {
log.Fatalf("failed to connect: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion grpc/run
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ echo "[INFO] Local endpoint is: ${SERVER_INTERNAL_ENDPOINT}"

# Create the client server app
echo "[INFO] Creating CE client/server application ${CLIENT_APP_NAME}"
ibmcloud ce app create --name "${CLIENT_APP_NAME}" --image icr.io/codeengine/grpc-client --min-scale 0 --env LOCAL_ENDPOINT_WITH_PORT="${SERVER_INTERNAL_ENDPOINT}:80"
ibmcloud ce app create --name "${CLIENT_APP_NAME}" --image icr.io/codeengine/grpc-client --min-scale 0 --env INSECURE=true --env ENDPOINT_WITH_PORT="${SERVER_INTERNAL_ENDPOINT}:80"

# Get the client server public endpoint
echo "[INFO] Retrieving client/server public endpoint"
Expand Down