client

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTLSConfig

func BuildTLSConfig(cfg *config.Config) (*tls.Config, error)

BuildTLSConfig creates a tls.Config based on the client configuration.

Types

type APIError

type APIError struct {
	Code    int
	Message string
}

APIError represents a structured Wazuh API error.

func (*APIError) Error

func (e *APIError) Error() string

type AuthError

type AuthError struct {
	Message string
}

AuthError represents an authentication failure.

func (*AuthError) Error

func (e *AuthError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps an http.Client with Wazuh-specific auth and configuration.

func NewClient

func NewClient(cfg *config.Config) (*Client, error)

NewClient creates a new Wazuh API client from the given config.

func (*Client) Auth

func (c *Client) Auth() *authManager

Auth returns the authentication manager for this client.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the configured API base URL.

func (*Client) Delete

func (c *Client) Delete(path string, params *QueryParams) (*Response, error)

Delete performs an authenticated DELETE request.

func (*Client) Get

func (c *Client) Get(path string, params *QueryParams) (*Response, error)

Get performs an authenticated GET request and returns the parsed response.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient returns the underlying http.Client (for testing).

func (*Client) Post

func (c *Client) Post(path string, body interface{}) (*Response, error)

Post performs an authenticated POST request with a JSON body.

func (*Client) Put

func (c *Client) Put(path string, body interface{}) (*Response, error)

Put performs an authenticated PUT request with a JSON body.

type QueryParams

type QueryParams struct {
	Offset  int
	Limit   int
	Sort    string
	Search  string
	Query   string // WQL
	Select  []string
	Filters map[string]string
}

QueryParams contains common Wazuh API query parameters.

type Response

type Response struct {
	// Data holds the actual response payload.
	Data json.RawMessage `json:"data"`
	// Error is the Wazuh API error code (0 = success).
	Error int `json:"error"`
	// Message is set when Error != 0.
	Message string `json:"message"`

	// Pagination metadata (populated from data.total_affected_items etc.)
	TotalAffectedItems int             `json:"-"`
	AffectedItems      json.RawMessage `json:"-"`
	FailedItems        json.RawMessage `json:"-"`

	// Raw HTTP status code
	HTTPStatus int `json:"-"`
	// RawBody is the full unparsed response (for --output raw)
	RawBody []byte `json:"-"`
}

Response represents the parsed Wazuh API response envelope.

func (*Response) IsSuccess

func (r *Response) IsSuccess() bool

IsSuccess returns true if the API call succeeded.

func (*Response) Items

func (r *Response) Items() json.RawMessage

Items returns the affected_items array from the data envelope. Returns raw data if affected_items is not present.

Jump to

Keyboard shortcuts

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