client

package
v0.0.0-...-c937b9e Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2015 License: MIT Imports: 23 Imported by: 10

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 FromId

func FromId(id bson.ObjectId) string

convert ObjectId to string

func IsConflicted

func IsConflicted(err error) bool

return true if http status code is 409 (Status conflict)

func IsNotFound

func IsNotFound(err error) bool

return true if http status code is 404 (Status not found)

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.

func ToId

func ToId(id string) bson.ObjectId

convert string id to ObjectId

Types

type AgentsListOpts

type AgentsListOpts struct {
	Name string     `url:"name"`
	Type agent.Type `url:"type"`
}

type AgentsService

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

func (*AgentsService) Create

func (s *AgentsService) Create(ctx context.Context, src *agent.Agent) (*agent.Agent, error)

func (*AgentsService) Get

func (s *AgentsService) Get(ctx context.Context, id string) (*agent.Agent, error)

func (*AgentsService) GetJobs

func (s *AgentsService) GetJobs(ctx context.Context, src *agent.Agent) ([]*agent.Job, error)

func (*AgentsService) List

List agents.

func (*AgentsService) String

func (s *AgentsService) String() string

func (*AgentsService) Update

func (s *AgentsService) Update(ctx context.Context, src *agent.Agent) (*agent.Agent, error)

type Client

type Client struct {

	// Base URL for API requests. BaseURL should
	// always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating with the Bearded API.
	UserAgent string

	// Token sent in header to authenticate
	Token string

	// Show different debug information
	Debug bool

	// Services used for talking to different parts of the Bearded API.
	Plugins *PluginsService
	Plans   *PlansService
	Agents  *AgentsService
	Scans   *ScansService
	Files   *FilesService
	Tokens  *TokensService
	// contains filtered or unexported fields
}

A Client manages communication with the Bearded API.

func NewClient

func NewClient(baseUrl string, httpClient *http.Client) *Client

NewClient returns a new Bearded API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the goauth2 library).

func (*Client) Create

func (c *Client) Create(ctx context.Context, url string, send interface{}, payload interface{}) error

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, url string, id string) error

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.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) Get

func (c *Client) Get(ctx context.Context, url string, id string, payload interface{}) error

Helper method to get a resource by id

func (*Client) List

func (c *Client) List(ctx context.Context, url string, opts interface{}, payload interface{}) error

Helper method to get a list of payload objects

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.

func (*Client) SetBaseUrl

func (c *Client) SetBaseUrl(u string) error

func (*Client) Update

func (c *Client) Update(ctx context.Context, url string, id string, send interface{}, payload interface{}) error

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, urlStr string, files []*UploadedFile, payload interface{}) error

type ErrorResponse

type ErrorResponse struct {
	Response     *http.Response
	ServiceError *ServiceError
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type FilesListOpts

type FilesListOpts struct {
	Name string `url:"name"`
}

type FilesService

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

func (*FilesService) Create

func (s *FilesService) Create(ctx context.Context, filename string, data io.Reader) (*file.Meta, error)

func (*FilesService) Download

func (s *FilesService) Download(ctx context.Context, id string) (io.Reader, error)

func (*FilesService) String

func (s *FilesService) String() string

type PlansListOpts

type PlansListOpts struct {
	Name string `url:"name"`
}

type PlansService

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

func (*PlansService) Create

func (s *PlansService) Create(ctx context.Context, src *plan.Plan) (*plan.Plan, error)

func (*PlansService) Get

func (s *PlansService) Get(ctx context.Context, id string) (*plan.Plan, error)

func (*PlansService) List

func (s *PlansService) List(ctx context.Context, opt *PlansListOpts) (*plan.PlanList, error)

List plans.

func (*PlansService) String

func (s *PlansService) String() string

func (*PlansService) Update

func (s *PlansService) Update(ctx context.Context, src *plan.Plan) (*plan.Plan, error)

type PluginsListOpts

type PluginsListOpts struct {
	Name    string `url:"name"`
	Version string `url:"version"`
	Type    string `url:"type"`
}

type PluginsService

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

func (*PluginsService) Create

func (s *PluginsService) Create(ctx context.Context, src *plugin.Plugin) (*plugin.Plugin, error)

func (*PluginsService) Get

func (s *PluginsService) Get(ctx context.Context, id string) (*plugin.Plugin, error)

func (*PluginsService) List

List plugins.

func (*PluginsService) String

func (s *PluginsService) String() string

func (*PluginsService) Update

func (s *PluginsService) Update(ctx context.Context, src *plugin.Plugin) (*plugin.Plugin, error)

type ScansListOpts

type ScansListOpts struct {
	Name string `url:"name"`
}

type ScansService

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

func (*ScansService) Get

func (s *ScansService) Get(ctx context.Context, id string) (*scan.Scan, error)

func (*ScansService) List

func (s *ScansService) List(ctx context.Context, opt *ScansListOpts) (*scan.ScanList, error)

List scans.

func (*ScansService) SessionAddChild

func (s *ScansService) SessionAddChild(ctx context.Context, child *scan.Session) (*scan.Session, error)

func (*ScansService) SessionGet

func (s *ScansService) SessionGet(ctx context.Context, scanId, sessionId string) (*scan.Session, error)

func (*ScansService) SessionReportCreate

func (s *ScansService) SessionReportCreate(ctx context.Context,
	src *scan.Session, rep *report.Report) (*report.Report, error)

func (*ScansService) SessionReportGet

func (s *ScansService) SessionReportGet(ctx context.Context, sc *scan.Session) (*report.Report, error)

func (*ScansService) SessionUpdate

func (s *ScansService) SessionUpdate(ctx context.Context, src *scan.Session) (*scan.Session, error)

func (*ScansService) String

func (s *ScansService) String() string

func (*ScansService) Update

func (s *ScansService) Update(ctx context.Context, src *scan.Scan) (*scan.Scan, error)

type ServiceError

type ServiceError struct {
	Code    int
	Message string
}

ServiceError is a transport object to pass information about a non-Http error occurred in a WebService while processing a request.

func NewError

func NewError(code int, message string) ServiceError

NewError returns a ServiceError using the code and reason

func (ServiceError) Error

func (s ServiceError) Error() string

Error returns a text representation of the service error

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 TokensListOpts

type TokensListOpts struct {
	Name    string `url:"name"`
	Version string `url:"version"`
	Type    string `url:"type"`
}

type TokensService

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

func (*TokensService) Create

func (s *TokensService) Create(ctx context.Context, src *token.Token) (*token.Token, error)

func (*TokensService) Delete

func (s *TokensService) Delete(ctx context.Context, id string) error

func (*TokensService) Get

func (s *TokensService) Get(ctx context.Context, id string) (*token.Token, error)

func (*TokensService) List

List tokens.

func (*TokensService) String

func (s *TokensService) String() string

func (*TokensService) Update

func (s *TokensService) Update(ctx context.Context, src *token.Token) (*token.Token, error)

type UploadedFile

type UploadedFile struct {
	Fieldname, Filename string
	Data                io.Reader
}

Jump to

Keyboard shortcuts

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