package
8.15.2+incompatible
Repository: https://github.com/elastic/elastic-agent.git
Documentation: pkg.go.dev

# README

Mock Fleet Server

It's a mock for fleet-server, allowing testing of Agent interactions with fleet-server without the need to run a fleet-server and have full control over it, to even test edge cases such as error handling.

The server is designed to work with one single agent. The Agent either needs to be enrolled or AgentID must be set on Handlers. Use WithAgentID to set it when creating the server. Also, the requests are executed sequentially, making safe for the handlers implementations to access and eventually change the Handlers properties.

Right now there is no authentication, which means any enrollment token will work by default. There is some work done for authentication on auth.go.

tl;dr

  • See testing/integration/proxy_url_test.go

  • and fleetservertest_test.go for examples.

  • on fleetservertest.Handlers the handlernameFn properties are used for

  • implementing the handlers.By default, any not implemented handler returns a

  • http.StatusNotImplemented.

  • Use fleetservertest.NewServer(fleetservertest.Handlers{}) to create a new

  • test server. It's a *httptest.Server:

	NewServer(&Handlers{
		AckFn:            nil,
		CheckinFn:        nil,
		EnrollFn:         nil,
		ArtifactFn:       nil,
		StatusFn:         nil,
		UploadBeginFn:    nil,
		UploadChunkFn:    nil,
		UploadCompleteFn: nil,
	})
  • Use the fleetservertest.NewPATHNAME(args) functions to get a path ready to be used:
p := NewPathAgentAcks("my-agent-id")
// p = "/api/fleet/agents/my-agent-id/acks"
  • Use fleetservertest.NewHANDERNAME() to get a ready to use handler:
ts := fleetservertest.NewServer(&Handlers{
	CheckinFn: fleetservertest.NewHandlerStatusHealth(),
})

# Functions

Authenticate extracts the authentication from the HeaderAuthorization header and validates against key and returns: - an empty APIKey and an error if a key cannot be extracted, - the extracted APIKey and error if it does not match a.APIKey, - the extracted APIKey and a nil error if all succeeds.
TODO: it does not work for enroll.
AuthFromCtx returns the APIKey the agent sent with the request or empty if none is found.
No description provided by the author
No description provided by the author
NewActionPolicyChangeWithFakeComponent returns a AckableAction where the policy, AckableAction.data, contains one single integration.
No description provided by the author
NewAPIKey generates an APIKey from the given base 64 encoded auth and returns as *APIKey or an HTTPError if any error happens.
NewAuthorizationHeader returns an authorization header key-value pair built from key to be used to authenticate requests to Fleet Server.
NewCheckinActionsWithAcker returns a new CheckinActionsWithAcker.
NewCheckinResponse returns a valid JSON encoded checkin response with the provided actions.
NewEmptyPolicy returns an policy without any input and monitoring disabled.
No description provided by the author
NewHandlerAckWithAcker takes an acker, a function that for each actionID must return the expected AckResponseItem for that action and if this ack errored or not, and returns a Ack handler which uses the provided acker when acking agent actions.
NewHandlerCheckin takes an ActionsGenerator which is used to populate the actions in the CheckinResponse.
NewHandlerEnroll returns an enrol handler ready to be used.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewRouter creates a new *mux.Router for each route defined on handlers.
NewServer returns a new started *httptest.Server mocking the Fleet Server API.
NewServerWithHandlers returns a Fleet Server ready for use to Agent's e2e tests.
WithAddress will set the address the server will listen on.
WithAgentID sets the agentID considered enrolled with the server.
WithRequestLog sets the server to log every request using logFn.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
AckRequest - The request an elastic-agent sends to fleet-serve to acknowledge the execution of one or more actions.
AckResponse - Response to processing acknowledgement events.
AckResponseItem - The results of processing an acknowledgement event.
Action - An action for an elastic-agent.
ActionSignature - Optional action signing data.
No description provided by the author
APIKey is used to represent an APIKey and APIKeyID pair.
CheckinAction is the actions to be sent on next checkin and the delay, how long the handler will wait before sending the response.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
EnrollMetadata - Metadata associated with the agent that is enrolling to fleet.
EnrollRequest - A request to enroll a new agent into fleet.
EnrollResponse - The enrollment action response.
EnrollResponseItem - Response to a successful enrollment of an agent into fleet.
Event - The ack for a specific action that the elastic-agent has executed.
Handlers holds the handlers for the fleet-server-api, see https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/fleet-server/main/model/openapi.yml for rendered OpenAPI definition.
Hash - Checksums on the file contents.
HTTPError is the HTTP error to be returned to the client.
No description provided by the author
No description provided by the author
No description provided by the author
StatusResponse - Status response information.
StatusResponseVersion - Version information included in the response to an authorized status request.
TmplPolicy is all the data used to create a policy.
No description provided by the author
No description provided by the author
UploadBeginResponse - Response to initiating a file upload.
No description provided by the author
UploadCompleteRequest - Request to verify and finish an uploaded file.
UploadCompleteRequestTransithash - the transithash (sha256 of the concatenation of each in-order chunk hash) of the entire file contents.

# Type aliases

Acker is a function that for each actionID must return a AckResponseItem for that action and if this ack errored or not.
ActionsGenerator is a function which upon call returns the actions the checkin handler will add to its repose to the Elastic Agent.
No description provided by the author