connection

package
v0.0.0-...-949e47c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package connection provides a set of helpers to establish connections with gRPC and HTTP endpoints.

Index

Constants

View Source
const AgentHeader = "agent"

AgentHeader with the key name for the agent payload.

View Source
const ContextTimeout = 5 * time.Minute

ContextTimeout with the default timeout for Napptive playground operations.

View Source
const VersionHeader = "version"

VersionHeader with the key name for the version payload.

Variables

This section is empty.

Functions

func GetConnection

func GetConnection(cfg *Config) (*grpc.ClientConn, error)

GetConnection creates a connection with a gRPC server.

func GetNonTLSConnection

func GetNonTLSConnection(_ *Config, address string) (*grpc.ClientConn, error)

GetNonTLSConnection returns a plain connection with the playground server.

func GetTLSConnection

func GetTLSConnection(cfg *Config, address string) (*grpc.ClientConn, error)

GetTLSConnection returns a TLS wrapped connection with the playground server.

Types

type Config

type Config struct {
	// Name of the connection as user information.
	Name string
	// ServerAddress with the dns/IP of the target gRPC server.
	ServerAddress string
	// ServerPort with the port of the catalog-manager gRPC server.
	ServerPort int
	// AuthEnable with a flag to indicate if the authentication is enabled or not
	AuthEnable bool
	// UseTLS indicates that a TLS connection is expected with the service.
	UseTLS bool
	// SkipCertValidation flag that enables ignoring the validation step of the certificate presented by the server.
	SkipCertValidation bool
	// ClientCA with a client trusted CA
	ClientCA string
}

Config contains the configuration elements related to the connection with gRPC services.

func (*Config) GetEffectiveAddress

func (cc *Config) GetEffectiveAddress() string

GetEffectiveAddress returns an address:port string.

func (*Config) IsValid

func (cc *Config) IsValid() error

IsValid checks if the configuration options are valid.

func (*Config) Print

func (cc *Config) Print()

Print the configuration using the application logger.

type ContextHelper

type ContextHelper struct {
	// Version of the application sending the request.
	Version string
	// Agent sending the request.
	Agent string

	printer.ResultPrinter
}

ContextHelper structure to facilitate the generation of secure contexts.

func NewContextHelper

func NewContextHelper(version string, agent string, printer printer.ResultPrinter) *ContextHelper

NewContextHelper creates a ContextHelper with a given configuration.

func (*ContextHelper) GetContext

func (ch *ContextHelper) GetContext() (context.Context, context.CancelFunc)

GetContext returns a valid gRPC context with the appropriate authorization header.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL