api

package
v0.0.0-...-1a0708b Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBackoff

func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration

DefaultBackoff provides a default callback for Backoff which will perform exponential backoff based on the attempt number and limited by the provided minimum and maximum durations. It also tries to parse XRateLimitReset response header when a http.StatusTooManyRequests (HTTP Code 429) is found in the resp parameter. Hence it will return the number of seconds the server states it may be ready to process more requests from this client.

func DefaultRetryPolicy

func DefaultRetryPolicy(resp *http.Response, err error) (bool, error)

DefaultRetryPolicy provides a default callback for CheckForRetry.

Types

type Backoff

type Backoff func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration

Backoff specifies a policy for how long to wait between retries. It is called after a failing request to determine the amount of time that should pass before trying again.

type CheckForRetry

type CheckForRetry func(resp *http.Response, err error) (bool, error)

CheckForRetry specifies a policy for handling retries. It is called following each request with the response and error values returned by the http.Client. If it returns false, the Client stops retrying and returns the response to the caller. If it returns an error, that error value is returned in lieu of the error from the request.

type Client

type Client struct {
	Duration      time.Duration
	CheckForRetry CheckForRetry
	Backoff       Backoff
	RetryMax      int
	RetryWaitMin  time.Duration
	RetryWaitMax  time.Duration
	// contains filtered or unexported fields
}

Client is used to with iAuditor API's.

func GetTestClient

func GetTestClient(opts ...Opt) *Client

GetTestClient creates a new test apiClient

func NewClient

func NewClient(addr string, accessToken string, opts ...Opt) *Client

NewClient creates a new instance of the Client

func (*Client) CheckInspectionReportExportCompletion

func (a *Client) CheckInspectionReportExportCompletion(ctx context.Context, auditID string, messageID string) (*InspectionReportExportCompletionResponse, error)

CheckInspectionReportExportCompletion checks if the report export is complete.

func (*Client) DownloadInspectionReportFile

func (a *Client) DownloadInspectionReportFile(ctx context.Context, url string) (io.ReadCloser, error)

DownloadInspectionReportFile downloads the report file of the inspection.

func (*Client) DrainAccountActivityHistoryLog

func (a *Client) DrainAccountActivityHistoryLog(ctx context.Context, req *GetAccountsActivityLogRequestParams, feedFn func(*GetAccountsActivityLogResponse) error) error

DrainAccountActivityHistoryLog cycle throgh GetAccountsActivityLogResponse and adapts the filter whule there is a next page

func (*Client) DrainFeed

func (a *Client) DrainFeed(ctx context.Context, request *GetFeedRequest, feedFn func(*GetFeedResponse) error) error

DrainFeed fetches the data in batches and triggers the callback for each batch.

func (*Client) DrainInspections

func (a *Client) DrainInspections(
	ctx context.Context,
	params *ListInspectionsParams,
	callback func(*ListInspectionsResponse) error,
) error

DrainInspections fetches the inspections in batches and triggers the callback for each batch.

func (*Client) GetFeed

func (a *Client) GetFeed(ctx context.Context, request *GetFeedRequest) (*GetFeedResponse, error)

GetFeed executes the feed request and

func (*Client) GetInspection

func (a *Client) GetInspection(ctx context.Context, id string) (*json.RawMessage, error)

GetInspection retrieves the inspection of the given id.

func (*Client) GetMedia

func (a *Client) GetMedia(ctx context.Context, request *GetMediaRequest) (*GetMediaResponse, error)

GetMedia fetches the media object from iAuditor.

func (*Client) HTTPClient

func (a *Client) HTTPClient() *http.Client

HTTPClient returns the http Client used by APIClient

func (*Client) HTTPTransport

func (a *Client) HTTPTransport() *http.Transport

HTTPTransport returns the http Transport used by APIClient

func (*Client) InitiateInspectionReportExport

func (a *Client) InitiateInspectionReportExport(ctx context.Context, auditID string, format string, preferenceID string) (string, error)

InitiateInspectionReportExport export the report of the given auditID.

func (*Client) ListInspections

func (a *Client) ListInspections(ctx context.Context, params *ListInspectionsParams) (*ListInspectionsResponse, error)

ListInspections retrieves the list of inspections from iAuditor

func (*Client) ListOrganisationActivityLog

func (a *Client) ListOrganisationActivityLog(ctx context.Context, request *GetAccountsActivityLogRequestParams) (*GetAccountsActivityLogResponse, error)

ListOrganisationActivityLog returns response from AccountsActivityLog or error

func (*Client) WhoAmI

func (a *Client) WhoAmI(ctx context.Context) (*WhoAmIResponse, error)

WhoAmI returns the details for the user who is making the request

type FeedMetadata

type FeedMetadata struct {
	NextPage         string `json:"next_page"`
	RemainingRecords int64  `json:"remaining_records"`
}

FeedMetadata is a representation of the metadata returned when fetching a feed

type GetAccountsActivityLogRequestParams

