Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agent): add support for port 443 #3276

Merged
merged 1 commit into from
Oct 17, 2023
Merged
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
34 changes: 32 additions & 2 deletions agent/client/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package client

import (
"context"
"crypto/tls"
"fmt"
"net"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

Expand All @@ -27,11 +30,38 @@ func connect(ctx context.Context, endpoint string) (*grpc.ClientConn, error) {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

// TODO: don't use insecure transportation
conn, err := grpc.DialContext(ctx, endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
transportCredentials, err := getTransportCredentialsForEndpoint(endpoint)
if err != nil {
return nil, fmt.Errorf("could not get transport credentials: %w", err)
}

conn, err := grpc.DialContext(
ctx, endpoint,
grpc.WithTransportCredentials(transportCredentials),
)
if err != nil {
return nil, fmt.Errorf("could not connect to server: %w", err)
}

return conn, nil
}

func getTransportCredentialsForEndpoint(endpoint string) (credentials.TransportCredentials, error) {
_, port, err := net.SplitHostPort(endpoint)
if err != nil {
return nil, fmt.Errorf("cannot parse endpoint: %w", err)
}

switch port {
case "443":
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
}
transportCredentials := credentials.NewTLS(tlsConfig)
return transportCredentials, nil

default:
return insecure.NewCredentials(), nil
}

}
Loading