Handle tls connection with asp (#96)

This commit is contained in:
Pietralberto Mazza
2024-02-09 17:20:14 +01:00
committed by GitHub
parent ee2a416297
commit 0d8c7bffb2

View File

@@ -2,10 +2,12 @@ package main
import (
"fmt"
"strings"
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)
@@ -52,7 +54,17 @@ func getClientFromState(ctx *cli.Context) (arkv1.ArkServiceClient, func(), error
}
func getClient(ctx *cli.Context, addr string) (arkv1.ArkServiceClient, func(), error) {
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
creds := insecure.NewCredentials()
port := 80
if strings.HasPrefix(addr, "https://") {
addr = strings.TrimPrefix(addr, "https://")
creds = credentials.NewTLS(nil)
port = 443
}
if !strings.Contains(addr, ":") {
addr = fmt.Sprintf("%s:%d", addr, port)
}
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(creds))
if err != nil {
return nil, nil, err
}