type GetAccountsActivityLogRequestParams struct {
	OrgID     string                    `json:"org_id"`
	PageSize  int                       `json:"page_size"`
	PageToken string                    `json:"page_token"`
	Filters   accountsActivityLogFilter `json:"filters"`
}

GetAccountsActivityLogRequestParams contains fields required to make a post request to activity log history api

func NewGetAccountsActivityLogRequest

func NewGetAccountsActivityLogRequest(pageSize int, from time.Time) *GetAccountsActivityLogRequestParams

NewGetAccountsActivityLogRequest build a request for AccountsActivityLog for now it serves the purposes only for inspection.deleted. If we need later, we can change this builder

type GetAccountsActivityLogResponse

type GetAccountsActivityLogResponse struct {
	Activities    []activityResponse
	NextPageToken string `json:"next_page_token"`
}

GetAccountsActivityLogResponse is the response from activity log history api

type GetFeedParams

type GetFeedParams struct {
	ModifiedAfter   time.Time `url:"modified_after,omitempty"`
	TemplateIDs     []string  `url:"template,omitempty"`
	Archived        string    `url:"archived,omitempty"`
	Completed       string    `url:"completed,omitempty"`
	IncludeInactive bool      `url:"include_inactive,omitempty"`
	Limit           int       `url:"limit,omitempty"`
	WebReportLink   string    `url:"web_report_link,omitempty"`

	// Applicable only for sites
	IncludeDeleted    bool  `url:"include_deleted,omitempty"`
	ShowOnlyLeafNodes *bool `url:"show_only_leaf_nodes,omitempty"`
}

GetFeedParams is a list of all parameters we can set when fetching a feed

type GetFeedRequest

type GetFeedRequest struct {
	URL        string
	InitialURL string
	Params     GetFeedParams
}

GetFeedRequest has all the data needed to make a request to get a feed

type GetFeedResponse

type GetFeedResponse struct {
	Metadata FeedMetadata `json:"metadata"`

	Data json.RawMessage `json:"data"`
}

GetFeedResponse is a representation of the data returned when fetching a feed

type GetMediaRequest

type GetMediaRequest struct {
	URL     string
	AuditID string
}

GetMediaRequest has all the data needed to make a request to get a media

type GetMediaResponse

type GetMediaResponse struct {
	ContentType string
	Body        []byte
	MediaID     string
}

GetMediaResponse is a representation of the data returned when fetching media

type HTTPDoer

type HTTPDoer interface {
	Do() (*http.Response, error)
	URL() string
	Error() interface{}
}

HTTPDoer executes http requests.

type Header string

Header is used to represent name of a header

const (
	Authorization      Header = "Authorization"
	ContentType        Header = "Content-Type"
	XRequestID         Header = "X-Request-ID"
	IntegrationID      Header = "sc-integration-id"
	IntegrationVersion Header = "sc-integration-version"
	XRateLimitReset    Header = "X-RateLimit-Reset"
)

Headers that are sent with each request when making api calls

type Inspection

type Inspection struct {
	ID         string    `json:"audit_id"`
	ModifiedAt time.Time `json:"modified_at"`
}

Inspection represents some properties present in an inspection

type InspectionReportExportCompletionResponse

type InspectionReportExportCompletionResponse struct {
	Status string `json:"status"`
	URL    string `json:"url,omitempty"`
}

InspectionReportExportCompletionResponse represents the response of report export completion status

type ListInspectionsParams

type ListInspectionsParams struct {
	ModifiedAfter time.Time `url:"modified_after,omitempty"`
	TemplateIDs   []string  `url:"template,omitempty"`
	Archived      string    `url:"archived,omitempty"`
	Completed     string    `url:"completed,omitempty"`
	Limit         int       `url:"limit,omitempty"`
}

ListInspectionsParams is a list of all parameters we can set when fetching inspections

type ListInspectionsResponse

type ListInspectionsResponse struct {
	Count       int          `json:"count"`
	Total       int          `json:"total"`
	Inspections []Inspection `json:"audits"`
}

ListInspectionsResponse represents the response of listing inspections

type Opt

type Opt func(*Client)

Opt is an option to configure the Client

func OptAddTLSCert

func OptAddTLSCert(certPath string) Opt

OptAddTLSCert adds a certificate at the supplied path to the cert pool

func OptSetInsecureTLS

func OptSetInsecureTLS(insecureSkipVerify bool) Opt

OptSetInsecureTLS sets whether TLS certs should be verified

func OptSetProxy

func OptSetProxy(proxyURL *url.URL) Opt

OptSetProxy sets the proxy URL to use for API requests

func OptSetTimeout

func OptSetTimeout(t time.Duration) Opt

OptSetTimeout sets the timeout for the request

type WhoAmIResponse

type WhoAmIResponse struct {
	UserID         string `json:"user_id"`
	OrganisationID string `json:"organisation_id"`
	Firstname      string `json:"firstname"`
	Lastname       string `json:"lastname"`
}

WhoAmIResponse represents the response of WhoAmI

Jump to

Keyboard shortcuts

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