Documentation ¶
Overview ¶
Package client implements a client to the Splunk REST API.
Index ¶
- type ACL
- type Authenticator
- type Client
- func (client *Client) Create(entry interface{}) error
- func (client *Client) Delete(entry interface{}) error
- func (c *Client) EntryACLURL(e interface{}) (*url.URL, error)
- func (c *Client) EntryURL(e interface{}) (*url.URL, error)
- func (client *Client) List(entries interface{}) error
- func (client *Client) ListID(entries interface{}, id ID) error
- func (client *Client) ListNamespace(entries interface{}, ns Namespace) error
- func (client *Client) Read(entry interface{}) error
- func (client *Client) ReadACL(entry interface{}, acl *ACL) error
- func (c *Client) RequestAndHandle(builder RequestBuilder, handler ResponseHandler) error
- func (c *Client) ServiceURL(s interface{}) (*url.URL, error)
- func (client *Client) Update(entry interface{}) error
- func (client *Client) UpdateACL(entry interface{}, acl ACL) error
- type ConfID
- type Error
- type ErrorCode
- type ID
- type Namespace
- type Permissions
- type RequestBuilder
- func BuildRequestAuthenticate(c *Client) RequestBuilder
- func BuildRequestBodyValues(i interface{}) RequestBuilder
- func BuildRequestBodyValuesSelective(c interface{}, tag string) RequestBuilder
- func BuildRequestEntryACLURL(c *Client, entry interface{}, acl ACL) RequestBuilder
- func BuildRequestEntryURL(c *Client, entry interface{}) RequestBuilder
- func BuildRequestGetServiceStatusCodes(entry interface{}, codes *service.StatusCodes) RequestBuilder
- func BuildRequestMethod(method string) RequestBuilder
- func BuildRequestOutputModeJSON() RequestBuilder
- func BuildRequestServiceURL(c *Client, service interface{}) RequestBuilder
- func ComposeRequestBuilder(builders ...RequestBuilder) RequestBuilder
- type ResponseHandler
- func ComposeResponseHandler(handlers ...ResponseHandler) ResponseHandler
- func HandleResponseCode(code int, errorResponseHandler ResponseHandler) ResponseHandler
- func HandleResponseEntries(entries interface{}) ResponseHandler
- func HandleResponseEntry(entry interface{}) ResponseHandler
- func HandleResponseJSON(i interface{}) ResponseHandler
- func HandleResponseJSONMessagesCustomError(code ErrorCode) ResponseHandler
- func HandleResponseJSONMessagesError() ResponseHandler
- func HandleResponseRequireCode(code int, errorResponseHandler ResponseHandler) ResponseHandler
- func HandleResponseXML(i interface{}) ResponseHandler
- func HandleResponseXMLMessagesCustomError(code ErrorCode) ResponseHandler
- func HandleResponseXMLMessagesError() ResponseHandler
- type Sharing
- type Titler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ACL ¶
type ACL struct { Permissions Permissions `json:"perms" values:"perms"` Owner attributes.Explicit[string] `json:"owner" values:"owner,omitzero"` Sharing Sharing `json:"sharing" values:"sharing,omitzero"` }
ACL represents the ACL of a Splunk object.
type Authenticator ¶
Authenticators are capable of adding authentication to requests.
type Client ¶
type Client struct { // URL is the URL to the Splunk REST API. It should include the scheme and port number. // // Example: // https://localhost:8089 URL string // Authenticator defines which authentication method and credentials to use. // // Example: // authenticators.Password{Username: "admin", Password: "changeme"} Authenticator // Set TLSInsecureSkipVerify to true to skip TLS verification. TLSInsecureSkipVerify bool // Timeout configures the timeout of requests. If unspecified, defaults to 5 minutes. Timeout time.Duration // contains filtered or unexported fields }
Client defines connectivity and authentication to a Splunk REST API.
Example (PasswordAuth) ¶
package main import ( "github.com/splunk/go-splunk-client/pkg/authenticators" "github.com/splunk/go-splunk-client/pkg/client" ) func main() { _ = client.Client{ URL: "https://splunk.example.com:8089", Authenticator: &authenticators.Password{ Username: "admin", Password: "changeme", }, } }
Output:
Example (SessionKeyAuth) ¶
package main import ( "github.com/splunk/go-splunk-client/pkg/authenticators" "github.com/splunk/go-splunk-client/pkg/client" ) func main() { _ = client.Client{ URL: "https://splunk.example.com:8089", Authenticator: &authenticators.SessionKey{ SessionKey: "my_session_key", }, TLSInsecureSkipVerify: false, } }
Output:
func (*Client) ListNamespace ¶
ListNamespace populates entries in place for a Namespace.
func (*Client) Read ¶
Read performs a Read action for the given Entry. It modifies entry in-place, so entry must be a pointer.
func (*Client) ReadACL ¶
ReadACL performs a ReadACL action for the given Entry. It modifies acl in-place, so acl must be a pointer.
func (*Client) RequestAndHandle ¶
func (c *Client) RequestAndHandle(builder RequestBuilder, handler ResponseHandler) error
RequestAndHandle creates a new http.Request from the given RequestBuilder, performs the request, and handles the http.Response with the given ResponseHandler.
func (*Client) ServiceURL ¶
ServiceURL returns a url.URL for a Service, relative to the Client's URL.
type ConfID ¶
ConfID represents the ID of configs/conf-<file> resources.
func (ConfID) GetEntryPath ¶
GetEntryPath implements custom GetEntryPath encoding.
func (ConfID) GetServicePath ¶
GetServicePath implements custom GetServicePath encoding.
func (ConfID) SetURLValues ¶
SetURLValues implements custom url.Query encoding of ConfID. It adds a field "name" for the ConfID's Stanza. If the Title value is empty, it returns an error, as there are no scenarios where a ConfID object is expected to be POSTed with an empty Stanza.
func (*ConfID) UnmarshalJSON ¶
UnmarshalJSON implements custom JSON unmarshaling for ConfID.
type Error ¶
Error represents an encountered error. It adheres to the "error" interface, so will be returned as a standard error.
Returned errors can be handled as this Error type:
if err := c.RequestAndHandle(...); err != nil { if clientErr, ok := err.(client.Error) { // check clientErr.Code to determine appropriate action } }
type ErrorCode ¶
type ErrorCode int
ErrorCode identifies the type of error that was encountered.
const ( // ErrorUndefined is the zero-value, indicating that the error type // has not been defined. ErrorUndefined ErrorCode = iota // ErrorNamespace indicates an error with the Namespace. ErrorNamespace // ErrorEndpoint indicates an error with the Endpoint configuration. ErrorEndpoint // ErrorValues indicates an error was encountered while trying to encode // to url.Values. ErrorValues // ErrorNilValue indicates an attempt to perform an action against a nil value, // such as attempting to set RawQuery on http.Request with a nil URL. ErrorNilValue // ErrorOverwriteValue indicates an attempt to overwrite an existing value, // such as attempting to set RawQuery multiple times on a URL. ErrorOverwriteValue // ErrorMissingTitle indicates an operation that required a non-empty Title was // attempted with an empty Title. ErrorMissingTitle // ErrorMissingURL indicates the Client's URL value is missing. ErrorMissingURL // ErrorHTTPClient indicates an error related to the http.Client was encountered. ErrorHTTPClient // ErrorResponseBody indicates an error encountered while trying to parse the Body // from an http.Response. ErrorResponseBody // ErrorSplunkMessage indicates the Splunk REST API returned an error message. ErrorSplunkMessage ErrorUnauthorized // ErrorNotFound indicates an attempt was made against an object that count not be found. ErrorNotFound // ErrorPtr indicates an operation requiring a pointer was passed a non-pointer. ErrorPtr // ErrorSlice indicates an operation requiring a slice was passed a non-slice, or a slice // of the wrong type. ErrorSlice // ErrorID indicates an error was encountered related to an object's ID. ErrorID // ErrorSharing indicates an error was encountered related to a Sharing value. ErrorSharing )
type ID ¶
type ID struct { Namespace Namespace // Title is the ID's title component. It is the name of the Splunk object. Title string // contains filtered or unexported fields }
ID represents a Splunk object ID URL for a specific object.
func (ID) GetEntryPath ¶
GetEntryPath implements custom GetEntryPath encoding. It returns the url-encoded value of the ID's Title with the service path preceding it.
func (ID) GetServicePath ¶
GetServicePath implements custom GetServicePath encoding. It returns its Namespace's service path.
func (ID) SetURLValues ¶
SetURLValues implements custom url.Query encoding of ID. It adds a field "name" for the ID's Title. If the Title value is empty, it returns an error, as there are no scenarios where an ID object is expected to be POSTed with an empty Title.
func (ID) URL ¶
URL returns the URL for ID. An error is returned if URL() is run on ID that has no set URL, or if the stored URL doesn't match the ID's fields.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON implements custom JSON unmarshaling for IDFields.
type Namespace ¶
Namespace is a Splunk object's namespace, consisting of a User and App. It is valid only if both User and App are set, or both are unset.
type Permissions ¶
type Permissions struct { Read []string `json:"read" values:"read,omitzero,fillempty"` Write []string `json:"write" values:"write,omitzero,fillempty"` }
Permissions represents the read/write permissions of a Splunk object.
type RequestBuilder ¶
RequestBuilder defines a function that performs an operation on an http.Request.
func BuildRequestAuthenticate ¶
func BuildRequestAuthenticate(c *Client) RequestBuilder
BuildRequestAuthenticate returns a RequestBuilder that authenticates a request for a given Client.
func BuildRequestBodyValues ¶
func BuildRequestBodyValues(i interface{}) RequestBuilder
BuildRequestBodyValues returns a RequestBuilder that sets the Body to the encoded url.Values for a given interface.
func BuildRequestBodyValuesSelective ¶
func BuildRequestBodyValuesSelective(c interface{}, tag string) RequestBuilder
BuildRequestBodyValuesSelective returns a RequestBuilder that sets the Body to the encoded url.Values for a given interface and selective tag.
func BuildRequestEntryACLURL ¶
func BuildRequestEntryACLURL(c *Client, entry interface{}, acl ACL) RequestBuilder
BuildRequestEntryACLURL returns a RequestBuilder that sets the URL to the ACL URL for a given Entry.
func BuildRequestEntryURL ¶
func BuildRequestEntryURL(c *Client, entry interface{}) RequestBuilder
BuildRequestCollectionURL returns a RequestBuilder that sets the URL to the EntryURL for a given Entry.
func BuildRequestGetServiceStatusCodes ¶
func BuildRequestGetServiceStatusCodes(entry interface{}, codes *service.StatusCodes) RequestBuilder
BuildRequestGetServiceStatusCodes updates codes for the given entry. It returns a RequestBuilder that returns the error (if any) returned by service.ServiceStatusCodes.
func BuildRequestMethod ¶
func BuildRequestMethod(method string) RequestBuilder
BuildRequestMethod returns a RequestBuilder that sets the given method.
func BuildRequestOutputModeJSON ¶
func BuildRequestOutputModeJSON() RequestBuilder
BuildRequestOutputModeJSON returns a RequestBuilder that sets the URL's RawQuery to output_mode=json. It checks that the URL is already set, so it must be applied after setting the URL. It overwrites any existing RawQuery Values.
func BuildRequestServiceURL ¶
func BuildRequestServiceURL(c *Client, service interface{}) RequestBuilder
BuildRequestServiceURL returns a RequestBuilder that sets the URL to the ServiceURL for a given Service.
func ComposeRequestBuilder ¶
func ComposeRequestBuilder(builders ...RequestBuilder) RequestBuilder
ComposeRequestBuilder creates a new RequestBuilder that performs each RequestBuilder provided as an argument, returning the first error encountered, if any.
type ResponseHandler ¶
ResponseHandler defines a function that performs an action on an http.Response.
func ComposeResponseHandler ¶
func ComposeResponseHandler(handlers ...ResponseHandler) ResponseHandler
ComposeResponseHandler creates a new ResponseHandler that runs each ResponseHandler provided as an argument.
func HandleResponseCode ¶
func HandleResponseCode(code int, errorResponseHandler ResponseHandler) ResponseHandler
HandleResponseCode returns a ResponseHandler that calls errorResponseHandler if an http.Response's StatusCode is equal to the provided code.
func HandleResponseEntries ¶
func HandleResponseEntries(entries interface{}) ResponseHandler
HandleResponseEntries returns a ResponseHandler that parses the http.Response Body into the list of Entry reference provided.
func HandleResponseEntry ¶
func HandleResponseEntry(entry interface{}) ResponseHandler
HandleResponseEntry returns a responseHaResponseHandlerndler that parses the http.Response Body into the given Entry.
func HandleResponseJSON ¶
func HandleResponseJSON(i interface{}) ResponseHandler
HandleResponseJSON returns a ResponseHandler that decodes an http.Response's Body as JSON to the given interface.
func HandleResponseJSONMessagesCustomError ¶
func HandleResponseJSONMessagesCustomError(code ErrorCode) ResponseHandler
HandleResponseJSONMessagesCustomError returns a ResponseHandler that decodes an http.Response's Body as JSON document of Messages and returns the Messages as an error with the given ErrorCode.
func HandleResponseJSONMessagesError ¶
func HandleResponseJSONMessagesError() ResponseHandler
HandleResponseJSONMessagesError returns a ResponseHandler that decode's an http.Response's Body as a JSON document of Messages and returns the Messages as an error with the Code ErrorSplunkMessage.
func HandleResponseRequireCode ¶
func HandleResponseRequireCode(code int, errorResponseHandler ResponseHandler) ResponseHandler
HandleResponseRequireCode returns a ResponseHandler that checks for a given StatusCode. If the http.Response has a different StatusCode, the provided ResponseHandler will be called to return the appopriate error message.
func HandleResponseXML ¶
func HandleResponseXML(i interface{}) ResponseHandler
HandleResponseXML returns a ResponseHandler that decodes an http.Response's Body as XML to the given interface.
func HandleResponseXMLMessagesCustomError ¶
func HandleResponseXMLMessagesCustomError(code ErrorCode) ResponseHandler
HandleResponseXMLMessagesCustomError returns a ResponseHandler that decode's an http.Response's Body as an XML document of Messages and returns the Messages as an error with the given ErrorCode.
func HandleResponseXMLMessagesError ¶
func HandleResponseXMLMessagesError() ResponseHandler
HandleResponseXMLMessagesError returns a ResponseHandler that decodes an http.Response's Body as an XML document of Messages and returns the Messages as an error.
type Sharing ¶
type Sharing string
Sharing represents the level of sharing of a Splunk object.
func (Sharing) MarshalJSON ¶
MarshalJSON implements custom marshaling.