Documentation
¶
Index ¶
- Variables
- func Create[E CreatableEntity](ctx context.Context, client Client, customAttributes string, input AddInput) (map[string]any, error)
- func Decode(input, output any) error
- func DecodeInterface(input GraphQLInterface, output any) error
- func Delete[E DeletableEntity](ctx context.Context, client Client, id string) (string, error)
- func FormatAttributes(attr string, offset int) string
- func List[E ListableEntity](ctx context.Context, client Client, customAttributes string, getAll bool, ...) ([]map[string]any, error)
- func ParseAttributes[Entity any](options ...ParseOption) string
- func Read[E ReadableEntity](ctx context.Context, client Client, customAttributes, id string) (map[string]any, error)
- func StructuredCreate[E CreatableEntity, ReturnStruct any](ctx context.Context, client Client, customAttributes string, input AddInput) (ReturnStruct, error)
- func StructuredList[E ListableEntity, ReturnStruct any](ctx context.Context, client Client, customAttributes string, getAll bool, ...) ([]ReturnStruct, error)
- func StructuredRead[E ReadableEntity, ReturnStruct any](ctx context.Context, client Client, customAttributes, id string) (ReturnStruct, error)
- type AddInput
- type Client
- type CreatableEntity
- type Defaults
- type DeletableEntity
- type EditInput
- type EditOperation
- type File
- type GraphQLInterface
- type InterfaceTypeError
- type ListableEntity
- type MissingFieldError
- type NotImplementingError
- type ParseOption
- type ReadableEntity
- type TypeAssertionError
- type UnimplementedDecodingError
Constants ¶
This section is empty.
Variables ¶
var ErrNotAPointer = errors.New("result must be a pointer")
Functions ¶
func Create ¶
func Create[E CreatableEntity]( ctx context.Context, client Client, customAttributes string, input AddInput, ) (map[string]any, error)
Create will push the chosen CreatableEntity with the attributes given in 'input' to the OpenCTI server. If the entity already exists on the platform, it will be updated instead. It returns a map containing the chosen 'customAttributes' structure, as per GraphQL syntax.
func Decode ¶
Decode wraps mapstructure.Decode, using a custom DecoderConfig: It targets the "gocti" struct tag. It handles special types with a custom DecodeFunc.
func DecodeInterface ¶
func DecodeInterface(input GraphQLInterface, output any) error
DecodeInterface converts a GraphQL Interface type into one of its implementations. It uses the data returned by [GraphQLInterface.Remainder] to complete the fields specific to the implementation.
func Delete ¶
Delete deletes the chosen DeletableEntity with the provided 'id' from the OpenCTI server. It returns the ID of the recently deleted entity.
func FormatAttributes ¶
func List ¶
func List[E ListableEntity]( ctx context.Context, client Client, customAttributes string, getAll bool, pageInfo *graphql.PageInfo, opts ...list.Option, ) ([]map[string]any, error)
List fetches a list of the chosen ListableEntity from the OpenCTI server It returns a slice of maps, each containing the chosen 'customAttributes' structure, as per GraphQL syntax. Pagination information can be retrieved by providing a non-nil pointer to a graphql.PageInfo.
func ParseAttributes ¶
func ParseAttributes[Entity any](options ...ParseOption) string
ParseAttributes parses a struct type to build a GraphQL query segment matching its fields. The provided type must have a structure compatible with the GraphQL schema. Only fields marked with the "gocti" struct tag will be parsed. Field arguments can be added after the name tag (e.g. `gocti:"name,(id: \"0123456789\")"`). They should be added in second position, after the name, and before any decoding-specific tag value, like "remain", "omitempty", or "squash".
WARNING: Using ParseAttributes with large structs pointing to many other structs (typically non-truncated OpenCTI entities) can quickly lead to a very large returned string.
func Read ¶
func Read[E ReadableEntity]( ctx context.Context, client Client, customAttributes, id string, ) (map[string]any, error)
Read retrieves the chosen ReadableEntity with the provided 'id' from the OpenCTI server. It returns a map containing the chosen 'customAttributes' structure, as per GraphQL syntax.
func StructuredCreate ¶
func StructuredCreate[E CreatableEntity, ReturnStruct any]( ctx context.Context, client Client, customAttributes string, input AddInput, ) (ReturnStruct, error)
StructuredCreate is a wrapper around Create that returns the data as a struct instead of a map. The provided ReturnStruct type must have a structure compatible with the GraphQL schema of the target entity. Field name aliases can (and should) be set using the "gocti" tag (e.g. struct{ OpenCTIName string `gocti:"name"` }). WARNING: Golang default values will be returned for fields that are not set or have a 'null' value on the server.
func StructuredList ¶
func StructuredList[E ListableEntity, ReturnStruct any]( ctx context.Context, client Client, customAttributes string, getAll bool, pageInfo *graphql.PageInfo, opts ...list.Option, ) ([]ReturnStruct, error)
StructuredList is a wrapper around List that returns the data as a list of structs instead of a list of maps. The provided ReturnStruct type must have a structure compatible with the GraphQL schema of the target entity. Field name aliases can (and should) be set using the "gocti" tag (e.g. struct{ OpenCTIName string `gocti:"name"` }). WARNING: Golang default values will be returned for fields that are not set or have a 'null' value on the server.
func StructuredRead ¶
func StructuredRead[E ReadableEntity, ReturnStruct any]( ctx context.Context, client Client, customAttributes, id string, ) (ReturnStruct, error)
StructuredRead is a wrapper around Read that returns the data as a struct instead of a map. The provided ReturnStruct type must have a structure compatible with the GraphQL schema of the target entity. Field name aliases can (and should) be set using the "gocti" tag (e.g. struct{ OpenCTIName string `gocti:"name"` }). WARNING: Golang default values will be returned for fields that are not set or have a 'null' value on the server.
Types ¶
type CreatableEntity ¶
type Defaults ¶
type Defaults interface { // DefaultPageSize returns the default pagination size for list queries and an ok expression indicating if the value // has been set (true) or not (false) by the user via env variables or [OpenCTIAPIClient] constructor options. // The zero value is returned if not set. DefaultPageSize() (int, bool) // DefaultOrderBy returns the default field name for ordering list queries and an ok expression indicating if the value // has been set (true) or not (false) by the user via env variables or [OpenCTIAPIClient] constructor options. // The zero value is returned if not set. DefaultOrderBy() (string, bool) // DefaultOrderMode returns the default mode for ordering list queries and an ok expression indicating if the value // has been set (true) or not (false) by the user via env variables or [OpenCTIAPIClient] constructor options. // The zero value is returned if not set. DefaultOrderMode() (string, bool) }
Defaults defines the interface to access various configured default values.
type DeletableEntity ¶
type EditInput ¶
type EditInput struct { Key string `json:"key,omitempty"` ObjectPath string `json:"object_path,omitempty"` Value any `json:"value,omitempty"` Operation EditOperation `json:"operation,omitempty"` }
type EditOperation ¶
type EditOperation string
const ( EditOperationAdd EditOperation = "add" EditOperationReplace EditOperation = "replace" EditOperationRemove EditOperation = "remove" )
type GraphQLInterface ¶
type GraphQLInterface interface { // The [Implementations] method should return all types that implement this GraphQL interface. Implementations() []reflect.Type // The [Remainder] method should return the additional data to be stored in an implementation's // specific fields. In GraphQL, Interfaces (and Unions) have less fields than their // implementations. The additional data can be saved separately when decoding a GraphQL // response into a Golang struct by adding a extra field using the tag `gocti:",remain"` // The [Remainder] method allows [DecodeInterface] to retrieve this extra data for conversion. Remainder() map[string]any }
GraphQLInterface is a type that represents a GraphQL Interface or Union.
type InterfaceTypeError ¶
InterfaceTypeError is returned when a provided type for a generic function does not match the expected kind.
func (InterfaceTypeError) Error ¶
func (err InterfaceTypeError) Error() string
type ListableEntity ¶
type MissingFieldError ¶
type MissingFieldError struct {
FieldName string
}
MissingFieldError is returned when a required field in a map is not found.
func (MissingFieldError) Error ¶
func (err MissingFieldError) Error() string
type NotImplementingError ¶
NotImplementingError is returned when decoding a GraphQL interface into a type that does not implement it.
func (NotImplementingError) Error ¶
func (e NotImplementingError) Error() string
type ParseOption ¶
type ParseOption func(p *attributeParser)
func WithComments ¶
func WithComments(comments bool) ParseOption
WithComments sets whether the parser should signal ignored recursion loops or exceeded maximum depth fields with a comment.
func WithMaxDepth ¶
func WithMaxDepth(maxDepth int) ParseOption
WithMaxDepth sets the maximum depth at which the parser stops recursively exploring struct fields.
type ReadableEntity ¶
type TypeAssertionError ¶
TypeAssertionError is returned when a required type assertion fails.
func (TypeAssertionError) Error ¶
func (err TypeAssertionError) Error() string
type UnimplementedDecodingError ¶
type UnimplementedDecodingError struct {
// contains filtered or unexported fields
}
UnimplementedDecodingError is returned when a decoding hook 'fromType -> toType' is missing.
func (UnimplementedDecodingError) Error ¶
func (e UnimplementedDecodingError) Error() string