syftsdk

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AutoDetectWorkers = 0
	DefaultWorkers    = 8
)
View Source
const (
	RetryInterval        = 5 * time.Second
	TokenRefreshInterval = 24 * time.Hour
)
View Source
const (
	HeaderUserAgent    = "User-Agent"
	HeaderSyftVersion  = "X-Syft-Version"
	HeaderSyftUser     = "X-Syft-User"
	HeaderSyftDeviceId = "X-Syft-Device-Id"
)
View Source
const (
	DefaultBaseURL = "https://syftbox.net"
)

Variables

View Source
var (
	// ErrEventsNotConnected is returned when trying to use events without an active connection
	ErrEventsNotConnected = errors.New("sdk: events: not connected")
	// ErrEventsMessageQueueFull is returned when the message queue is full
	ErrEventsMessageQueueFull = errors.New("sdk: events: message queue full")
)
View Source
var (
	ErrNoRefreshToken = errors.New("sdk: refresh token missing")
	ErrNoServerURL    = errors.New("sdk: server url missing")
	ErrInvalidEmail   = errors.New("sdk: invalid email")
)

sdk common

View Source
var (
	ErrInvalidOTP = errors.New("sdk: invalid otp")
)

auth

View Source
var (
	ErrNoPermissions = errors.New("no permissions")
)

blob

Functions

func IsValidOTP

func IsValidOTP(otp string) bool

func UploadPresigned

func UploadPresigned(ctx context.Context, url string, path string, callback ProgressCallback) (*http.Response, error)

Upload a file to a presigned url

func VerifyEmail

func VerifyEmail(ctx context.Context, serverURL string, email string) error

VerifyEmail starts the Email verification flow by requesting a one-time password (OTP) from the server.

Types

type AuthClaims

type AuthClaims struct {
	Type AuthTokenType `json:"type"`
	jwt.RegisteredClaims
}

func (*AuthClaims) Validate

func (c *AuthClaims) Validate(email string, issuer string) error

type AuthTokenResponse

type AuthTokenResponse struct {
	AccessToken  string `json:"accessToken"`
	RefreshToken string `json:"refreshToken"`
}

func RefreshAuthTokens

func RefreshAuthTokens(ctx context.Context, serverURL string, refreshToken string) (*AuthTokenResponse, error)

func VerifyEmailCode

func VerifyEmailCode(ctx context.Context, serverURL string, codeReq *VerifyEmailCodeRequest) (*AuthTokenResponse, error)

type AuthTokenType

type AuthTokenType string
const (
	AccessToken  AuthTokenType = "access"
	RefreshToken AuthTokenType = "refresh"
)

type BlobAPI

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

func (*BlobAPI) Delete

func (b *BlobAPI) Delete(ctx context.Context, params *DeleteParams) (*DeleteResponse, error)

Delete deletes multiple blobs

func (*BlobAPI) DownloadPresigned

func (b *BlobAPI) DownloadPresigned(ctx context.Context, params *PresignedParams) (*PresignedResponse, error)

DownloadPresigned gets presigned URLs for downloading multiple blobs

func (*BlobAPI) Upload

func (b *BlobAPI) Upload(ctx context.Context, params *UploadParams) (*UploadResponse, error)

Upload uploads a file to the blob storage

func (*BlobAPI) UploadPresigned

func (b *BlobAPI) UploadPresigned(ctx context.Context, params *PresignedParams) (*PresignedResponse, error)

UploadPresigned gets presigned URLs for uploading multiple blobs

type BlobError

type BlobError struct {
	Key   string `json:"key"`
	Error string `json:"error"`
}

BlobError represents an error for a specific blob operation

type BlobInfo

type BlobInfo struct {
	Key          string    `json:"key"`
	ETag         string    `json:"etag"`
	Size         int       `json:"size"`
	LastModified time.Time `json:"lastModified"`
}

BlobInfo represents information about a blob

type BlobUrl

type BlobUrl struct {
	Key string `json:"key"`
	URL string `json:"url"`
}

BlobUrl represents a presigned URL for a blob

type DatasiteAPI

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

func (*DatasiteAPI) GetView

type DatasiteViewParams

type DatasiteViewParams struct {
}

DataSiteViewInput represents the input parameters for the datasite view API

type DatasiteViewResponse

type DatasiteViewResponse struct {
	Files []BlobInfo `json:"files"`
}

DataSiteViewOutput represents the output from the datasite view API

type DeleteParams

type DeleteParams struct {
	Keys []string `json:"keys"`
}

DeleteParams represents the parameters for deleting blobs

type DeleteResponse

type DeleteResponse struct {
	Deleted []string     `json:"deleted"`
	Errors  []*BlobError `json:"errors"`
}

DeleteResponse represents the response from a blob delete operation

