apiclient

package
v0.0.0-...-98cd694 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Unlicense Imports: 28 Imported by: 0

Documentation

Overview

Package apiclient provides an HTTP client that can communicate with and interpret the responses of an instance of the service.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is a handy error to return when we receive a 404 response.
	ErrNotFound = errors.New("404: not found")

	// ErrInvalidRequestInput is a handy error to return when we receive a 400 response.
	ErrInvalidRequestInput = errors.New("400: bad request")

	// ErrInternalServerError is a handy error to return when we receive a 500 response.
	ErrInternalServerError = errors.New("500: internal server error")

	// ErrUnauthorized is a handy error to return when we receive a 401 response.
	ErrUnauthorized = errors.New("401: not authorized")

	// ErrNoURLProvided is a handy error to return when we expect a *url.URL and don't receive one.
	ErrNoURLProvided = errors.New("no URL provided")

	// ErrInvalidTOTPToken is an error for when our TOTP validation request goes awry.
	ErrInvalidTOTPToken = errors.New("invalid TOTP token")

	// ErrNilInputProvided indicates nil input was provided in an unacceptable context.
	ErrNilInputProvided = errors.New("nil input provided")

	// ErrInvalidIDProvided indicates a required ID was passed in as zero.
	ErrInvalidIDProvided = errors.New("required ID provided is zero")

	// ErrEmptyEmailAddressProvided indicates the user provided an empty username for search.
	ErrEmptyEmailAddressProvided = errors.New("empty email address provided")

	// ErrEmptyQueryProvided indicates the user provided an empty query.
	ErrEmptyQueryProvided = errors.New("query provided was empty")

	// ErrEmptyUsernameProvided indicates the user provided an empty username for search.
	ErrEmptyUsernameProvided = errors.New("empty username provided")

	// ErrCookieRequired indicates a cookie is required.
	ErrCookieRequired = errors.New("cookie required for request")

	// ErrNoCookiesReturned indicates nil input was provided in an unacceptable context.
	ErrNoCookiesReturned = errors.New("no cookies returned from request")

	// ErrNilResponse indicates we received a nil response.
	ErrNilResponse = errors.New("nil response")

	// ErrArgumentIsNotPointer indicates we received a non-pointer interface argument.
	ErrArgumentIsNotPointer = errors.New("value is not a pointer")
)

Functions

func UsingCookie

func UsingCookie(cookie *http.Cookie) func(*Client) error

UsingCookie sets the authCookie value on the client.

func UsingDebug

func UsingDebug(debug bool) func(*Client) error

UsingDebug sets the debug value on the client.

func UsingJSON

func UsingJSON() func(*Client) error

UsingJSON sets the url on the client.

func UsingLogger

func UsingLogger(logger logging.Logger) func(*Client) error

UsingLogger sets the logger on the client.

func UsingLogin

func UsingLogin(ctx context.Context, input *types.UserLoginInput) func(*Client) error

UsingLogin sets the authCookie value on the client.

func UsingOAuth2

func UsingOAuth2(ctx context.Context, clientID, clientSecret string, cookie *http.Cookie) func(*Client) error

UsingOAuth2 sets the client to use OAuth2.

func UsingTimeout

func UsingTimeout(timeout time.Duration) func(*Client) error

UsingTimeout sets the debug value on the client.

func UsingTracingProvider

func UsingTracingProvider(tracerProvider tracing.TracerProvider) option

UsingTracingProvider sets the url on the client.

func UsingURL

func UsingURL(u string) func(*Client) error

UsingURL sets the url on the client.

func UsingXML

func UsingXML() func(*Client) error

UsingXML sets the url on the client.

Types

type Client

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

Client is a client for interacting with v1 of our HTTP API.

func NewClient

func NewClient(u *url.URL, tracerProvider tracing.TracerProvider, options ...option) (*Client, error)

NewClient builds a new API client for us.

func (*Client) AcceptAccountInvitation

func (c *Client) AcceptAccountInvitation(ctx context.Context, accountInvitationID, token, note string) error

AcceptAccountInvitation accepts a given account invitation.

func (*Client) ArchiveAccount

func (c *Client) ArchiveAccount(ctx context.Context, accountID string) error

ArchiveAccount archives a account.

func (*Client) ArchiveOAuth2Client

func (c *Client) ArchiveOAuth2Client(ctx context.Context, oauth2ClientDatabaseID string) error

ArchiveOAuth2Client archives an OAuth2 client.

func (*Client) ArchiveServiceSetting

func (c *Client) ArchiveServiceSetting(ctx context.Context, serviceSettingID string) error

