client

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package client contains the GreyNoise API client.

Package client is a generated GoMock package.

Index

Constants

View Source
const (
	SensorSortByName      = SensorSortBy("name")
	SensorSortByIP        = SensorSortBy("public_ips")
	SensorSortByPort      = SensorSortBy("access_port")
	SensorSortByPersona   = SensorSortBy("persona_name")
	SensorSortByCreatedAt = SensorSortBy("created_at")
	SensorSortByStatus    = SensorSortBy("status")

	MetadataAccessReadWrite = MetadataAccess("readwrite") // User readable and modifiable
	MetadataAccessReadonly  = MetadataAccess("readonly")  // User readable, not modifiable
	MetadataAccessHidden    = MetadataAccess("hidden")
)
View Source
const (
	HeaderKey = "key"
)

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Account

type Account struct {
	UserID      uuid.UUID `json:"user_id"`
	WorkspaceID uuid.UUID `json:"workspace_id"`
}

type ErrInvalidField

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

ErrInvalidField is an error type that is returned when a field is invalid.

func NewErrInvalidField

func NewErrInvalidField(field, reason string) *ErrInvalidField

func (*ErrInvalidField) Error

func (e *ErrInvalidField) Error() string

type ErrMissingField

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

ErrMissingField is an error type that is returned when a required field is missing.

func NewErrMissingField

func NewErrMissingField(field string) *ErrMissingField

func (*ErrMissingField) Error

func (e *ErrMissingField) Error() string

type ErrUnexpectedStatusCode

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

ErrUnexpectedStatusCode is an error type that is returned when a status code does not match an expected one.

func NewErrUnexpectedStatusCode

func NewErrUnexpectedStatusCode(expected, actual int) *ErrUnexpectedStatusCode

func (*ErrUnexpectedStatusCode) Error

func (e *ErrUnexpectedStatusCode) Error() string

func (*ErrUnexpectedStatusCode) StatusCode

func (e *ErrUnexpectedStatusCode) StatusCode() int

type GreyNoiseClient

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

GreyNoiseClient is a thin wrapper for a HTTP client.

func New

func New(apiKey string, options ...Option) (*GreyNoiseClient, error)

New is the preferred way to instantiate the GreyNoiseClient.

func (*GreyNoiseClient) GetPersona

func (c *GreyNoiseClient) GetPersona(ctx context.Context, id string) (*Persona, error)

func (*GreyNoiseClient) GetSensor

func (c *GreyNoiseClient) GetSensor(ctx context.Context, id string) (*Sensor, error)

func (*GreyNoiseClient) PersonasSearch

func (c *GreyNoiseClient) PersonasSearch(ctx context.Context, filters PersonaSearchFilters) (*PersonaSearchResponse, error)

func (*GreyNoiseClient) SensorBootstrapURL

func (c *GreyNoiseClient) SensorBootstrapURL() *url.URL

func (*GreyNoiseClient) SensorUnBootstrapURL added in v0.3.0

func (c *GreyNoiseClient) SensorUnBootstrapURL() *url.URL

func (*GreyNoiseClient) SensorsSearch

func (c *GreyNoiseClient) SensorsSearch(ctx context.Context, filters SensorSearchFilter) (*SensorSearchResponse, error)

func (*GreyNoiseClient) SensorsURL added in v0.3.0

func (c *GreyNoiseClient) SensorsURL() *url.URL

func (*GreyNoiseClient) UpdateSensor added in v0.5.0

func (c *GreyNoiseClient) UpdateSensor(ctx context.Context, id string, request SensorUpdateRequest) error

func (*GreyNoiseClient) UserID

func (c *GreyNoiseClient) UserID() uuid.UUID

func (*GreyNoiseClient) WorkspaceID

func (c *GreyNoiseClient) WorkspaceID() uuid.UUID

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type MetadataAccess added in v0.5.0

type MetadataAccess string

type MockHTTPClient

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

MockHTTPClient is a mock of HTTPClient interface.

func NewMockHTTPClient

func NewMockHTTPClient(ctrl *gomock.Controller) *MockHTTPClient

NewMockHTTPClient creates a new mock instance.

func (*MockHTTPClient) Do

