sdingest

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package sdingest provides a typed client for the versioned SDIngest OpenAPI.

Index

Constants

View Source
const (
	CallbackHeaderEventID   = "X-SDIngest-Event-ID"
	CallbackHeaderTimestamp = "X-SDIngest-Timestamp"
	CallbackHeaderSignature = "X-SDIngest-Signature"

	CallbackEventManifestReady    = "job.manifest.ready"
	CallbackEventPhaseChanged     = "job.phase_changed"
	CallbackEventProgressChanged  = "job.progress_changed"
	CallbackEventStalled          = "job.stalled"
	CallbackEventRetrying         = "job.retrying"
	CallbackEventAccountWaiting   = "job.account.waiting"
	CallbackEventAccountRecovered = "job.account.recovered"
	CallbackEventTargetWaiting    = "job.target.waiting"
	CallbackEventTargetRecovered  = "job.target.recovered"
	CallbackEventSucceeded        = "job.succeeded"
	CallbackEventPartial          = "job.partial"
	CallbackEventFailed           = "job.failed"
	CallbackEventCanceled         = "job.canceled"
)
View Source
const (
	JobStatusPending   = "pending"
	JobStatusRunning   = "running"
	JobStatusWaiting   = "waiting"
	JobStatusPartial   = "partial"
	JobStatusSucceeded = "succeeded"
	JobStatusFailed    = "failed"
	JobStatusCanceled  = "canceled"
)
View Source
const (
	ManifestModeAuto   = "auto"
	ManifestModeManual = "manual"
)

Variables

View Source
var (
	ErrNilContext             = errors.New("sdingest: nil context")
	ErrInvalidConfig          = errors.New("sdingest: invalid client config")
	ErrIdempotencyKeyRequired = errors.New("sdingest: idempotency key is required")
	ErrInvalidCallback        = errors.New("sdingest: invalid callback")
	ErrCallbackSignature      = errors.New("sdingest: callback signature mismatch")
	ErrCallbackTimestamp      = errors.New("sdingest: callback timestamp is outside the allowed window")
)

Functions

func IsSubCode

func IsSubCode(err error, subCode string) bool

Types

type APIError

type APIError struct {
	StatusCode int
	Code       int
	SubCode    string
	Message    string
	Data       json.RawMessage
	RequestID  string
	RetryAfter time.Duration
}

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Retryable

func (e *APIError) Retryable() bool

type AppProfile

type AppProfile struct {
	AppID             string          `json:"app_id"`
	Name              string          `json:"name"`
	Status            string          `json:"status"`
	Scope             []string        `json:"scope"`
	RateLimit         int64           `json:"rate_limit"`
	JobLimit          int             `json:"job_limit"`
	ByteLimit         int64           `json:"byte_limit"`
	StorageMode       string          `json:"storage_mode"`
	DefaultTarget     json.RawMessage `json:"default_target,omitempty"`
	DefaultCallbackID string          `json:"default_callback_id,omitempty"`
	DefaultFilterID   string          `json:"default_filter_id,omitempty"`
	ExpiresAt         *time.Time      `json:"expires_at,omitempty"`
	CreatedAt         time.Time       `json:"created_at"`
	UpdatedAt         time.Time       `json:"updated_at"`
}

type Artifact

type Artifact struct {
	ArtifactID     string         `json:"artifact_id"`
	JobID          string         `json:"job_id"`
	ItemID         string         `json:"item_id"`
	TargetID       string         `json:"target_id"`
	TargetName     string         `json:"target_name"`
	TargetDriver   string         `json:"target_driver"`
	TargetEndpoint string         `json:"target_endpoint"`
	TargetBucket   string         `json:"target_bucket"`
	ObjectURI      string         `json:"object_uri"`
	Key            string         `json:"key"`
	Name           string         `json:"name"`
	Path           string         `json:"path"`
	MIME           string         `json:"mime,omitempty"`
	Size           int64          `json:"size"`
	Checksum       string         `json:"checksum,omitempty"`
	ETag           string         `json:"etag,omitempty"`
	Status         string         `json:"status"`
	AckAt          *time.Time     `json:"ack_at,omitempty"`
	ExpiresAt      *time.Time     `json:"expires_at,omitempty"`
	CreatedAt      time.Time      `json:"created_at"`
	Job            ArtifactJobRef `json:"job"`
}

type ArtifactAccess