ArchiveServiceSetting archives a service setting.

func (*Client) ArchiveServiceSettingConfiguration

func (c *Client) ArchiveServiceSettingConfiguration(ctx context.Context, serviceSettingConfigurationID string) error

ArchiveServiceSettingConfiguration archives a service setting.

func (*Client) ArchiveUser

func (c *Client) ArchiveUser(ctx context.Context, userID string) error

ArchiveUser archives a user.

func (*Client) ArchiveWebhook

func (c *Client) ArchiveWebhook(ctx context.Context, webhookID string) error

ArchiveWebhook archives a webhook.

func (*Client) ArchiveWebhookTriggerEvent

func (c *Client) ArchiveWebhookTriggerEvent(ctx context.Context, webhookID, webhookTriggerEventID string) error

ArchiveWebhookTriggerEvent archives a webhook trigger event.

func (*Client) AuthenticatedClient

func (c *Client) AuthenticatedClient() *http.Client

AuthenticatedClient returns the authenticated *apiclient.Client that we use to make most requests.

func (*Client) BeginSession

func (c *Client) BeginSession(ctx context.Context, input *types.UserLoginInput) (*http.Cookie, error)

BeginSession fetches a login cookie.

func (*Client) BuildURL

func (c *Client) BuildURL(ctx context.Context, qp url.Values, parts ...string) string

BuildURL builds standard service URLs.

func (*Client) CancelAccountInvitation

func (c *Client) CancelAccountInvitation(ctx context.Context, accountInvitationID, token, note string) error

CancelAccountInvitation cancels a given account invitation.

func (*Client) ChangePassword

func (c *Client) ChangePassword(ctx context.Context, cookie *http.Cookie, input *types.PasswordUpdateInput) error

ChangePassword changes a user's password.

func (*Client) CheckUserPermissions

func (c *Client) CheckUserPermissions(ctx context.Context, permissions ...string) (*types.UserPermissionsResponse, error)

CheckUserPermissions checks if a user has certain permissions.

func (*Client) CreateAccount

func (c *Client) CreateAccount(ctx context.Context, input *types.AccountCreationRequestInput) (*types.Account, error)

CreateAccount creates a account.

func (*Client) CreateOAuth2Client

CreateOAuth2Client creates an OAuth2 client.

func (*Client) CreateServiceSetting

func (c *Client) CreateServiceSetting(ctx context.Context, input *types.ServiceSettingCreationRequestInput) (*types.ServiceSetting, error)

CreateServiceSetting creates a service setting.

func (*Client) CreateServiceSettingConfiguration

CreateServiceSettingConfiguration creates a service setting.

func (*Client) CreateUser

CreateUser creates a new user.

func (*Client) CreateUserNotification

func (c *Client) CreateUserNotification(ctx context.Context, input *types.UserNotificationCreationRequestInput) (*types.UserNotification, error)

CreateUserNotification creates a user notification.

func (*Client) CreateWebhook

func (c *Client) CreateWebhook(ctx context.Context, input *types.WebhookCreationRequestInput) (*types.Webhook, error)

CreateWebhook creates a webhook.

func (*Client) CycleTwoFactorSecret

func (c *Client) CycleTwoFactorSecret(ctx context.Context, cookie *http.Cookie, input *types.TOTPSecretRefreshInput) (*types.TOTPSecretRefreshResponse, error)

CycleTwoFactorSecret cycles a user's 2FA secret.

func (*Client) EndSession

func (c *Client) EndSession(ctx context.Context) error

EndSession logs a user out.

func (*Client) GetAccount

func (c *Client) GetAccount(ctx context.Context, accountID string) (*types.Account, error)

GetAccount retrieves a account.

func (*Client) GetAccountInvitation

func (c *Client) GetAccountInvitation(ctx context.Context, accountID, accountInvitationID string) (*types.AccountInvitation, error)

GetAccountInvitation retrieves a account invitation.

func (*Client) GetAccounts

func (c *Client) GetAccounts(ctx context.Context, filter *types.QueryFilter) (*types.QueryFilteredResult[types.Account], error)

GetAccounts retrieves a list of accounts.

func (*Client) GetAuditLogEntriesForAccount

func (c *Client) GetAuditLogEntriesForAccount(ctx context.Context, resourceTypes ...string) (*types.QueryFilteredResult[types.AuditLogEntry], error)

GetAuditLogEntriesForAccount fetches audit log entries for a user's account.

func (*Client) GetAuditLogEntriesForUser

func (c *Client) GetAuditLogEntriesForUser(ctx context.Context, resourceTypes ...string) (*types.QueryFilteredResult[types.AuditLogEntry], error)

