cloud

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cloud contains API clients for Mocklet cloud services.

Index

Constants

This section is empty.

Variables

View Source
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

func IsKind

func IsKind(err error, kind ErrorKind) bool

IsKind checks if an error belongs to a specific kind.

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

type DomainMockInfo struct {
	OriginalDomain string
	MockID         string
	BaseURL        string
	IsMain         bool
}

DomainMockInfo describes one domain-specific mock entry from cross-domain mode.

type Error

type Error struct {
	Kind    ErrorKind
	Message string
}

Error is a structured cloud error.

func (*Error) Error

func (e *Error) Error() string

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

type ListMocksOptions struct {
	Limit  *int
	Cursor *string
}

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

type LoginResult struct {
	Token     string
	Email     string
	UserID    int
	ExpiresAt int64
}

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

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

type RestartMockResult struct {
	MockID string
	Status string
}

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

type ServiceUser struct {
	ServiceUserID int
	Name          string
	Description   *string
	CreatedAt     *time.Time
}

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

type TemplateArtifact struct {
	Body        []byte
	ContentType string
}

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

type UserIdentity struct {
	Email  string
	UserID int
}

UserIdentity is a normalized auth/me response.

Directories

Path Synopsis
Package openapi provides primitives to interact with the openapi HTTP API.
Package openapi provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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