otxapi

package
v0.0.0-...-ac284b7 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

func Stringify

func Stringify(message interface{}) string

Stringify attempts to create a reasonable string representation of types in the GitHub library. It does things like resolve pointers to their values and omits struct fields with nil values.

Types

type Client

type Client struct {

	// Base URL for API requests.  Defaults to the otx.alienvault.com:443.
	// BaseURL should always be specified with a trailing slash
	BaseURL *url.URL

	UserAgent string

	// OTX API Services
	UserDetail  *OTXUserDetailService
	PulseDetail *OTXPulseDetailService
	ThreatIntel *OTXThreatIntelFeedService
	// contains filtered or unexported fields
}

A Client manages communication with the OTX API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new OTX API client. If a nil httpClient is provided, http.DefaultClient will be used.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type Error

type Error struct {
	Message string
}

func (*Error) Error

func (e *Error) Error() string

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Message  string         `json:"detail"` // error message
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ListOptions

type ListOptions struct {
	// For paginated result sets, page of results to retrieve.
	Page int `url:"page,omitempty"`

	// For paginated result sets, the number of results to include per page.
	PerPage int `url:"limit,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination. our list options: ?limit=50&page_num=1

type OTXPulseDetailService

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

func (*OTXPulseDetailService) Get

func (c *OTXPulseDetailService) Get(id_string string) (PulseDetail, Response, error)

type OTXThreatIntelFeedService

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

func (*OTXThreatIntelFeedService) List

type OTXUserDetailService

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

func (*OTXUserDetailService) Get

type PulseDetail

type PulseDetail struct {
	ID          *string  `json:"id"`
	Author      *string  `json:"author_name"`
	Name        *string  `json:"name"`
	Description *string  `json:"description,omitempty"`
	CreatedAt   *string  `json:"created,omitempty"`
	ModifiedAt  *string  `json:"modified"`
	References  []string `json:"references,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Indicators  []struct {
		ID          *string `json:"_id"`
		Indicator   *string `json:"indicator"`
		Type        *string `json:"type"`
		Description *string `json:"description,omitempty"`
	} `json:"indicators,omitempty"`
	Revision *float32 `json:"revision,omitempty"`
}

Pulse represents an OTX Pulse

func (PulseDetail) String

func (r PulseDetail) String() string

type Response

type Response struct {
	*http.Response
	// RawContent - raw stream
	RawContent []uint8
	// Content - additional way to access the content body of the response.
	Content map[string]interface{} `json:"results,omitempty"`
}

Response is a otx API response. This wraps the standard http.Response returned from OTX and provides convenient access to things like pagination links.

type ThreatIntelFeed

type ThreatIntelFeed struct {
	Pulses []PulseDetail `json:"results"`
	// These fields provide the page values for paginating through a set of
	// results.  Any or all of these may be set to the zero value for
	// responses that are not part of a paginated set, or for which there
	// are no additional pages.
	//NextPageNum  int   Coming soon
	//PrevPageNum  int   Coming soon
	NextPageString *string `json:"next"`
	PrevPageString *string `json:"prev"`
	Count          int     `json:"count"`
}

func (ThreatIntelFeed) String

func (r ThreatIntelFeed) String() string

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. This is necessary for some fields since the GitHub API is inconsistent in how it represents times. All exported methods of time.Time can be called on Timestamp.

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

type UserDetail

type UserDetail struct {
	AwardCount      *int    `json:"award_count"`
	FollowerCount   *int    `json:"follower_count"`
	SubscriberCount *int    `json:"subscriber_count"`
	IndicatorCount  *int    `json:"indicator_count"`
	PulseCount      *int    `json:"pulse_count"`
	MemberSince     *string `json:"member_since"`
	UserId          *int    `json:"user_id"`
	Username        *string `json:"username"`
}

func (UserDetail) String

func (r UserDetail) String() string

Jump to

Keyboard shortcuts

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