GetAuditLogEntriesForUser fetches audit log entries for a user.

func (*Client) GetAuditLogEntry

func (c *Client) GetAuditLogEntry(ctx context.Context, auditLogEntryID string) (*types.AuditLogEntry, error)

GetAuditLogEntry fetches an audit log entry.

func (*Client) GetCurrentAccount

func (c *Client) GetCurrentAccount(ctx context.Context) (*types.Account, error)

GetCurrentAccount retrieves a account.

func (*Client) GetOAuth2Client

func (c *Client) GetOAuth2Client(ctx context.Context, oauth2ClientDatabaseID string) (*types.OAuth2Client, error)

GetOAuth2Client gets an OAuth2 client.

func (*Client) GetOAuth2Clients

func (c *Client) GetOAuth2Clients(ctx context.Context, filter *types.QueryFilter) (*types.QueryFilteredResult[types.OAuth2Client], error)

GetOAuth2Clients gets a list of OAuth2 clients.

func (*Client) GetPendingAccountInvitationsForUser

func (c *Client) GetPendingAccountInvitationsForUser(ctx context.Context, filter *types.QueryFilter) (*types.QueryFilteredResult[types.AccountInvitation], error)

GetPendingAccountInvitationsForUser retrieves account invitations received by the user.

func (*Client) GetPendingAccountInvitationsFromUser

func (c *Client) GetPendingAccountInvitationsFromUser(ctx context.Context, filter *types.QueryFilter) (*types.QueryFilteredResult[types.AccountInvitation], error)

GetPendingAccountInvitationsFromUser retrieves account invitations sent by the user.

func (*Client) GetSelf

func (c *Client) GetSelf(ctx context.Context) (*types.User, error)

GetSelf retrieves a user.

func (*Client) GetServiceSetting

func (c *Client) GetServiceSetting(ctx context.Context, serviceSettingID string) (*types.ServiceSetting, error)

GetServiceSetting gets a service setting.

func (*Client) GetServiceSettingConfigurationForUserByName

func (c *Client) GetServiceSettingConfigurationForUserByName(ctx context.Context, settingName string, filter *types.QueryFilter) (*types.ServiceSettingConfiguration, error)

GetServiceSettingConfigurationForUserByName retrieves a list of service settings.

func (*Client) GetServiceSettingConfigurationsForAccount

func (c *Client) GetServiceSettingConfigurationsForAccount(ctx context.Context, filter *types.QueryFilter) (*types.QueryFilteredResult[types.ServiceSettingConfiguration], error)

GetServiceSettingConfigurationsForAccount retrieves a list of service settings.

func (*Client) GetServiceSettingConfigurationsForUser

func (c *Client) GetServiceSettingConfigurationsForUser(ctx context.Context, filter *types.QueryFilter) (*types.QueryFilteredResult[types.ServiceSettingConfiguration], error)

GetServiceSettingConfigurationsForUser retrieves a list of service settings.

func (*Client) GetServiceSettings

func (c *Client) GetServiceSettings(ctx context.Context, filter *types.QueryFilter) (*types.QueryFilteredResult[types.ServiceSetting], error)

GetServiceSettings retrieves a list of service settings.

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, userID string) (*types.User, error)

GetUser retrieves a user.

func (*Client) GetUserNotification

func (c *Client) GetUserNotification(ctx context.Context, userNotificationID string) (*types.UserNotification, error)

GetUserNotification gets a user notification.

func (*Client) GetUserNotifications

func (c *Client) GetUserNotifications(ctx context.Context, filter *types.QueryFilter) (*types.QueryFilteredResult[types.UserNotification], error)

GetUserNotifications retrieves a list of user notifications.

func (*Client) GetUsers

GetUsers retrieves a list of users.

func (*Client) GetWebhook

func (c *Client) GetWebhook(ctx context.Context, webhookID string) (*types.Webhook, error)

GetWebhook retrieves a webhook.

func (*Client) GetWebhooks

func (c *Client) GetWebhooks(ctx context.Context, filter *types.QueryFilter) (*types.QueryFilteredResult[types.Webhook], error)

GetWebhooks gets a list of webhooks.

func (*Client) InviteUserToAccount

func (c *Client) InviteUserToAccount(ctx context.Context, destinationAccountID string, input *types.AccountInvitationCreationRequestInput) (*types.AccountInvitation, error)

InviteUserToAccount adds a user to a account.

func (*Client) IsUp

func (c *Client) IsUp(ctx context.Context) bool

IsUp returns whether the service's health endpoint is returning 200s.