func (m *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

Do mocks base method.

func (*MockHTTPClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockHTTPClientMockRecorder

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

MockHTTPClientMockRecorder is the mock recorder for MockHTTPClient.

func (*MockHTTPClientMockRecorder) Do

func (mr *MockHTTPClientMockRecorder) Do(req interface{}) *gomock.Call

Do indicates an expected call of Do.

type Option

type Option func(client *GreyNoiseClient)

Option is used to configure the GreyNoiseClient.

func WithBaseURL

func WithBaseURL(url *url.URL) Option

WithBaseURL is used to set the base URL.

func WithHTTPClient

func WithHTTPClient(httpClient HTTPClient) Option

WithHTTPClient is used to set the internal HTTP client.

type Pagination

type Pagination struct {
	Page       int32 `json:"page"`
	PageSize   int32 `json:"page_size"`
	TotalItems int32 `json:"total_items"`
}

type Persona

type Persona struct {
	ID                        string    `json:"id"`
	CreatedAt                 time.Time `json:"created_at"`
	UpdatedAt                 time.Time `json:"updated_at"`
	Name                      string    `json:"name"`
	Author                    string    `json:"author"`
	ArtifactLink              string    `json:"artifact_link"`
	Tier                      string    `json:"tier"`
	InstanceManagement        string    `json:"instance_management"`
	Workspace                 string    `json:"workspace"`
	Categories                []string  `json:"categories"`
	Description               string    `json:"description"`
	OperatingSystem           string    `json:"operating_system"`
	Icon                      string    `json:"icon"`
	AssociatedVulnerabilities []string  `json:"associated_vulnerabilities"`
}

type PersonaSearchFilters

type PersonaSearchFilters struct {
	Workspace  string `mapstructure:"workspace"`
	Tiers      string `mapstructure:"tiers"`
	Categories string `mapstructure:"categories"`
	Protocols  string `mapstructure:"protocols"`
	Search     string `mapstructure:"search"`
	PageSize   int32  `mapstructure:"page_size"`
}

func (*PersonaSearchFilters) Validate

func (f *PersonaSearchFilters) Validate() error

type PersonaSearchResponse

type PersonaSearchResponse struct {
	Items      []Persona  `json:"items"`
	Pagination Pagination `json:"pagination"`
}

type Sensor

type Sensor struct {
	ID         string         `json:"sensor_id"`
	Name       string         `json:"name"`
	PublicIps  []string       `json:"public_ips"`
	AccessPort int32          `json:"access_port"`
	Persona    string         `json:"persona"`
	Metadata   SensorMetadata `json:"metadata"`
	Status     string         `json:"status"`
	Disabled   bool           `json:"disabled"`
	LastSeen   time.Time      `json:"last_seen"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  time.Time      `json:"updated_at"`
}

type SensorMetadata added in v0.5.0

type SensorMetadata struct {
	Items []SensorMetadatum `json:"items"`
}

type SensorMetadatum added in v0.5.0

type SensorMetadatum struct {
	Access MetadataAccess `json:"access"`
	Name   string         `json:"name"`
	Val    string         `json:"val"`
}

func (*SensorMetadatum) Validate added in v0.5.0

func (s *SensorMetadatum) Validate() error

type SensorSearchFilter

type SensorSearchFilter struct {
	Filter     string       `mapstructure:"filter"`
	Page       int32        `mapstructure:"page"`
	PageSize   int32        `mapstructure:"page_size"`
	SortBy     SensorSortBy `mapstructure:"sort_by"`
	Descending bool         `mapstructure:"descending"`
}

func (*SensorSearchFilter) Validate

func (f *SensorSearchFilter) Validate() error

type SensorSearchResponse

type SensorSearchResponse struct {
	Items      []Sensor   `json:"items"`
	Pagination Pagination `json:"pagination"`
}

type SensorSortBy

type SensorSortBy string

type SensorUpdateRequest added in v0.5.0

type SensorUpdateRequest struct {
	Name     string          `json:"name,omitempty"`
	Persona  string          `json:"persona,omitempty"`
	Metadata *SensorMetadata `json:"metadata,omitempty"`
}

Jump to

Keyboard shortcuts

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