tenable

package module
v0.0.0-...-f0c1290 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

go-tenable

Go client library for Tenable.io.

Features

  • Authentication (API Key)
  • Retrieve Repositories, Analysis.

Requirements

  • Go >= 1.18
  • Tenable ??

Installation

It is go gettable

go get github.com/IBM/go-tenable

Usage:

package main

import (
	tenable "github.com/IBM/go-tenable"
)
...

(optional) to run unit / example tests:

cd $GOPATH/src/github.com/IBM/go-tenable
go test -v ./...

API

Please have a look at the GoDoc documentation for a detailed API description.

The latest Tenable REST API documentation was the base document for this package.

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. The caller is responsible to analyze the response body. The body can contain JSON (if the error is intended) or xml (sometimes Tenable just failes).

func NewTenableError

func NewTenableError(resp *Response, httpError error) error

NewTenableError creates a new Tenable Error

Types

type APIKeyAuthTransport

type APIKeyAuthTransport struct {
	APIKey    string
	APISecret string

	// Transport is the underlying HTTP transport to use when making requests.
	// It will default to http.DefaultTransport if nil.
	Transport http.RoundTripper
}

APIKeyAuthTransport is an http.RoundTripper that authenticates all requests using HTTP APIKey Authentication with the provided username and password.

func (*APIKeyAuthTransport) Client

func (t *APIKeyAuthTransport) Client() *http.Client

Client returns an *http.Client that makes requests that are authenticated using HTTP APIKey Authentication. This is a nice little bit of sugar so we can just get the client instead of creating the client in the calling code. If it's necessary to send more information on client init, the calling code can always skip this and set the transport itself.

func (*APIKeyAuthTransport) RoundTrip

