Documentation ¶
Overview ¶
Token implements access to prToken microservice which stores information about token to access 3rd party sites.
HTTP verbs are translated into the following function calls:
Verbs to Functions ------ --------- POST Create GET Get GET/ List resources PUT Replace DELETE Delete PATCH Edit
user ID mapper translates 3rd party sides credentials into internal user id.
HTTP verbs are translated into the following function calls:
Verbs to keys Functions ---------- -------------------------- --------- POST Create GET /credential Get GET /prUserIdMappersLIST List resources PUT /credential Replace DELETE /credential Delete PATCH /credential Edit
Index ¶
- func Bool(v bool) *bool
- func CheckResponse(r *http.Response) error
- func Int(v int) *int
- func Int64(v int64) *int64
- func String(v string) *string
- func Stringify(message interface{}) string
- type AcceptedError
- type BasicAuthTransport
- type Client
- func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)
- func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)
- func (c *Client) NewUploadRequest(urlStr string, reader io.Reader, size int64, mediaType string) (*http.Request, error)
- type Error
- type ErrorResponse
- type ListOptions
- type Metadata
- type RawOptions
- type RawType
- type Response
- type Timestamp
- type Token
- type TokenListOptions
- type TokensService
- func (s *TokensService) Create(ctx context.Context, newToken Token) (*Token, *Response, error)
- func (s *TokensService) Delete(ctx context.Context, uuid string) (*Response, error)
- func (s *TokensService) Edit(ctx context.Context, token *Token, uuid string) (*Token, *Response, error)
- func (s *TokensService) Get(ctx context.Context, uuid string) (*Token, *Response, error)
- func (s *TokensService) List(ctx context.Context, opt *TokenListOptions) (*Response, error)
- func (s *TokensService) Replace(ctx context.Context, token *Token, uuid string) (*Token, *Response, error)
- type UploadOptions
- type UserIdMapper
- type UserIdMapperListOptions
- type UserIdMappersService
- func (s *UserIdMappersService) Create(ctx context.Context, newUserIdMapper UserIdMapper) (*UserIdMapper, *Response, error)
- func (s *UserIdMappersService) Delete(ctx context.Context, cred string) (*Response, error)
- func (s *UserIdMappersService) Edit(ctx context.Context, token *UserIdMapper, cred string) (*UserIdMapper, *Response, error)
- func (s *UserIdMappersService) Get(ctx context.Context, cred string) (*UserIdMapper, *Response, error)
- func (s *UserIdMappersService) List(ctx context.Context, opt *UserIdMapperListOptions) (*Response, error)
- func (s *UserIdMappersService) Replace(ctx context.Context, token *UserIdMapper, cred string) (*UserIdMapper, *Response, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
func CheckResponse ¶
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 or equal to 202 Accepted. 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.
*AcceptedError for 202 Accepted status codes, and *TwoFactorAuthError for two-factor authentication errors.
func Int ¶
Int is a helper routine that allocates a new int value to store v and returns a pointer to it.
func Int64 ¶
Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.
Types ¶
type AcceptedError ¶
type AcceptedError struct { // Raw contains the response body. Raw []byte }
AcceptedError occurs when PavedRoad returns 202 Accepted response with an empty body, which means a job was scheduled on the PavedRoad side to process the information needed and cache it. Technically, 202 Accepted is not a real error, it's just used to indicate that results are not ready yet, but should be available soon. The request can be repeated after some time.
func (*AcceptedError) Error ¶
func (*AcceptedError) Error() string
type BasicAuthTransport ¶
type BasicAuthTransport struct { Username string // PavedRoad username Password string // PavedRoad password OTP string // one-time password for users with two-factor auth enabled // Transport is the underlying HTTP transport to use when making requests. // It will default to http.DefaultTransport if nil. Transport http.RoundTripper }
BasicAuthTransport is an http.RoundTripper that authenticates all requests using HTTP Basic Authentication with the provided username and password. It additionally supports users who have two-factor authentication enabled.
func (*BasicAuthTransport) Client ¶
func (t *BasicAuthTransport) Client() *http.Client
Client returns an *http.Client that makes requests that are authenticated using HTTP Basic Authentication.
type Client ¶
type Client struct { // Base URL for API requests. Defaults to the public PavedRoad API, but can be // set to a domain endpoint to use with PavedRoad Enterprise. BaseURL should // always be specified with a trailing slash. BaseURL *url.URL // Base URL for uploading files. UploadURL *url.URL // User agent used when communicating with the PavedRoad API. UserAgent string // Services used for talking to different parts of the PavedRoad API. Token *TokensService UserIdMapper *UserIdMappersService // contains filtered or unexported fields }
A Client manages communication with the PavedRoad API.
func NewClient ¶
NewClient returns a new PavedRoad API client. If a nil httpClient is provided, a new http.Client 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 golang.org/x/oauth2 library).
func (*Client) Do ¶
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.
The provided ctx must be non-nil. If it is canceled or times out, ctx.Err() will be returned.
func (*Client) NewRequest ¶
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) NewUploadRequest ¶
func (c *Client) NewUploadRequest(urlStr string, reader io.Reader, size int64, mediaType string) (*http.Request, error)
NewUploadRequest creates an upload request. A relative URL can be provided in urlStr, in which case it is resolved relative to the UploadURL of the Client. Relative URLs should always be specified without a preceding slash.
type Error ¶
type Error struct { Resource string `json:"resource"` // resource on which the error occurred Field string `json:"field"` // field on which the error occurred Code string `json:"code"` // validation error code Message string `json:"message"` // Message describing the error. Errors with Code == "custom" will always have this set. }
An Error reports more details on an individual error in an ErrorResponse. These are the possible validation error codes:
missing: resource does not exist missing_field: a required field on a resource has not been set invalid: the formatting of a field is invalid already_exists: another resource has the same valid as this field custom: some resources return this, additional information is set in the Message field of the Error
PavedRoad API docs: https://developer.pavedroad.io/v1/#client-errors
type ErrorResponse ¶
type ErrorResponse struct { Response *http.Response // HTTP response that caused this error Message string `json:"message"` // error message Errors []Error `json:"errors"` // more detail on individual errors // Block is only populated on certain types of errors such as code 451. Block *struct { Reason string `json:"reason,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` } `json:"block,omitempty"` // Most errors will also include a documentation_url field pointing // to some content that might help you resolve the error, see // TODO:(tbd) https://developer.pavedroad.io/v3/#client-errors DocumentationURL string `json:"documentation_url,omitempty"` }
An ErrorResponse reports one or more errors caused by an API request.
TODO:(tbd)PavedRoad API docs: https://developer.pavedroad.io/v3/#client-errors
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:"per_page,omitempty"` }
ListOptions specifies the optional parameters to various List methods that support pagination.
type Metadata ¶
type Metadata struct { Name string `json:"name"` Namespace string `json:"namespace"` UID string `json:"uid"` Site string `json:"site"` EndPoint string `json:"endPoint"` Token string `json:"token"` Scope []string `json:"scope"` }
Metadata stored for a token
type RawOptions ¶
type RawOptions struct {
Type RawType
}
RawOptions specifies parameters when user wants to get raw format of a response instead of JSON.
type RawType ¶
type RawType uint8
RawType represents type of raw format of a request instead of JSON.
type Response ¶
Response is a PavedRoad API response. This wraps the standard http.Response returned from PavedRoad and provides convenient access to things like pagination links.
type Timestamp ¶
Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp.
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.
type Token ¶
type Token struct { APIVersion string `json:"apiVersion"` Kind string `json:"kind"` Metadata Metadata `json:"metadata"` Created string `json:"created,ignoreempty"` Updated string `json:"updated"` Active bool `json:"active"` }
Token data structure for token storage
type TokenListOptions ¶
type TokenListOptions struct { // ID of the last token seen Since int64 `url:"since,omitempty"` // Note: Pagination is powered exclusively by the Since parameter, // ListOptions.Page has no effect. // ListOptions.PerPage controls an undocumented PavedRoad API parameter. ListOptions }
TokenListOptions specifies optional parameters to the TokensService.ListAll method.
type TokensService ¶
type TokensService service
TokensService handles communication with the token related methods of the PavedRoad API.
func (*TokensService) Edit ¶
func (s *TokensService) Edit(ctx context.Context, token *Token, uuid string) (*Token, *Response, error)
Edit a token. PavedRoad API docs: https://developer.pavedroad.io/v1/token/#update-token
func (*TokensService) Get ¶
Get fetches a token using based on a UUID. PavedRoad API endpoint /prTokens/uuid.
func (*TokensService) List ¶
func (s *TokensService) List(ctx context.Context, opt *TokenListOptions) (*Response, error)
ListAll lists all PavedRoad token.
type UploadOptions ¶
type UploadOptions struct { Name string `url:"name,omitempty"` Label string `url:"label,omitempty"` MediaType string `url:"-"` }
UploadOptions specifies the parameters to methods that support uploads.
type UserIdMapper ¶
type UserIdMapper struct { APIVersion string `json:"apiVersion"` ObjVersion string `json:"objVersion"` Kind string `json:"kind"` Credential string `json:"login"` UserUUID string `json:"userUUID"` LoginCount int `json:"loginCount"` Created string `json:"created,ignoreempty"` Updated string `json:"updated,ignoreempty"` Active string `json:"active"` }
prUserIdMapper data structure for token storage
func (UserIdMapper) String ¶
func (u UserIdMapper) String() string
type UserIdMapperListOptions ¶
type UserIdMapperListOptions struct { // ID of the last token seen Since int64 `url:"since,omitempty"` // Note: Pagination is powered exclusively by the Since parameter, // ListOptions.Page has no effect. // ListOptions.PerPage controls an undocumented PavedRoad API parameter. ListOptions }
UserIdMapperListOptions specifies optional parameters to the UserIdMappersService.ListAll method.
type UserIdMappersService ¶
type UserIdMappersService service
UserIdMappersService handles communication with the token related methods of the PavedRoad API.
func (*UserIdMappersService) Create ¶
func (s *UserIdMappersService) Create(ctx context.Context, newUserIdMapper UserIdMapper) (*UserIdMapper, *Response, error)
Create a token PavedRoad API endpoint /prUserIdMappers/
func (*UserIdMappersService) Delete ¶
Delete a token using a Ucredential. PavedRoad API endpoint /prUserIdMappers/cred.
func (*UserIdMappersService) Edit ¶
func (s *UserIdMappersService) Edit(ctx context.Context, token *UserIdMapper, cred string) (*UserIdMapper, *Response, error)
Edit a token. PavedRoad API docs: https://developer.pavedroad.io/v1/token/#update-token
func (*UserIdMappersService) Get ¶
func (s *UserIdMappersService) Get(ctx context.Context, cred string) (*UserIdMapper, *Response, error)
Get fetches a token using based on a Ucredential. PavedRoad API endpoint /prUserIdMappers/credential.
func (*UserIdMappersService) List ¶
func (s *UserIdMappersService) List(ctx context.Context, opt *UserIdMapperListOptions) (*Response, error)
ListAll lists all PavedRoad token.
func (*UserIdMappersService) Replace ¶
func (s *UserIdMappersService) Replace(ctx context.Context, token *UserIdMapper, cred string) (*UserIdMapper, *Response, error)
Replace a token. PavedRoad API docs: https://developer.pavedroad.io/v1/token/#replace-token