Skip to content

Commit

Permalink
Handle tls connection with asp (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
altafan authored Feb 9, 2024
1 parent ee2a416 commit 0d8c7bf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion noah/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0d8c7bf

Please sign in to comment.