func (t *APIKeyAuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface. We just add the APIKey auth and return the RoundTripper for this transport type.

type Analysis

type Analysis struct {
	PluginID       string      `json:"pluginID"`
	Severity       Severity    `json:"severity,omitempty"`
	VPRScore       string      `json:"vprScore,omitempty"`
	VPRContext     interface{} `json:"vprContext,omitempty"`
	IP             string      `json:"ip,omitempty"`
	UUID           string      `json:"uuid,omitempty"`
	Port           string      `json:"port,omitempty"`
	Protocol       string      `json:"protocol,omitempty"`
	Name           string      `json:"name,omitempty"`
	DNSName        string      `json:"dnsName,omitempty"`
	MACAddress     string      `json:"macAddress,omitempty"`
	NetBiosName    string      `json:"netBiosName,omitempty"`
	Uniqueness     string      `json:"uniqueness,omitempty"`
	HostUniqueness string      `json:"hostUniqueness,omitempty"`
	Family         Family      `json:"family,omitempty"`
	Repository     Repository  `json:"repository,omitempty"`
	PluginInfo     string      `json:"pluginInfo,omitempty"`
}

type AnalysisBody

type AnalysisBody struct {
	Query      AnalysisQuery `json:"query"`
	SourceType string        `json:"sourceType"`
	Columns    interface{}   `json:"columns"`
	Type       string        `json:"type"`
}

type AnalysisFilter

type AnalysisFilter struct {
	ID           string      `json:"id"`
	FilterName   string      `json:"filterName"`
	Operator     string      `json:"operator"`
	Type         string      `json:"type"`
	IsPredefined bool        `json:"isPredefined"`
	Value        interface{} `json:"value"`
}

type AnalysisQuery

type AnalysisQuery struct {
	Name         string   `json:"name"`
	Description  string   `json:"description"`
	Context      string   `json:"context"`
	Status       int64    `json:"status"`
	CreatedTime  int64    `json:"createdTime"`
	ModifiedTime int64    `json:"modifiedTime"`
	Groups       []string `json:"groups"`
	Type         string   `json:"type"`
	Tool         string   `json:"tool"`
	SourceType   string   `json:"sourceType"`
	StartOffset  int64    `json:"startOffset"`
	EndOffset    int64    `json:"endOffset"`

	Filters  []AnalysisFilter `json:"filters"`
	VulnTool string           `json:"vulnTool"`
}

type AnalysisResponse

type AnalysisResponse struct {
	Type      string            `json:",type,omitempty"`
	Response  AnalysisResultSet `json:"response,omitempty"`
	ErrorCode int               `json:"error_code,omitempty"`
	ErrorMsg  string            `json:"error_msg,omitempty"`
	Warnings  []string          `json:"warnings,omitempty"`
	Timestamp int               `json:"timestamp,omitempty"`
}

Analysis represents a Tenable user.

type AnalysisResultSet

type AnalysisResultSet struct {
	TotalRecords             string     `json:"totalRecords,omitempty"`
	ReturnedRecords          int64      `json:"returnedRecords,omitempty"`
	StartOffset              string     `json:"startOffset,omitempty"`
	EndOffset                string     `json:"endOffset,omitempty"`
	MatchingDataElementCount string     `json:"MatchingDataElementCount,omitempty"`
	Results                  []Analysis `json:"results,omitempty"`
}

type AnalysisService

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

AnalysisService handles users for the Tenable instance / API.

Tenable API docs: https://docs.tenable.com/tenablesc/api/Analysis.htm

func (*AnalysisService) Post

func (s *AnalysisService) Post(body interface{}) (*AnalysisResponse, *Response, error)

Get wraps PostWithContext using the background context.

func (*AnalysisService) PostWithContext

func (s *AnalysisService) PostWithContext(ctx context.Context, body interface{}) (*AnalysisResponse, *Response, error)

PostWithContext gets user info from Tenable using its Account Id

Tenable API docs: https://docs.tenable.com/tenablesc/api/Analysis.htm

type AuthenticationService

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

AuthenticationService handles users for the Tenable instance / API.

Tenable API docs: https://docs.tenable.com/tenablesc/api/index.htm

func (*AuthenticationService) Authenticated

func (s *AuthenticationService) Authenticated() bool

Authenticated reports if the current Client has authentication details for Jira

func (*AuthenticationService) SetAPIKeyAuth deprecated

func (s *AuthenticationService) SetAPIKeyAuth(api_key, api_secret string)

SetAPIKeyAuth sets api_key and api_secret for the APIKey auth against the Jira instance.

Deprecated: Use APIKeyAuthTransport instead

type Client

type Client struct {

	// Services used for talking to different parts of the Tenable API.
	Analysis       *AnalysisService
	Authentication *AuthenticationService
	CurrentUser    *CurrentUserService
	Repository     *RepositoryService
	// contains filtered or unexported fields
}

A Client manages communication with the Tenable API.

func NewClient

func NewClient(httpClient httpClient, baseURL string) (*Client, error)

NewClient returns a new Tenable API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication you can follow the preferred solution and provide an http.Client that will perform the authentication for you with OAuth and HTTP Basic (such as that provided by the golang.org/x/oauth2 library). As an alternative you can use Session Cookie based authentication provided by this package as well. See https://docs.tenable.com/tenablesc/api_best_practices/Content/ScApiBestPractices/APIKeyAuthorization.htm baseURL is the HTTP endpoint of your Tenable instance and should always be specified with a trailing slash.

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.

func (*Client) NewRawRequest

func (c *Client) NewRawRequest(method, urlStr string, body io.Reader) (*http.Request, error)

NewRawRequest wraps NewRawRequestWithContext using the background context.

func (*Client) NewRawRequestWithContext

func (c *Client) NewRawRequestWithContext(ctx context.Context, method, urlStr string, body io.Reader) (*http.Request, error)

NewRawRequestWithContext 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. Allows using an optional native io.Reader for sourcing the request body.

func (*Client) NewRequest

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

NewRequest wraps NewRequestWithContext using the background context.

func (*Client) NewRequestWithContext

func (c *Client) NewRequestWithContext(ctx context.Context, method, urlStr string, body interface{}) (*http.Request, error)

NewRequestWithContext 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. If specified, the value pointed to by body is JSON encoded and included as the request body.

type CurrentUser

type CurrentUser struct {
	User
}

CurrentUserResponse represents a Tenable user response

type CurrentUserResponse

type CurrentUserResponse struct {
	// "type": "regular",
	Type string
	// "response": {
	Response CurrentUser `json:"response"`
	// "error_code": 0,
	ErrorCode int `json:"error_code"`
	// "error_msg": "",
	ErrorMsg string `json:"error_msg"`
	// "warnings": [],
	Warnings []string
	// "timestamp": 1657818772
	Timestamp int
}

CurrentUser represents a Tenable user.

type CurrentUserService

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

CurrentUserService handles users for the Tenable instance / API.

Tenable API docs: https://docs.tenable.com/tenablesc/api/CurrentUser.htm

func (*CurrentUserService) Get

Get wraps GetWithContext using the background context.

func (*CurrentUserService) GetWithContext

func (s *CurrentUserService) GetWithContext(ctx context.Context) (*CurrentUser, *Response, error)

GetWithContext gets user info from Tenable using its Account Id

Tenable API docs: https://docs.tenable.com/tenablesc/api/CurrentUser.md

type Error

type Error struct {
	HTTPError     error
	ErrorMessages []string          `json:"errorMessages"`
	Errors        map[string]string `json:"errors"`
}

Error message from Tenable

func (*Error) Error

func (e *Error) Error() string

Error is a short string representing the error

type Family

type Family struct {
	ID   interface{} `json:"id,omitempty"`
	Name string      `json:"name,omitempty"`
	Type string      `json:"type,omitempty"`
}

type Organization

type Organization struct {
	ID          interface{}
	Name        string
	Description string
}

type PreferenceItem

type PreferenceItem struct {
	Name  string
	Value string
	Tag   string
}

type Repository

type Repository struct {
	ID          interface{} `json:"id"`
	Name        string      `json:"name,omitempty"`
	Description string      `json:"description,omitempty"`
	DataFormat  string      `json:"dataFormat,omitempty"`
	UUID        string      `json:"uuid,omitempty"`
}

type RepositoryResponse

type RepositoryResponse struct {
	// "type": "regular",
	Type string
	// "response": {
	Response []Repository `json:"response"`
	// "error_code": 0,
	ErrorCode int `json:"error_code"`
	// "error_msg": "",
	ErrorMsg string `json:"error_msg"`
	// "warnings": [],
	Warnings []string
	// "timestamp": 1657818772
	Timestamp int
}

Repository represents a Tenable user.

type RepositoryService

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

RepositoryService handles users for the Tenable instance / API.

Tenable API docs: https://docs.tenable.com/tenablesc/api/Repository.htm

func (*RepositoryService) Get

func (s *RepositoryService) Get(requestType, fields string) ([]Repository, *Response, error)

Get wraps GetWithContext using the background context.

func (*RepositoryService) GetWithContext

func (s *RepositoryService) GetWithContext(ctx context.Context, requestType, fields string) ([]Repository, *Response, error)

GetWithContext gets user info from Tenable using its Account Id

Tenable API docs: https://docs.tenable.com/tenablesc/api/Repository.htm

type Response

type Response struct {
	*http.Response

	StartAt    int
	MaxResults int
	Total      int
}

Response represents Tenable API response. It wraps http.Response returned from API and provides information about paging.

type Role

type Role struct {
	ID          interface{}
	Name        string
	Description string
}

type Severity

type Severity struct {
	ID          interface{} `json:"id,omitempty"`
	Name        string      `json:"name,omitempty"`
	Description string      `json:"description,omitempty"`
}

type User

type User struct {
	ID                 interface{} `json:"id"`
	Status             string      `json:"status,omitempty"`             // "0",
	Username           string      `json:"username,omitempty"`           // "admin",
	LDAPUsername       string      `json:"ldapUsername,omitempty"`       // "",
	Firstname          string      `json:"firstname,omitempty"`          // "Admin",
	Lastname           string      `json:"lastname,omitempty"`           // "User",
	Title              string      `json:"title,omitempty"`              // "Application Administrator",
	Email              string      `json:"email,omitempty"`              // "",
	Address            string      `json:"address,omitempty"`            // "",
	City               string      `json:"city,omitempty"`               // "",
	State              string      `json:"state,omitempty"`              // "",
	Country            string      `json:"country,omitempty"`            // "",
	Phone              string      `json:"phone,omitempty"`              // "",
	Fax                string      `json:"fax,omitempty"`                // "",
	CreatedTime        string      `json:"createdTime,omitempty"`        // "1432921843",
	ModifiedTime       string      `json:"modifiedTime,omitempty"`       // "1453473716",
	LastLogin          string      `json:"lastLogin,omitempty"`          // "1454350174",
	LastLoginIP        string      `json:"lastLoginIP,omitempty"`        // "172.20.0.0",
	MustChangePassword string      `json:"mustChangePassword,omitempty"` // "false",
	Locked             string      `json:"locked,omitempty"`             // "false",
	FailedLogin        string      `json:"failedLogins,omitempty"`       // "0",
	AuthType           string      `json:"authType,omitempty"`           // "tns",
	Fingerprint        string      `json:"fingerprint,omitempty"`        // null,
	Password           string      `json:"password,omitempty"`           // "SET",
	Preferences        []PreferenceItem
	Organization       Organization
	OrgName            string `json:"orgName,omitempty"`
	UserPrefs          []UserPrefItem
	UUID               string `json:"uuid,omitempty"`
}

type UserPrefItem

type UserPrefItem struct {
	Name  string
	Value string
	Tag   string
}

type VPRContext

type VPRContext struct {
	ID    interface{} `json:"id,omitempty"`
	Name  string      `json:"name,omitempty"`
	Value string      `json:"value,omitempty"`
	Type  string      `json:"type,omitempty"`
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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