func (*Client) MarkAsDefault

func (c *Client) MarkAsDefault(ctx context.Context, accountID string) error

MarkAsDefault marks a given account as the default for a given user.

func (*Client) ModifyMemberPermissions

func (c *Client) ModifyMemberPermissions(ctx context.Context, accountID, userID string, input *types.ModifyUserPermissionsInput) error

ModifyMemberPermissions modifies a given user's permissions for a given account.

func (*Client) PlainClient

func (c *Client) PlainClient() *http.Client

PlainClient returns the unauthenticated *apiclient.Client that we use to make certain requests.

func (*Client) RedeemPasswordResetToken

func (c *Client) RedeemPasswordResetToken(ctx context.Context, input *types.PasswordResetTokenRedemptionRequestInput) error

RedeemPasswordResetToken redeems a password reset token.

func (*Client) RejectAccountInvitation

func (c *Client) RejectAccountInvitation(ctx context.Context, accountInvitationID, token, note string) error

RejectAccountInvitation rejects a given account invitation.

func (*Client) RemoveUserFromAccount

func (c *Client) RemoveUserFromAccount(ctx context.Context, accountID, userID string) error

RemoveUserFromAccount removes a user from a account.

func (*Client) RequestBuilder

func (c *Client) RequestBuilder() *requests.Builder

RequestBuilder provides the client's *requests.Builder.

func (*Client) RequestPasswordResetToken

func (c *Client) RequestPasswordResetToken(ctx context.Context, emailAddress string) error

RequestPasswordResetToken requests a password reset token.

func (*Client) SearchForUsersByUsername

func (c *Client) SearchForUsersByUsername(ctx context.Context, username string) ([]*types.User, error)

SearchForUsersByUsername searches for a user from a list of users by their username.

func (*Client) SearchServiceSettings

func (c *Client) SearchServiceSettings(ctx context.Context, query string, limit uint8) ([]*types.ServiceSetting, error)

SearchServiceSettings searches through a list of service settings.

func (*Client) SetOptions

func (c *Client) SetOptions(opts ...option) error

SetOptions sets a new option on the client.

func (*Client) SwitchActiveAccount

func (c *Client) SwitchActiveAccount(ctx context.Context, accountID string) error

SwitchActiveAccount will switch the account on whose behalf requests are made.

func (*Client) TransferAccountOwnership

func (c *Client) TransferAccountOwnership(ctx context.Context, accountID string, input *types.AccountOwnershipTransferInput) error

TransferAccountOwnership transfers ownership of a account to a given user.

func (*Client) URL

func (c *Client) URL() *url.URL

URL provides the client's URL.

func (*Client) UpdateAccount

func (c *Client) UpdateAccount(ctx context.Context, account *types.Account) error

UpdateAccount updates a account.

func (*Client) UpdateServiceSettingConfiguration

func (c *Client) UpdateServiceSettingConfiguration(ctx context.Context, serviceSettingConfiguration *types.ServiceSettingConfiguration) error

UpdateServiceSettingConfiguration updates a service setting.

func (*Client) UpdateUserAccountStatus

func (c *Client) UpdateUserAccountStatus(ctx context.Context, input *types.UserAccountStatusUpdateInput) error

UpdateUserAccountStatus updates a user's account status.

func (*Client) UpdateUserDetails

func (c *Client) UpdateUserDetails(ctx context.Context, input *types.UserDetailsUpdateRequestInput) error

UpdateUserDetails updates a user's details.

func (*Client) UpdateUserEmailAddress

func (c *Client) UpdateUserEmailAddress(ctx context.Context, input *types.UserEmailAddressUpdateInput) error

UpdateUserEmailAddress updates a user's email address.

func (*Client) UpdateUserNotification

func (c *Client) UpdateUserNotification(ctx context.Context, userNotification *types.UserNotification) error

UpdateUserNotification updates a user notification.

func (*Client) UpdateUserUsername

func (c *Client) UpdateUserUsername(ctx context.Context, input *types.UsernameUpdateInput) error

UpdateUserUsername updates a user's username.

func (*Client) UploadNewAvatar

func (c *Client) UploadNewAvatar(ctx context.Context, input *types.AvatarUpdateInput) error

UploadNewAvatar uploads a new avatar.

func (*Client) UserStatus

func (c *Client) UserStatus(ctx context.Context) (*types.UserStatusResponse, error)

UserStatus fetches a user's status.

func (*Client) VerifyTOTPSecret

func (c *Client) VerifyTOTPSecret(ctx context.Context, userID, token string) error

VerifyTOTPSecret verifies a 2FA secret.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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