clients

package
v0.0.0-...-6186498 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DSEntrypointReload        = "/dalekservices/connectors/reload/:agentID"
	DSEntrypointValidateToken = "/dalekservices/validate-token"
)

Define entrypoints for DSOperations

View Source
const (
	HdrCompressed     = "compressed"
	HdrPayloadType    = "payloadType"
	HdrSpanSpanID     = "spanSpanID"
	HdrSpanTraceID    = "spanTraceID"
	HdrSpanTraceFlags = "spanTraceFlags"
	HdrTodoTracerCtx  = "todoTracerCtx"
)
View Source
const (
	EnvHttpClientTimeout = "TCG_HTTP_CLIENT_TIMEOUT"
	EnvTlsClientInsecure = "TCG_TLS_CLIENT_INSECURE"
)
View Source
const EnvHttpClientTimeoutGW = "TCG_HTTP_CLIENT_TIMEOUT_GW"

Variables

View Source
var CtxHeaders = CtxKey("headers")
View Source
var GZIP = func(ctx context.Context, p []byte) (context.Context, []byte, error) {
	buf := &bytes.Buffer{}
	gw := gzip.NewWriter(buf)
	_, err := gw.Write(p)
	_ = gw.Close()
	return ctx, buf.Bytes(), err
}
View Source
var HookRequestContext = func(ctx context.Context, req *http.Request) (context.Context, *http.Request) {
	return ctx, req
}
View Source
var HttpClient = &http.Client{
	Timeout: func(env string) time.Duration {
		if s, ok := os.LookupEnv(env); ok {
			if v, err := time.ParseDuration(s); err == nil {
				return v
			}
		}
		return time.Duration(5 * time.Second)
	}(EnvHttpClientTimeout),

	Transport: HttpClientTransport,
}
View Source
var HttpClientTransport = &http.Transport{
	TLSClientConfig: &tls.Config{
		InsecureSkipVerify: func(env string) bool {
			v, err := strconv.ParseBool(os.Getenv(env))
			return err == nil && v
		}(EnvTlsClientInsecure),

		RootCAs: nil,
	},
}

Functions

func BuildQueryParams

func BuildQueryParams(params map[string]string) string

BuildQueryParams makes the query parameters string

func SendRequest

func SendRequest(httpMethod string, requestURL string,
	headers map[string]string, formValues map[string]string, body []byte) (int, []byte, error)

SendRequest wraps HTTP methods

func SendRequestWithContext

func SendRequestWithContext(ctx context.Context, httpMethod string, requestURL string,
	headers map[string]string, formValues map[string]string, body []byte) (int, []byte, error)

SendRequestWithContext wraps HTTP methods

Types

type CtxKey

type CtxKey interface{}

type DSClient

type DSClient struct {
	*DSConnection
}

DSClient implements DS API operations

func (*DSClient) Reload

func (client *DSClient) Reload(agentID string) error

Reload calls API

func (*DSClient) ValidateToken

func (client *DSClient) ValidateToken(appName, apiToken string) error

ValidateToken calls API

type DSConnection

type DSConnection struct {
	// HostName accepts value for combined "host:port"
	// used as `url.URL{HostName}`
	HostName string `yaml:"hostName"`
}

DSConnection defines DalekServices Connection configuration

type GWClient

type GWClient struct {
	AppName string
	AppType string
	*GWConnection
	// contains filtered or unexported fields
}

GWClient implements GW API operations

func (*GWClient) AuthenticatePassword

func (client *GWClient) AuthenticatePassword(username, password string) (string, error)

AuthenticatePassword calls API and returns token

func (*GWClient) ClearInDowntime

func (client *GWClient) ClearInDowntime(ctx context.Context, payload []byte) ([]byte, error)

ClearInDowntime calls API

func (*GWClient) Connect

func (client *GWClient) Connect() error

Connect calls API

func (*GWClient) Disconnect

func (client *GWClient) Disconnect() error

Disconnect calls API

func (*GWClient) GetHostGroupsByHostNamesAndAppType

func (client *GWClient) GetHostGroupsByHostNamesAndAppType(hostNames []string, appType string) (*GWHostGroups, error)

GetHostGroupsByHostNamesAndAppType calls API

func (*GWClient) GetServicesByAgent

func (client *GWClient) GetServicesByAgent(agentID string) (*GWServices, error)

GetServicesByAgent calls API

func (*GWClient) SendEvents

func (client *GWClient) SendEvents(ctx context.Context, payload []byte) ([]byte, error)

SendEvents calls API

func (*GWClient) SendEventsAck

func (client *GWClient) SendEventsAck(ctx context.Context, payload []byte) ([]byte, error)

SendEventsAck calls API

func (*GWClient) SendEventsUnack