type DownloadFileParams

type DownloadFileParams struct {
	User string   `json:"user"`
	Keys []string `json:"keys"`
}

DownloadFileParams represents the parameters for downloading files

type DownloadFileResponse

type DownloadFileResponse struct {
	URLs   []*BlobUrl   `json:"urls"`
	Errors []*BlobError `json:"errors"`
}

DownloadFileResponse represents the response from a file download request

type DownloadJob

type DownloadJob struct {
	URL      string
	FileName string
}

type DownloadResult

type DownloadResult struct {
	DownloadJob
	DownloadPath string
	Error        error
}

type Downloader

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

func NewDownloader

func NewDownloader(numWorkers int) (*Downloader, error)

func (*Downloader) DownloadAll

func (d *Downloader) DownloadAll(ctx context.Context, files []*DownloadJob) <-chan *DownloadResult

func (*Downloader) DownloadAllC

func (d *Downloader) DownloadAllC(ctx context.Context, files <-chan *DownloadJob) <-chan *DownloadResult

func (*Downloader) DownloadFile

func (d *Downloader) DownloadFile(ctx context.Context, url string, name string) (string, error)

DownloadFile downloads a single file from the provided URL to the temp directory Returns the path to the downloaded file or an error

func (*Downloader) Stop

func (d *Downloader) Stop() error

type EventMessage

type EventMessage struct {
	// The message payload
	Message *syftmsg.Message
}

EventMessage represents a message sent or received via the events system

type EventsAPI

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

EventsAPI manages real-time event communication

func (*EventsAPI) Close

func (e *EventsAPI) Close()

Close terminates the WebSocket connection and cleans up

func (*EventsAPI) Connect

func (e *EventsAPI) Connect(ctx context.Context) error

Connect initiates a WebSocket connection

func (*EventsAPI) Get

func (e *EventsAPI) Get() <-chan *syftmsg.Message

Get returns a channel for receiving WebSocket messages

func (*EventsAPI) IsConnected

func (e *EventsAPI) IsConnected() bool

IsConnected returns the current connection status

func (*EventsAPI) Send

func (e *EventsAPI) Send(msg *syftmsg.Message) error

Send sends a message through the WebSocket

type PresignedParams

type PresignedParams struct {
	Keys []string `json:"keys"`
}

PresignedParams represents the parameters for getting presigned URLs

type PresignedResponse

type PresignedResponse struct {
	URLs   []*BlobUrl   `json:"urls"`
	Errors []*BlobError `json:"errors"`
}

PresignedResponse represents the response from a presigned URL request

type ProgressCallback

type ProgressCallback func(uploaded int64, total int64)

type RefreshTokenRequest

type RefreshTokenRequest struct {
	RefreshToken string `json:"refreshToken"`
}

type SyftSDK

type SyftSDK struct {
	Datasite *DatasiteAPI
	Blob     *BlobAPI
	Events   *EventsAPI
	// contains filtered or unexported fields
}

SyftSDK is the main client for interacting with the Syft API

func New

func New(config *SyftSDKConfig) (*SyftSDK, error)

New creates a new SyftSDK client

func (*SyftSDK) Authenticate

func (s *SyftSDK) Authenticate(ctx context.Context) error

Authenticate sets the user authentication for API calls and events

func (*SyftSDK) Close

func (s *SyftSDK) Close()

Close terminates all connections and cleans up resources

func (*SyftSDK) OnAuthTokenUpdate

func (s *SyftSDK) OnAuthTokenUpdate(fn func(refreshToken string))

type SyftSDKConfig

type SyftSDKConfig struct {
	BaseURL      string // BaseURL is required
	Email        string // Email is required
	RefreshToken string // RefreshToken is required
	AccessToken  string // AccessToken is optional
}

SyftSDKConfig is the configuration for the SyftSDK

func (*SyftSDKConfig) Validate

func (c *SyftSDKConfig) Validate() error

type SyftSDKError

type SyftSDKError struct {
	Error string `json:"error"`
}

type UploadParams

type UploadParams struct {
	Key               string
	FilePath          string
	ChecksumCRC64NVME string
}

UploadParams represents the parameters for uploading a blob

type UploadResponse

type UploadResponse struct {
	Key          string `json:"key"`
	Version      string `json:"version"`
	ETag         string `json:"etag"`
	Size         int64  `json:"size"`
	LastModified string `json:"lastModified"`
}

UploadResponse represents the response from a blob upload

type VerifyEmailCodeRequest

type VerifyEmailCodeRequest struct {
	Email string `json:"email"`
	Code  string `json:"code"`
}

type VerifyEmailRequest

type VerifyEmailRequest struct {
	Email string `json:"email"`
}

Jump to

Keyboard shortcuts

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