type ArtifactAccess struct {
	ArtifactID string    `json:"artifact_id"`
	ObjectURI  string    `json:"object_uri"`
	URL        string    `json:"url"`
	ExpiresAt  time.Time `json:"expires_at"`
}

type ArtifactJobRef

type ArtifactJobRef struct {
	JobID       string     `json:"job_id"`
	SourceName  string     `json:"source_name,omitempty"`
	ExternalRef string     `json:"external_ref,omitempty"`
	Provider    string     `json:"provider"`
	Status      string     `json:"status"`
	Phase       string     `json:"phase"`
	CreatedAt   time.Time  `json:"created_at"`
	FinishedAt  *time.Time `json:"finished_at,omitempty"`
}

type Callback

type Callback struct {
	CallbackID string     `json:"callback_id"`
	AppID      string     `json:"app_id,omitempty"`
	Name       string     `json:"name"`
	URL        string     `json:"url"`
	Events     []string   `json:"events"`
	Status     string     `json:"status"`
	SecretVer  int64      `json:"secret_ver"`
	LastTestAt *time.Time `json:"last_test_at,omitempty"`
	Error      string     `json:"err,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
}

type CallbackCredential

type CallbackCredential struct {
	Callback
	SigningSecret string `json:"signing_secret"`
}

type CallbackData

type CallbackData struct {
	JobID         string            `json:"job_id"`
	ExternalRef   string            `json:"external_ref,omitempty"`
	Status        string            `json:"status"`
	Phase         string            `json:"phase"`
	Revision      int64             `json:"revision"`
	WaitingReason string            `json:"waiting_reason,omitempty"`
	ErrorCode     string            `json:"error_code,omitempty"`
	Progress      *CallbackProgress `json:"progress,omitempty"`
}

type CallbackEnvelope

type CallbackEnvelope struct {
	EventID   string       `json:"event_id"`
	Event     string       `json:"event"`
	Timestamp time.Time    `json:"timestamp"`
	Data      CallbackData `json:"data"`
}

func VerifyAndDecodeCallback

func VerifyAndDecodeCallback(header http.Header, body []byte, signingSecret string, now time.Time, tolerance time.Duration) (CallbackEnvelope, error)

type CallbackLog

type CallbackLog struct {
	EventID    string          `json:"event_id"`
	Event      string          `json:"event"`
	CallbackID string          `json:"callback_id"`
	JobID      string          `json:"job_id"`
	AttemptNo  int             `json:"attempt_no"`
	SecretVer  int64           `json:"secret_ver"`
	Status     string          `json:"status"`
	LatencyMS  int64           `json:"latency_ms"`
	NextAt     *time.Time      `json:"next_at,omitempty"`
	Error      string          `json:"err,omitempty"`
	Response   string          `json:"response,omitempty"`
	CreatedAt  time.Time       `json:"created_at"`
	Callback   json.RawMessage `json:"callback,omitempty"`
	Job        json.RawMessage `json:"job,omitempty"`
}

type CallbackProgress

type CallbackProgress struct {
	CurrentItemID string    `json:"current_item_id,omitempty"`
	DownBytes     int64     `json:"down_bytes"`
	UpBytes       int64     `json:"up_bytes"`
	TotalBytes    int64     `json:"total_bytes"`
	ItemTotal     int64     `json:"item_total"`
	ItemDone      int64     `json:"item_done"`
	ItemFailed    int64     `json:"item_failed"`
	IsAlive       bool      `json:"is_alive"`
	SnapshotAt    time.Time `json:"snapshot_at"`
}

type Client

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

func NewClient

func NewClient(config Config) (*Client, error)

func (*Client) AcknowledgeArtifact

func (c *Client) AcknowledgeArtifact(ctx context.Context, artifactID string, idempotencyKey string) (Artifact, error)

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context) (Token, error)

func (*Client) CancelJob

func (c *Client) CancelJob(ctx context.Context, jobID string, idempotencyKey string) (Job, error)

func (*Client) ConfirmJobManifest

func (c *Client) ConfirmJobManifest(ctx context.Context, jobID string, revision int64, hash string, idempotencyKey string) (Job, error)

func (*Client) ConfirmJobManifestSelection

func (c *Client) ConfirmJobManifestSelection(ctx context.Context, input ConfirmJobManifestInput, idempotencyKey string) (Job, error)

func (*Client) CreateCallback

func (c *Client) CreateCallback(ctx context.Context, input CreateCallbackInput, idempotencyKey string) (CallbackCredential, error)

func (*Client) CreateJob

func (c *Client) CreateJob(ctx context.Context, input CreateJobInput, idempotencyKey string) (Job, error)

func (*Client) DisableCallback

func (c *Client) DisableCallback(ctx context.Context, callbackID string, idempotencyKey string) error

func (*Client) EnableCallback

func (c *Client) EnableCallback(ctx context.Context, callbackID string, idempotencyKey string) error

func (*Client) GetAppProfile

func (c *Client) GetAppProfile(ctx context.Context) (AppProfile, error)

func (*Client) GetArtifact

func (c *Client) GetArtifact(ctx context.Context, artifactID string) (Artifact, error)

func (*Client) GetArtifactAccess

func (c *Client) GetArtifactAccess(ctx context.Context, artifactID string, ttl time.Duration) (ArtifactAccess, error)

func (*Client) GetCallback

func (c *Client) GetCallback(ctx context.Context, callbackID string) (Callback, error)

func (*Client) GetItemProgress

func (c *Client) GetItemProgress(ctx context.Context, jobID string, itemID string) (ItemProgress, error)

func (*Client) GetJob

func (c *Client) GetJob(ctx context.Context, jobID string) (Job, error)

func (*Client) GetJobManifest

func (c *Client) GetJobManifest(ctx context.Context, jobID string, page int, limit int) (ManifestPage, error)

func (*Client) GetJobProgress

func (c *Client) GetJobProgress(ctx context.Context, jobID string) (JobProgress, error)

func (*Client) ListArtifacts

func (c *Client) ListArtifacts(ctx context.Context, input ListArtifactsInput) (Page[Artifact], error)

func (*Client) ListCallbackLogs

func (c *Client) ListCallbackLogs(ctx context.Context, input ListCallbackLogsInput) (Page[CallbackLog], error)

func (*Client) ListCallbacks

func (c *Client) ListCallbacks(ctx context.Context, input ListCallbacksInput) (Page[Callback], error)

func (*Client) ListJobs

func (c *Client) ListJobs(ctx context.Context, input ListJobsInput) (Page[Job], error)

func (*Client) ReplayCallback

func (c *Client) ReplayCallback(ctx context.Context, eventID string, idempotencyKey string) error

func (*Client) RetryJob

func (c *Client) RetryJob(ctx context.Context, jobID string, idempotencyKey string) (Job, error)

func (*Client) RotateCallbackSecret

func (c *Client) RotateCallbackSecret(ctx context.Context, callbackID string, idempotencyKey string) (CallbackCredential, error)

type Config

type Config struct {
	BaseURL          string
	AppID            string
	AppSecret        string
	HTTPClient       HTTPDoer
	TokenSkew        time.Duration
	MaxResponseBytes int64
	UserAgent        string
	Clock            func() time.Time
}

type ConfirmJobManifestInput

type ConfirmJobManifestInput struct {
	JobID    string   `json:"job_id"`
	Revision int64    `json:"revision"`
	Hash     string   `json:"hash"`
	ItemIDs  []string `json:"item_ids,omitempty"`
}

type CreateCallbackInput

type CreateCallbackInput struct {
	Name   string   `json:"name"`
	URL    string   `json:"url"`
	Events []string `json:"events"`
}

type CreateJobInput

type CreateJobInput struct {
	ExternalRef  string     `json:"external_ref,omitempty"`
	Source       Source     `json:"source"`
	Filter       FileFilter `json:"filter,omitempty"`
	ManifestMode string     `json:"manifest_mode,omitempty"`
	TargetID     string     `json:"target_id,omitempty"`
	PoolID       string     `json:"pool_id,omitempty"`
	CallbackID   string     `json:"callback_id,omitempty"`
	FailPolicy   string     `json:"fail_policy,omitempty"`
	Priority     int16      `json:"priority,omitempty"`
}

type FileFilter

type FileFilter struct {
	IncludeExtensions []string `json:"include_extensions,omitempty"`
	ExcludeExtensions []string `json:"exclude_extensions,omitempty"`
	IncludeGlobs      []string `json:"include_globs,omitempty"`
	ExcludeGlobs      []string `json:"exclude_globs,omitempty"`
	MinSize           *int64   `json:"min_size,omitempty"`
	MaxSize           *int64   `json:"max_size,omitempty"`
	MaxFiles          *int64   `json:"max_files,omitempty"`
	MaxTotalBytes     *int64   `json:"max_total_bytes,omitempty"`
	MaxDepth          *int     `json:"max_depth,omitempty"`
}

type HTTPDoer

type HTTPDoer interface {
	Do(request *http.Request) (*http.Response, error)
}

type ItemProgress

type ItemProgress struct {
	JobID    string           `json:"job_id"`
	ItemID   string           `json:"item_id"`
	Source   string           `json:"source"`
	Status   string           `json:"status"`
	Phase    string           `json:"phase"`
	Download TransferProgress `json:"download"`
	Upload   TransferProgress `json:"upload"`
	Overall  TransferProgress `json:"overall"`
	Liveness Liveness         `json:"liveness"`
}

type Job

type Job struct {
	JobID          string          `json:"job_id"`
	SourceName     string          `json:"source_name,omitempty"`
	TargetID       string          `json:"target_id"`
	PoolID         string          `json:"pool_id,omitempty"`
	CallbackID     string          `json:"callback_id,omitempty"`
	ExternalRef    string          `json:"external_ref,omitempty"`
	Provider       string          `json:"provider"`
	SourceMode     string          `json:"source_mode"`
	ManifestMode   string          `json:"manifest_mode"`
	Filter         FileFilter      `json:"filter"`
	FailPolicy     string          `json:"fail_policy"`
	Priority       int16           `json:"priority"`
	Status         string          `json:"status"`
	Phase          string          `json:"phase"`
	WaitingReason  string          `json:"waiting_reason,omitempty"`
	Revision       int64           `json:"revision"`
	ItemTotal      int64           `json:"item_total"`
	ItemDone       int64           `json:"item_done"`
	ItemFailed     int64           `json:"item_failed"`
	TotalBytes     int64           `json:"total_bytes"`
	DownBytes      int64           `json:"down_bytes"`
	UpBytes        int64           `json:"up_bytes"`
	HeartbeatAt    *time.Time      `json:"heartbeat_at,omitempty"`
	LastProgressAt *time.Time      `json:"last_progress_at,omitempty"`
	NextRetryAt    *time.Time      `json:"next_retry_at,omitempty"`
	CancelAt       *time.Time      `json:"cancel_at,omitempty"`
	ErrorCode      string          `json:"err_code,omitempty"`
	ErrorMessage   string          `json:"err_msg,omitempty"`
	StartedAt      *time.Time      `json:"started_at,omitempty"`
	FinishedAt     *time.Time      `json:"finished_at,omitempty"`
	CreatedAt      time.Time       `json:"created_at"`
	UpdatedAt      time.Time       `json:"updated_at"`
	App            JobAppRef       `json:"app"`
	Target         JobTargetRef    `json:"target"`
	Pool           *JobPoolRef     `json:"pool,omitempty"`
	Source         *Source         `json:"source,omitempty"`
	Raw            json.RawMessage `json:"-"`
}

func (Job) Terminal

func (j Job) Terminal() bool

type JobAppRef

type JobAppRef struct {
	AppID string `json:"app_id"`
	Name  string `json:"name"`
}

type JobPoolRef

type JobPoolRef struct {
	PoolID   string `json:"pool_id"`
	Name     string `json:"name"`
	Provider string `json:"provider"`
}

type JobProgress

type JobProgress struct {
	JobID            string           `json:"job_id"`
	CurrentItemID    string           `json:"current_item_id,omitempty"`
	CurrentAttemptID string           `json:"current_attempt_id,omitempty"`
	Source           string           `json:"source"`
	Status           string           `json:"status"`
	Phase            string           `json:"phase"`
	ItemTotal        int64            `json:"item_total"`
	ItemDone         int64            `json:"item_done"`
	ItemFailed       int64            `json:"item_failed"`
	Download         TransferProgress `json:"download"`
	Upload           TransferProgress `json:"upload"`
	Overall          TransferProgress `json:"overall"`
	Liveness         Liveness         `json:"liveness"`
}

func (JobProgress) Terminal

func (p JobProgress) Terminal() bool

type JobTargetRef

type JobTargetRef struct {
	TargetID string `json:"target_id"`
	Name     string `json:"name"`
	Driver   string `json:"driver"`
	Bucket   string `json:"bucket"`
	Prefix   string `json:"prefix,omitempty"`
}

type ListArtifactsInput

type ListArtifactsInput struct {
	Page   int
	Limit  int
	JobID  string
	Status string
}

type ListCallbackLogsInput

type ListCallbackLogsInput struct {
	Page       int
	Limit      int
	CallbackID string
	JobID      string
	Status     string
}

type ListCallbacksInput

type ListCallbacksInput struct {
	Page   int
	Limit  int
	Status string
	Search string
}

type ListJobsInput

type ListJobsInput struct {
	Page         int
	Limit        int
	Provider     string
	ManifestMode string
	Status       string
	Phase        string
	ExternalRef  string
	Search       string
}

type Liveness

type Liveness struct {
	State             string     `json:"state"`
	IsAlive           bool       `json:"is_alive"`
	AttemptID         string     `json:"attempt_id,omitempty"`
	WorkerID          string     `json:"worker_id,omitempty"`
	NodeID            string     `json:"node_id,omitempty"`
	HeartbeatAt       *time.Time `json:"heartbeat_at,omitempty"`
	StateChangedAt    *time.Time `json:"state_changed_at,omitempty"`
	LastProgressAt    *time.Time `json:"last_progress_at,omitempty"`
	NoProgressSeconds int64      `json:"no_progress_seconds"`
	SnapshotRevision  int64      `json:"snapshot_revision"`
}

type Manifest

type Manifest struct {
	JobID       string          `json:"job_id"`
	Revision    int64           `json:"revision"`
	Hash        string          `json:"hash"`
	Filter      json.RawMessage `json:"filter"`
	Status      string          `json:"status"`
	ItemCount   int64           `json:"item_count"`
	TotalBytes  int64           `json:"total_bytes"`
	ExpiresAt   *time.Time      `json:"expires_at,omitempty"`
	ConfirmedAt *time.Time      `json:"confirmed_at,omitempty"`
	CreatedAt   time.Time       `json:"created_at"`
}

type ManifestItem

type ManifestItem struct {
	ItemID     string          `json:"item_id"`
	ArtifactID string          `json:"artifact_id,omitempty"`
	Path       string          `json:"path"`
	Name       string          `json:"name"`
	Size       int64           `json:"size"`
	MTime      *time.Time      `json:"mtime,omitempty"`
	Checksum   string          `json:"checksum,omitempty"`
	Selected   bool            `json:"selected"`
	SkipReason string          `json:"skip_reason,omitempty"`
	Status     string          `json:"status"`
	Phase      string          `json:"phase"`
	LocalSize  int64           `json:"local_size"`
	MIME       string          `json:"mime,omitempty"`
	HashType   string          `json:"hash_type,omitempty"`
	HashValue  string          `json:"hash_value,omitempty"`
	Media      json.RawMessage `json:"media,omitempty"`
	DownBytes  int64           `json:"down_bytes"`
	UpBytes    int64           `json:"up_bytes"`
	ErrorCode  string          `json:"err_code,omitempty"`
	ErrorMsg   string          `json:"err_msg,omitempty"`
	StartedAt  *time.Time      `json:"started_at,omitempty"`
	FinishedAt *time.Time      `json:"finished_at,omitempty"`
}

type ManifestPage

type ManifestPage struct {
	Manifest Manifest       `json:"manifest"`
	Items    []ManifestItem `json:"items"`
	Total    int64          `json:"total"`
}

type Page

type Page[T any] struct {
	List  []T   `json:"list"`
	Total int64 `json:"total"`
}

type ProtocolError

type ProtocolError struct {
	StatusCode int
	RequestID  string
	Err        error
}

func (*ProtocolError) Error

func (e *ProtocolError) Error() string

func (*ProtocolError) Unwrap

func (e *ProtocolError) Unwrap() error

type Source

type Source struct {
	Mode     string `json:"mode"`
	Provider string `json:"provider,omitempty"`
	URL      string `json:"url,omitempty"`
	Password string `json:"password,omitempty"`
	Profile  string `json:"profile,omitempty"`
	Path     string `json:"path,omitempty"`
}

type Token

type Token struct {
	AccessToken string   `json:"access_token"`
	TokenType   string   `json:"token_type"`
	ExpiresIn   int64    `json:"expires_in"`
	Scope       []string `json:"scope"`
	// contains filtered or unexported fields
}

type TransferProgress

type TransferProgress struct {
	TransferredBytes int64      `json:"transferred_bytes"`
	TotalBytes       int64      `json:"total_bytes"`
	Percent          *float64   `json:"percent"`
	BytesPerSecond   int64      `json:"bytes_per_second"`
	StartedAt        *time.Time `json:"started_at,omitempty"`
	LastProgressAt   *time.Time `json:"last_progress_at,omitempty"`
}

Jump to

Keyboard shortcuts

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