func (client *GWClient) SendEventsUnack(ctx context.Context, payload []byte) ([]byte, error)

SendEventsUnack calls API

func (*GWClient) SendResourcesWithMetrics

func (client *GWClient) SendResourcesWithMetrics(ctx context.Context, payload []byte) ([]byte, error)

SendResourcesWithMetrics calls API

func (*GWClient) SetInDowntime

func (client *GWClient) SetInDowntime(ctx context.Context, payload []byte) ([]byte, error)

SetInDowntime calls API

func (*GWClient) SynchronizeInventory

func (client *GWClient) SynchronizeInventory(ctx context.Context, payload []byte) ([]byte, error)

SynchronizeInventory calls API

func (*GWClient) ValidateToken

func (client *GWClient) ValidateToken(appName, apiToken string) error

ValidateToken calls API

type GWConnection

type GWConnection struct {
	ID int `yaml:"id"`
	// HostName accepts value for combined "host:port"
	// used as `url.URL{HostName}`
	HostName            string `yaml:"hostName"`
	UserName            string `yaml:"userName"`
	Password            string `yaml:"password"`
	Enabled             bool   `yaml:"enabled"`
	IsChild             bool   `yaml:"isChild"`
	DisplayName         string `yaml:"displayName"`
	MergeHosts          bool   `yaml:"mergeHosts"`
	LocalConnection     bool   `yaml:"localConnection"`
	DeferOwnership      string `yaml:"deferOwnership"`
	PrefixResourceNames bool   `yaml:"prefixResourceNames"`
	ResourceNamePrefix  string `yaml:"resourceNamePrefix"`
	SendAllInventory    bool   `yaml:"sendAllInventory"`
	IsDynamicInventory  bool   `yaml:"-"`
	HTTPEncode          bool   `yaml:"-"`
}

GWConnection defines Groundwork Connection configuration

type GWEntrypoint

type GWEntrypoint string

GWEntrypoint defines entrypoint

const (
	GWEntrypointAuthenticatePassword           GWEntrypoint = "/api/users/authenticatePassword"
	GWEntrypointConnect                        GWEntrypoint = "/api/auth/login"
	GWEntrypointDisconnect                     GWEntrypoint = "/api/auth/logout"
	GWEntrypointClearInDowntime                GWEntrypoint = "/api/biz/clearindowntime"
	GWEntrypointSetInDowntime                  GWEntrypoint = "/api/biz/setindowntime"
	GWEntrypointSendEvents                     GWEntrypoint = "/api/events"
	GWEntrypointSendEventsAck                  GWEntrypoint = "/api/events/ack"
	GWEntrypointSendEventsUnack                GWEntrypoint = "/api/events/unack"
	GWEntrypointSendResourceWithMetrics        GWEntrypoint = "/api/monitoring"
	GWEntrypointSendResourceWithMetricsDynamic GWEntrypoint = "/api/monitoring?dynamic=true"
	GWEntrypointSynchronizeInventory           GWEntrypoint = "/api/synchronizer"
	GWEntrypointServices                       GWEntrypoint = "/api/services"
	GWEntrypointHostgroups                     GWEntrypoint = "/api/hostgroups"
	GWEntrypointValidateToken                  GWEntrypoint = "/api/auth/validatetoken"
)

GWEntrypoint

type GWHostGroups

type GWHostGroups struct {
	HostGroups []struct {
		Name  string `json:"name"`
		Hosts []struct {
			HostName string `json:"hostName"`
		} `json:"hosts"`
	} `json:"hostGroups"`
}

GWHostGroups defines collection

type GWServices

type GWServices struct {
	Services []struct {
		HostName string `json:"hostName"`
	} `json:"services"`
}

GWServices defines collection

type Req

type Req struct {
	Err      error
	Form     map[string]string
	Headers  map[string]string
	Method   string
	Payload  []byte
	Response []byte
	Status   int
	URL      string
	// contains filtered or unexported fields
}

Req defines request context

func (Req) Details

func (q Req) Details() ReqDetails

func (Req) LogFields

func (q Req) LogFields() (fields map[string]interface{}, rawJSON map[string][]byte)

LogFields returns fields maps

func (*Req) Send

func (q *Req) Send() (*Req, error)

Send sends request

func (*Req) SendWithContext

func (q *Req) SendWithContext(ctx context.Context) (*Req, error)

SendWithContext sends request

func (*Req) SetClient

func (q *Req) SetClient(c *http.Client) *Req

SetClient sets http.Client to use

type ReqDetails

type ReqDetails Req

ReqDetails defines an alias for logging with forced details

func (ReqDetails) LogFields

func (q ReqDetails) LogFields() (fields map[string]interface{}, rawJSON map[string][]byte)

LogFields returns fields maps

Jump to

Keyboard shortcuts

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