Documentation
¶
Overview ¶
Package cloud contains API clients for Mocklet cloud services.
Index ¶
- Variables
- func IsKind(err error, kind ErrorKind) bool
- type AuthClient
- func (c *AuthClient) ExchangeGoogleCLI(ctx context.Context, oneTimeCode string) (GoogleCLIExchange, error)
- func (c *AuthClient) Login(ctx context.Context, email, password string) (LoginResult, error)
- func (c *AuthClient) StartGoogleCLI(ctx context.Context) (GoogleCLIStart, error)
- func (c *AuthClient) WhoAmI(ctx context.Context) (UserIdentity, error)
- type ClientConfig
- type CreateMockFileOptions
- type CreateMockRawOptions
- type CreateMockResult
- type CreateTemplateFileOptions
- type CreateTemplateOptions
- type DomainMockInfo
- type Error
- type ErrorKind
- type GoogleCLIExchange
- type GoogleCLIStart
- type ListMocksOptions
- type ListMocksResult
- type LoginResult
- type ManagementClient
- func (c *ManagementClient) CreateMockFile(ctx context.Context, path string, options CreateMockFileOptions) (CreateMockResult, error)
- func (c *ManagementClient) CreateMockRaw(ctx context.Context, payload []byte, options CreateMockRawOptions) (CreateMockResult, error)
- func (c *ManagementClient) CreateServiceToken(ctx context.Context, serviceUserID int, name string, expiresInSeconds int) (ServiceTokenCreateResult, error)
- func (c *ManagementClient) CreateServiceUser(ctx context.Context, name, description string) (ServiceUser, error)
- func (c *ManagementClient) CreateTemplate(ctx context.Context, options CreateTemplateOptions) (TemplateSummary, error)
- func (c *ManagementClient) CreateTemplateFile(ctx context.Context, path string, options CreateTemplateFileOptions) (TemplateSummary, error)
- func (c *ManagementClient) DeleteMock(ctx context.Context, mockID string) error
- func (c *ManagementClient) DeleteTemplate(ctx context.Context, templateID string) error
- func (c *ManagementClient) DownloadTemplateHar(ctx context.Context, templateID string) (TemplateArtifact, error)
- func (c *ManagementClient) DownloadTemplateOpenAPI(ctx context.Context, templateID string, format string) (TemplateArtifact, error)
- func (c *ManagementClient) DownloadTemplateOpenAPIByVersion(ctx context.Context, templateID string, version int, format string) (TemplateArtifact, error)
- func (c *ManagementClient) DownloadTemplatePostman(ctx context.Context, templateID string) (TemplateArtifact, error)
- func (c *ManagementClient) GetMock(ctx context.Context, mockID string) (MockSummary, error)
- func (c *ManagementClient) GetMockStats(ctx context.Context, mockID string, historyLimit *int) (*openapi.MockStatsResponse, error)
- func (c *ManagementClient) GetTemplate(ctx context.Context, templateID string) (TemplateSummary, error)
- func (c *ManagementClient) GetTemplateDocs(ctx context.Context, templateID string) (TemplateArtifact, error)
- func (c *ManagementClient) ListMocks(ctx context.Context, options ListMocksOptions) (ListMocksResult, error)
- func (c *ManagementClient) ListServiceTokens(ctx context.Context, serviceUserID int, limit *int) ([]ServiceToken, error)
- func (c *ManagementClient) ListServiceUsers(ctx context.Context, limit *int) ([]ServiceUser, error)
- func (c *ManagementClient) ListTemplateRevisions(ctx context.Context, templateID string) ([]TemplateRevision, error)
- func (c *ManagementClient) ListTemplates(ctx context.Context, limit *int) ([]TemplateSummary, error)
- func (c *ManagementClient) RestartMock(ctx context.Context, mockID string) (RestartMockResult, error)
- func (c *ManagementClient) RevokeServiceToken(ctx context.Context, serviceUserID int, tokenID int) error
- func (c *ManagementClient) SpawnMockFromTemplate(ctx context.Context, templateID string, options SpawnMockFromTemplateOptions) (CreateMockResult, error)
- func (c *ManagementClient) UpdateTemplate(ctx context.Context, templateID string, options UpdateTemplateOptions) (TemplateSummary, error)
- func (c *ManagementClient) UploadTemplateRevision(ctx context.Context, templateID string, payload []byte) (TemplateRevision, error)
- func (c *ManagementClient) UploadTemplateRevisionFile(ctx context.Context, templateID string, path string) (TemplateRevision, error)
- func (c *ManagementClient) ValidateHARFile(ctx context.Context, path string) (*openapi.HarValidationResult, error)
- func (c *ManagementClient) ValidateHARRaw(ctx context.Context, payload openapi.HarDocument) (*openapi.HarValidationResult, error)
- func (c *ManagementClient) ValidateHARRawBytes(ctx context.Context, payload []byte) (*openapi.HarValidationResult, error)
- type MockSummary
- type RestartMockResult
- type ServiceToken
- type ServiceTokenCreateResult
- type ServiceUser
- type SpawnMockFromTemplateOptions
- type TemplateArtifact
- type TemplateCurrentRevision
- type TemplateRevision
- type TemplateSummary
- type UpdateTemplateOptions
- type UserIdentity
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBaseURLRequired indicates that the cloud client was initialized without a base URL. ErrBaseURLRequired = errors.New("base URL is required") // ErrHarPayloadRequired indicates that a HAR payload was expected but not provided. ErrHarPayloadRequired = errors.New("har payload is required") // ErrTTLRequired indicates that a positive TTL value was expected. ErrTTLRequired = errors.New("ttl_seconds must be greater than zero") // ErrNameRequired indicates that a name field was expected but not provided. ErrNameRequired = errors.New("name is required") // ErrServiceUserIDRequired indicates that a positive service user ID was expected. ErrServiceUserIDRequired = errors.New("service_user_id must be greater than zero") // ErrTokenIDRequired indicates that a positive token ID was expected. ErrTokenIDRequired = errors.New("token_id must be greater than zero") // ErrTemplateIDRequired indicates that a non-empty template identifier was expected. ErrTemplateIDRequired = errors.New("template_id is required") // ErrTemplateRevisionVersionRequired indicates that a positive template revision version was expected. ErrTemplateRevisionVersionRequired = errors.New("template revision version must be greater than zero") // ErrHarPayloadInvalidJSON indicates that the HAR payload is not valid JSON. ErrHarPayloadInvalidJSON = errors.New("har payload must be valid JSON") // ErrMatchingRulesInvalidJSON indicates that the matching rules payload is not valid JSON. ErrMatchingRulesInvalidJSON = errors.New("matching_rules payload must be valid JSON") // ErrFilePathRequired indicates that a file path was expected but not provided. ErrFilePathRequired = errors.New("file path is required") // ErrJSONPayloadEmpty indicates that a JSON payload part is empty. ErrJSONPayloadEmpty = errors.New("json payload part cannot be empty") // ErrJSONPayloadInvalid indicates that a JSON payload part is not valid JSON. ErrJSONPayloadInvalid = errors.New("json payload part must be valid JSON") // ErrJSONFieldNameRequired indicates that a JSON field name was expected but not provided. ErrJSONFieldNameRequired = errors.New("json field name is required") )
Functions ¶
Types ¶
type AuthClient ¶
type AuthClient struct {
// contains filtered or unexported fields
}
AuthClient is a thin wrapper around auth endpoints.
func NewAuthClient ¶
func NewAuthClient(cfg ClientConfig) (*AuthClient, error)
NewAuthClient constructs an auth client from transport config.
func NewAuthClientWithGeneratedClient ¶
func NewAuthClientWithGeneratedClient(client openapi.ClientWithResponsesInterface) *AuthClient
NewAuthClientWithGeneratedClient wires an already constructed generated client.
func (*AuthClient) ExchangeGoogleCLI ¶
func (c *AuthClient) ExchangeGoogleCLI(ctx context.Context, oneTimeCode string) (GoogleCLIExchange, error)
ExchangeGoogleCLI exchanges one-time-code polling state for final token.
func (*AuthClient) Login ¶
func (c *AuthClient) Login(ctx context.Context, email, password string) (LoginResult, error)
Login authenticates a user using email/password credentials.
func (*AuthClient) StartGoogleCLI ¶
func (c *AuthClient) StartGoogleCLI(ctx context.Context) (GoogleCLIStart, error)
StartGoogleCLI starts one-time-code OAuth flow.
func (*AuthClient) WhoAmI ¶
func (c *AuthClient) WhoAmI(ctx context.Context) (UserIdentity, error)
WhoAmI returns identity information for the current token.
type ClientConfig ¶
type ClientConfig struct {
BaseURL string
Token string
RequestID string
Timeout time.Duration
UserAgent string
HTTPClient *http.Client
}
ClientConfig controls HTTP transport and request metadata.
type CreateMockFileOptions ¶
type CreateMockFileOptions struct {
TTLSeconds int
SSLEnabled *bool
LatencyEmulation *bool
ReplaceLinks *bool
CrossDomainMainDomain *string
MatchingRulesRaw []byte
}
CreateMockFileOptions defines parameters for multipart mock creation.
type CreateMockRawOptions ¶
type CreateMockRawOptions struct {
TTLSeconds int
SSLEnabled *bool
LatencyEmulation *bool
ReplaceLinks *bool
CrossDomainMainDomain *string
MatchingRulesRaw []byte
}
CreateMockRawOptions defines parameters for raw JSON mock creation.
type CreateMockResult ¶
type CreateMockResult struct {
MockID string
BaseURL string
ExpiresAt *time.Time
HarSizeBytes *int
TTLSeconds *int
SSLEnabled *bool
LatencyEmulation *bool
DomainMap []DomainMockInfo
}
CreateMockResult is a normalized creation response.
type CreateTemplateFileOptions ¶ added in v0.1.6
type CreateTemplateFileOptions struct {
Name string
Description *string
DefaultTTLSeconds *int
DefaultSSLEnabled *bool
DefaultLatencyEmulation *bool
}
CreateTemplateFileOptions defines fields for multipart template creation.
type CreateTemplateOptions ¶ added in v0.1.6
type CreateTemplateOptions struct {
Name string
Description *string
DefaultTTLSeconds *int
DefaultSSLEnabled *bool
DefaultLatencyEmulation *bool
HARPayload []byte
}
CreateTemplateOptions defines fields for raw JSON template creation.
type DomainMockInfo ¶
DomainMockInfo describes one domain-specific mock entry from cross-domain mode.
type ErrorKind ¶
type ErrorKind string
ErrorKind identifies the category of a cloud error for mapping to CLI exit codes.
const ( ErrorKindAuth ErrorKind = "auth" ErrorKindValidation ErrorKind = "validation" ErrorKindConflict ErrorKind = "conflict" ErrorKindNotFound ErrorKind = "not found" ErrorKindRateLimit ErrorKind = "rate limit" ErrorKindTimeout ErrorKind = "timeout" ErrorKindNetwork ErrorKind = "network" ErrorKindServer ErrorKind = "server" )
type GoogleCLIExchange ¶
type GoogleCLIExchange struct {
Pending bool
RetryAfterSeconds int
Login *LoginResult
}
GoogleCLIExchange reports either a pending poll or final login response.
type GoogleCLIStart ¶
type GoogleCLIStart struct {
OneTimeCode string
AuthorizationURL string
IntervalSeconds int
ExpiresAt string
}
GoogleCLIStart is a normalized start response for one-time-code OAuth.
type ListMocksOptions ¶
ListMocksOptions configures list endpoint query parameters.
type ListMocksResult ¶
type ListMocksResult struct {
Items []MockSummary
NextCursor string
Totals *openapi.UserTotals
}
ListMocksResult is a normalized list response.
type LoginResult ¶
LoginResult is an internal auth login model independent from generated response envelopes.
type ManagementClient ¶
type ManagementClient struct {
// contains filtered or unexported fields
}
ManagementClient is a thin wrapper around management endpoints.
func NewManagementClient ¶
func NewManagementClient(cfg ClientConfig) (*ManagementClient, error)
NewManagementClient constructs a management client from transport config.
func NewManagementClientWithGeneratedClient ¶
func NewManagementClientWithGeneratedClient(client openapi.ClientWithResponsesInterface) *ManagementClient
NewManagementClientWithGeneratedClient wires an existing generated client.
func (*ManagementClient) CreateMockFile ¶
func (c *ManagementClient) CreateMockFile(ctx context.Context, path string, options CreateMockFileOptions) (CreateMockResult, error)
CreateMockFile uploads HAR file and creates a mock.
func (*ManagementClient) CreateMockRaw ¶
func (c *ManagementClient) CreateMockRaw(ctx context.Context, payload []byte, options CreateMockRawOptions) (CreateMockResult, error)
CreateMockRaw creates a mock using raw JSON HAR payload.
func (*ManagementClient) CreateServiceToken ¶ added in v0.1.6
func (c *ManagementClient) CreateServiceToken(ctx context.Context, serviceUserID int, name string, expiresInSeconds int) (ServiceTokenCreateResult, error)
CreateServiceToken creates one token and returns one-time raw token value.
func (*ManagementClient) CreateServiceUser ¶ added in v0.1.6
func (c *ManagementClient) CreateServiceUser(ctx context.Context, name, description string) (ServiceUser, error)
CreateServiceUser creates one service user under authenticated account.
func (*ManagementClient) CreateTemplate ¶ added in v0.1.6
func (c *ManagementClient) CreateTemplate(ctx context.Context, options CreateTemplateOptions) (TemplateSummary, error)
CreateTemplate creates a template from raw HAR JSON.
func (*ManagementClient) CreateTemplateFile ¶ added in v0.1.6
func (c *ManagementClient) CreateTemplateFile(ctx context.Context, path string, options CreateTemplateFileOptions) (TemplateSummary, error)
CreateTemplateFile creates a template from a HAR file.
func (*ManagementClient) DeleteMock ¶
func (c *ManagementClient) DeleteMock(ctx context.Context, mockID string) error
DeleteMock removes mock by id.
func (*ManagementClient) DeleteTemplate ¶ added in v0.1.6
func (c *ManagementClient) DeleteTemplate(ctx context.Context, templateID string) error
DeleteTemplate removes one template by id.
func (*ManagementClient) DownloadTemplateHar ¶ added in v0.1.6
func (c *ManagementClient) DownloadTemplateHar(ctx context.Context, templateID string) (TemplateArtifact, error)
DownloadTemplateHar downloads the current HAR snapshot for one template.
func (*ManagementClient) DownloadTemplateOpenAPI ¶ added in v0.1.6
func (c *ManagementClient) DownloadTemplateOpenAPI(ctx context.Context, templateID string, format string) (TemplateArtifact, error)
DownloadTemplateOpenAPI downloads the current generated OpenAPI document.
func (*ManagementClient) DownloadTemplateOpenAPIByVersion ¶ added in v0.1.6
func (c *ManagementClient) DownloadTemplateOpenAPIByVersion(ctx context.Context, templateID string, version int, format string) (TemplateArtifact, error)
DownloadTemplateOpenAPIByVersion downloads generated OpenAPI for one revision version.
func (*ManagementClient) DownloadTemplatePostman ¶ added in v0.1.6
func (c *ManagementClient) DownloadTemplatePostman(ctx context.Context, templateID string) (TemplateArtifact, error)
DownloadTemplatePostman downloads the generated Postman collection.
func (*ManagementClient) GetMock ¶
func (c *ManagementClient) GetMock(ctx context.Context, mockID string) (MockSummary, error)
GetMock returns one mock by id.
func (*ManagementClient) GetMockStats ¶
func (c *ManagementClient) GetMockStats(ctx context.Context, mockID string, historyLimit *int) (*openapi.MockStatsResponse, error)
GetMockStats returns full mock stats payload.
func (*ManagementClient) GetTemplate ¶ added in v0.1.6
func (c *ManagementClient) GetTemplate(ctx context.Context, templateID string) (TemplateSummary, error)
GetTemplate returns one template by id.
func (*ManagementClient) GetTemplateDocs ¶ added in v0.1.6
func (c *ManagementClient) GetTemplateDocs(ctx context.Context, templateID string) (TemplateArtifact, error)
GetTemplateDocs downloads the rendered HTML documentation page.
func (*ManagementClient) ListMocks ¶
func (c *ManagementClient) ListMocks(ctx context.Context, options ListMocksOptions) (ListMocksResult, error)
ListMocks returns normalized mock summaries.
func (*ManagementClient) ListServiceTokens ¶ added in v0.1.6
func (c *ManagementClient) ListServiceTokens(ctx context.Context, serviceUserID int, limit *int) ([]ServiceToken, error)
ListServiceTokens returns tokens for one service user.
func (*ManagementClient) ListServiceUsers ¶ added in v0.1.6
func (c *ManagementClient) ListServiceUsers(ctx context.Context, limit *int) ([]ServiceUser, error)
ListServiceUsers returns service users owned by authenticated account.
func (*ManagementClient) ListTemplateRevisions ¶ added in v0.1.6
func (c *ManagementClient) ListTemplateRevisions(ctx context.Context, templateID string) ([]TemplateRevision, error)
ListTemplateRevisions returns revision history for one template.
func (*ManagementClient) ListTemplates ¶ added in v0.1.6
func (c *ManagementClient) ListTemplates(ctx context.Context, limit *int) ([]TemplateSummary, error)
ListTemplates returns templates owned by the authenticated caller.
func (*ManagementClient) RestartMock ¶
func (c *ManagementClient) RestartMock(ctx context.Context, mockID string) (RestartMockResult, error)
RestartMock resets sequence state for a mock.
func (*ManagementClient) RevokeServiceToken ¶ added in v0.1.6
func (c *ManagementClient) RevokeServiceToken(ctx context.Context, serviceUserID int, tokenID int) error
RevokeServiceToken revokes one token for one service user.
func (*ManagementClient) SpawnMockFromTemplate ¶ added in v0.1.6
func (c *ManagementClient) SpawnMockFromTemplate(ctx context.Context, templateID string, options SpawnMockFromTemplateOptions) (CreateMockResult, error)
SpawnMockFromTemplate materializes one template into a runtime mock.
func (*ManagementClient) UpdateTemplate ¶ added in v0.1.6
func (c *ManagementClient) UpdateTemplate(ctx context.Context, templateID string, options UpdateTemplateOptions) (TemplateSummary, error)
UpdateTemplate patches mutable template fields.
func (*ManagementClient) UploadTemplateRevision ¶ added in v0.1.6
func (c *ManagementClient) UploadTemplateRevision(ctx context.Context, templateID string, payload []byte) (TemplateRevision, error)
UploadTemplateRevision uploads a new revision from raw HAR JSON.
func (*ManagementClient) UploadTemplateRevisionFile ¶ added in v0.1.6
func (c *ManagementClient) UploadTemplateRevisionFile(ctx context.Context, templateID string, path string) (TemplateRevision, error)
UploadTemplateRevisionFile uploads a new revision from a HAR file.
func (*ManagementClient) ValidateHARFile ¶
func (c *ManagementClient) ValidateHARFile(ctx context.Context, path string) (*openapi.HarValidationResult, error)
ValidateHARFile validates a HAR file upload.
func (*ManagementClient) ValidateHARRaw ¶
func (c *ManagementClient) ValidateHARRaw(ctx context.Context, payload openapi.HarDocument) (*openapi.HarValidationResult, error)
ValidateHARRaw validates HAR JSON payload.
func (*ManagementClient) ValidateHARRawBytes ¶
func (c *ManagementClient) ValidateHARRawBytes(ctx context.Context, payload []byte) (*openapi.HarValidationResult, error)
ValidateHARRawBytes validates HAR JSON payload provided as raw bytes.
type MockSummary ¶
type MockSummary struct {
MockID string
BaseURL string
Status string
CreatedAt *time.Time
ExpiresAt *time.Time
LastSeenAt *time.Time
ParentMockID *string
RequestsHit *int
RequestsMiss *int
RequestsTotal *int
HarSizeBytes *int
TTLSeconds *int
SSLEnabled *bool
LatencyEmulation *bool
}
MockSummary is an internal representation for list/get outputs.
type RestartMockResult ¶
RestartMockResult represents restart endpoint payload.
type ServiceToken ¶ added in v0.1.6
type ServiceToken struct {
TokenID int
ServiceUserID int
Name string
TokenPrefix string
Status string
ExpiresAt *time.Time
RevokedAt *time.Time
LastUsedAt *time.Time
CreatedAt *time.Time
}
ServiceToken is a normalized service token metadata payload.
type ServiceTokenCreateResult ¶ added in v0.1.6
type ServiceTokenCreateResult struct {
ServiceToken
Token string
}
ServiceTokenCreateResult contains metadata together with one-time raw token.
type ServiceUser ¶ added in v0.1.6
ServiceUser is a normalized service user metadata payload.
type SpawnMockFromTemplateOptions ¶ added in v0.1.6
type SpawnMockFromTemplateOptions struct {
TTLSeconds *int
SSLEnabled *bool
LatencyEmulation *bool
}
SpawnMockFromTemplateOptions defines spawn overrides.
type TemplateArtifact ¶ added in v0.1.6
TemplateArtifact is a raw downloadable template payload.
type TemplateCurrentRevision ¶ added in v0.1.6
type TemplateCurrentRevision struct {
ID string
Version *int
EntriesTotal *int
EndpointsTotal *int
CreatedAt *time.Time
}
TemplateCurrentRevision is the current revision metadata embedded in template details.
type TemplateRevision ¶ added in v0.1.6
type TemplateRevision struct {
ID string
Version *int
EntriesTotal *int
EndpointsTotal *int
CreatedAt *time.Time
}
TemplateRevision is a normalized template revision payload.
type TemplateSummary ¶ added in v0.1.6
type TemplateSummary struct {
ID string
Name string
Description *string
DefaultTTLSeconds *int
DefaultSSLEnabled *bool
DefaultLatencyEmulation *bool
DocsPublic *bool
CreatedAt *time.Time
UpdatedAt *time.Time
CurrentRevision *TemplateCurrentRevision
}
TemplateSummary is a normalized template payload.
type UpdateTemplateOptions ¶ added in v0.1.6
type UpdateTemplateOptions struct {
Name *string
Description *string
DefaultTTLSeconds *int
DefaultSSLEnabled *bool
DefaultLatencyEmulation *bool
DocsPublic *bool
}
UpdateTemplateOptions defines mutable template fields.
type UserIdentity ¶
UserIdentity is a normalized auth/me response.