@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"context"
5
+ "crypto/x509"
5
6
"encoding/json"
6
7
"fmt"
7
8
"log"
@@ -13,6 +14,7 @@ import (
13
14
"github.com/gorilla/mux"
14
15
ec "github.com/qu1queee/CodeEngine/grpc/ecommerce"
15
16
"google.golang.org/grpc"
17
+ "google.golang.org/grpc/credentials"
16
18
"google.golang.org/grpc/credentials/insecure"
17
19
)
18
20
@@ -98,10 +100,28 @@ func BuyHandler(w http.ResponseWriter, r *http.Request, groceryClient ec.Grocery
98
100
}
99
101
100
102
func main () {
101
- localEndpoint := os .Getenv ("LOCAL_ENDPOINT_WITH_PORT" )
103
+ endpoint := os .Getenv ("ENDPOINT_WITH_PORT" )
104
+ if endpoint == "" {
105
+ log .Fatalf ("no endpoint set: %s" , endpoint )
106
+ }
107
+ certPool , err := x509 .SystemCertPool ()
108
+ if err != nil {
109
+ log .Fatalf ("failed to get cert pool: %v" , err )
110
+ }
111
+ creds := credentials .NewClientTLSFromCert (certPool , "" )
112
+ insArg := os .Getenv ("INSECURE" )
113
+ if insArg != "" {
114
+ unencrypted , err := strconv .ParseBool (insArg )
115
+ if err != nil {
116
+ log .Fatalf ("could not parse %v: " , err )
117
+ }
118
+ if unencrypted {
119
+ creds = insecure .NewCredentials ()
120
+ }
121
+ }
102
122
103
- fmt .Printf ("using local endpoint: %s\n " , localEndpoint )
104
- conn , err := grpc .Dial (localEndpoint , grpc .WithTransportCredentials (insecure . NewCredentials () ))
123
+ fmt .Printf ("using endpoint: %s\n " , endpoint )
124
+ conn , err := grpc .Dial (endpoint , grpc .WithTransportCredentials (creds ))
105
125
if err != nil {
106
126
log .Fatalf ("failed to connect: %v" , err )
107
127
}
0 commit comments