ephcli

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package ephcli provides progress bar functionality for file operations.

Package ephcli provides organization context management for resolving organization from flags or configuration.

Package ephcli provides organization file operation methods for the ephemeralfiles API.

Package ephcli provides organization management methods for the ephemeralfiles API.

Index

Constants

View Source
const (
	// PEMLineLength is the standard length for PEM-encoded lines.
	PEMLineLength = 64
	// AESKeySize32 is the size of AES-256 key in bytes.
	AESKeySize32 = 32
)
View Source
const ChunkDownloadTimeout = 30 * time.Minute

ChunkDownloadTimeout is the timeout for chunk download requests (longer for large files).

View Source
const ChunkUploadTimeout = 30 * time.Minute

ChunkUploadTimeout is the timeout for chunk upload requests (longer for large files).

View Source
const DefaultAPIRequestTimeout = 5 * time.Second

DefaultAPIRequestTimeout is the default timeout for API requests.

View Source
const (
	// DefaultBarWidth is the default width for progress bars.
	DefaultBarWidth = 50
)
View Source
const (
	// FilePermission is the permission for downloaded files.
	FilePermission = 0600
)

Variables

View Source
var (
	// HTTP and API errors.
	ErrUnexpectedStatusCode = errors.New("unexpected status code")
	ErrSendingRequest       = errors.New("error sending request")
	ErrCreatingRequest      = errors.New("error creating request")
	ErrDecodingResponse     = errors.New("error decoding response")
	ErrReadingResponse      = errors.New("error reading response")

	// Encryption and security errors.
	ErrParsePEMBlock       = errors.New("failed to parse PEM block")
	ErrParsePublicKey      = errors.New("failed to parse public key")
	ErrNotRSAPublicKey     = errors.New("not an RSA public key")
	ErrEncryptionFailed    = errors.New("encryption failed")
	ErrCiphertextTooShort  = errors.New("ciphertext too short")
	ErrGeneratingAESKey    = errors.New("error generating AES key")
	ErrCreatingCipherBlock = errors.New("error creating new cipher block")
	ErrGeneratingRandomIV  = errors.New("error generating random IV")

	// File and I/O errors.
	ErrOpeningFile        = errors.New("error opening file")
	ErrGettingFileInfo    = errors.New("error getting file info")
	ErrReadingChunk       = errors.New("error reading chunk")
	ErrEncryptingChunk    = errors.New("error encrypting chunk")
	ErrCreatingFormFile   = errors.New("error creating form file")
	ErrWritingChunkToForm = errors.New("error writing chunk to form")
	ErrClosingWriter      = errors.New("error closing writer")
	ErrSeekingInFile      = errors.New("error seeking in file")
	ErrWritingChunkToFile = errors.New("error writing chunk to file")
	ErrDecryptingChunk    = errors.New("error decrypting chunk")

	// Payload and marshalling errors.
	ErrMarshallingPayload = errors.New("error marshalling payload")

	// GitHub release errors.
	ErrGettingLatestRelease = errors.New("error getting latest release")

	// Header and response errors.
	ErrDecodePEMBlock             = errors.New("failed to decode PEM block containing public key")
	ErrMissingHeaderFileID        = errors.New("missing X-File-Id header")
	ErrMissingHeaderPublicKey     = errors.New("missing X-File-Public-Key header")
	ErrMissingHeaderTransactionID = errors.New("missing X-Transaction-Id header")
	ErrMissingHeaderUploadID      = errors.New("missing X-Upload-Id header")
)

Error constants for the ephcli package.

View Source
var (
	// ErrInvalidToken is returned when a JWT token is invalid or malformed.
	ErrInvalidToken = errors.New("invalid token")
	// Now is a function that returns the current time, exposed for testing purposes.
	Now func() time.Time
)
View Source
var (
	// ErrFileNotFound is returned when a requested file cannot be found.
	ErrFileNotFound = errors.New("file not found")
)
View Source
var (
	// ErrNoOrganizationSpecified is returned when no organization is specified via flags or config.
	ErrNoOrganizationSpecified = errors.New("no organization specified. Use --org flag or set default with 'eph org use'")
)
View Source
var (
	// ErrOrganizationNotFound is returned when an organization cannot be found.
	ErrOrganizationNotFound = errors.New("organization not found")
)

Functions

func CheckExpiration

func CheckExpiration(token string) (bool, error)

CheckExpiration checks if a JWT token has expired.

func DecryptAES added in v0.2.0

func DecryptAES(key []byte, ciphertext []byte) ([]byte, error)

DecryptAES decrypts ciphertext using AES decryption with the provided key.

func EncryptAES added in v0.2.0

func EncryptAES(key []byte, plaintext []byte) ([]byte, error)

EncryptAES encrypts plaintext using AES encryption with the provided key.

func EncryptAESKey added in v0.2.0

func EncryptAESKey(publicKeyPem, aesKey string) (string, error)

EncryptAESKey encrypts an AES key using RSA public key encryption.

func GenAESKey32bits added in v0.2.0

func GenAESKey32bits() ([]byte, error)

GenAESKey32bits generates a 32 bits AES key.

func LoadRSAPublicKey added in v0.2.0

func LoadRSAPublicKey(pemString string) (*rsa.PublicKey, error)

LoadRSAPublicKey loads an RSA public key from a PEM-encoded string.

func Print added in v0.2.0

func Print(fl *dto.FileList) error

Print prints the list of files as a table.

func PrintCSV added in v0.2.0

func PrintCSV(fl *dto.FileList) error

PrintCSV prints the list of files as a CSV.

func PrintJSON added in v0.2.0

func PrintJSON(fl *dto.FileList) error

PrintJSON prints the list of files as JSON.

func PrintYAML added in v0.2.0

func PrintYAML(fl *dto.FileList) error

PrintYAML prints the list of files as YAML.

func Whoami

func Whoami(token string) (string, time.Time, error)

Whoami extracts user information from a JWT token, returning email and expiration time.

Types

type Box

type Box struct {
	CapacityMb  int64 `json:"capacity_mb"`
	UsedMb      int64 `json:"used_mb"`
	RemainingMb int64 `json:"remaining_mb"`
}

Box represents storage capacity and usage information for a user's box.

type ClientEphemeralfiles

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

ClientEphemeralfiles is the client to interact with the API.

func NewClient

func NewClient(token string) *ClientEphemeralfiles

NewClient creates a new client.

func (*ClientEphemeralfiles) CloseProgressBar added in v0.2.0

func (c *ClientEphemeralfiles) CloseProgressBar()

CloseProgressBar clears and closes the progress bar.

func (*ClientEphemeralfiles) CreateNewDownloadTransaction added in v0.2.0

func (c *ClientEphemeralfiles) CreateNewDownloadTransaction(
	fileID string,
) (string, string, error)

CreateNewDownloadTransaction creates a new E2E download transaction and returns the transaction ID and public key.

func (*ClientEphemeralfiles) DeleteOrganizationFile added in v0.3.0

func (c *ClientEphemeralfiles) DeleteOrganizationFile(fileID string) error

DeleteOrganizationFile deletes a file from an organization.

func (*ClientEphemeralfiles) DisableProgressBar

func (c *ClientEphemeralfiles) DisableProgressBar()

DisableProgressBar disables the progress bar for this client.

func (*ClientEphemeralfiles) Download

func (c *ClientEphemeralfiles) Download(uuidFile string, outputfile string) error

Download downloads a file from the server and saves it to the outputfile If the outputfile is empty, the file will be saved to the current directory with the same name as the file on the server (retrieving the name from the Content-Disposition header).

func (*ClientEphemeralfiles) DownloadE2E added in v0.2.0

func (c *ClientEphemeralfiles) DownloadE2E(fileID string, outputPath string) error

DownloadE2E downloads and decrypts a file using end-to-end encryption.

func (*ClientEphemeralfiles) DownloadEndpoint

func (c *ClientEphemeralfiles) DownloadEndpoint(uuidFile string) string

DownloadEndpoint returns the API endpoint URL for downloading a file by UUID.

func (*ClientEphemeralfiles) DownloadOrganizationFile added in v0.3.0

func (c *ClientEphemeralfiles) DownloadOrganizationFile(fileID string, outputFile string) error

DownloadOrganizationFile downloads a file from an organization.

func (*ClientEphemeralfiles) DownloadPartE2E added in v0.2.0

func (c *ClientEphemeralfiles) DownloadPartE2E(
	outputFilePath string, transactionID string, aesKey []byte, part int,
) (int, error)

DownloadPartE2E downloads and decrypts a specific part of an E2E encrypted file. Deprecated: Use DownloadPartE2EToFile instead.

func (*ClientEphemeralfiles) DownloadPartE2EEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) DownloadPartE2EEndpoint(transactionID string, part int) string

DownloadPartE2EEndpoint returns the API endpoint URL for downloading a specific part of an E2E encrypted file.

func (*ClientEphemeralfiles) DownloadPartE2EToFile added in v0.3.0

func (c *ClientEphemeralfiles) DownloadPartE2EToFile(
	file *os.File, transactionID string, aesKey []byte, part int,
) (int, error)

DownloadPartE2EToFile downloads and decrypts a specific part of an E2E encrypted file to an open file handle.

func (*ClientEphemeralfiles) Fetch

func (c *ClientEphemeralfiles) Fetch() (dto.FileList, error)

Fetch retrieves the list of files from the server.

func (*ClientEphemeralfiles) FilesEndpoint

func (c *ClientEphemeralfiles) FilesEndpoint() string

FilesEndpoint returns the endpoint for the files.

func (*ClientEphemeralfiles) GetBoxInfos

func (c *ClientEphemeralfiles) GetBoxInfos() (*Box, error)

GetBoxInfos retrieves storage capacity and usage information for the current user's box.

func (*ClientEphemeralfiles) GetFileInformationEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) GetFileInformationEndpoint(fileID string) string

GetFileInformationEndpoint returns the API endpoint URL for retrieving file information.

func (*ClientEphemeralfiles) GetNewDownloadTransactionEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) GetNewDownloadTransactionEndpoint(fileID string) string

GetNewDownloadTransactionEndpoint returns the API endpoint URL for creating a new download transaction.

func (*ClientEphemeralfiles) GetOrganization added in v0.3.0

func (c *ClientEphemeralfiles) GetOrganization(orgID string) (*dto.Organization, error)

GetOrganization retrieves a specific organization by ID.

func (*ClientEphemeralfiles) GetOrganizationByName added in v0.3.0

func (c *ClientEphemeralfiles) GetOrganizationByName(name string) (*dto.Organization, error)

GetOrganizationByName retrieves an organization by name.

func (*ClientEphemeralfiles) GetOrganizationFilesByTags added in v0.3.0

func (c *ClientEphemeralfiles) GetOrganizationFilesByTags(
	orgID string,
	tags []string,
	limit int,
	offset int,
) ([]dto.OrganizationFile, error)

GetOrganizationFilesByTags gets files filtered by tags.

func (*ClientEphemeralfiles) GetOrganizationStats added in v0.3.0

func (c *ClientEphemeralfiles) GetOrganizationStats(orgID string) (*dto.OrganizationStats, error)

GetOrganizationStats retrieves organization statistics.

func (*ClientEphemeralfiles) GetOrganizationStorage added in v0.3.0

func (c *ClientEphemeralfiles) GetOrganizationStorage(orgID string) (*dto.OrganizationStorage, error)

GetOrganizationStorage retrieves storage information for an organization.

func (*ClientEphemeralfiles) GetPopularTags added in v0.3.0

func (c *ClientEphemeralfiles) GetPopularTags(
	orgID string,
	limit int,
) ([]dto.TagCount, error)

GetPopularTags retrieves popular tags for an organization.

func (*ClientEphemeralfiles) GetPublicKey added in v0.2.0

func (c *ClientEphemeralfiles) GetPublicKey() (string, string, string, error)

GetPublicKey retrieves the server's public key and creates a new upload transaction.

func (*ClientEphemeralfiles) GetPublicKeyEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) GetPublicKeyEndpoint() string

GetPublicKeyEndpoint returns the API endpoint URL for retrieving the server's public key.

func (*ClientEphemeralfiles) GetPublicKeyWithHeaders added in v0.3.0

func (c *ClientEphemeralfiles) GetPublicKeyWithHeaders(orgID string, tags []string) (string, string, string, error)

GetPublicKeyWithHeaders retrieves the server's public key with optional organization context.

func (*ClientEphemeralfiles) InitProgressBar added in v0.2.0

func (c *ClientEphemeralfiles) InitProgressBar(msg string, totalSize int64)

InitProgressBar initializes a progress bar with the given message and total size.

func (*ClientEphemeralfiles) ListExpiredOrganizationFiles added in v0.3.0

func (c *ClientEphemeralfiles) ListExpiredOrganizationFiles(
	orgID string,
	limit int,
) ([]dto.OrganizationFile, error)

ListExpiredOrganizationFiles lists expired files in an organization.

func (*ClientEphemeralfiles) ListOrganizationFiles added in v0.3.0

func (c *ClientEphemeralfiles) ListOrganizationFiles(
	orgID string,
	limit int,
	offset int,
) ([]dto.OrganizationFile, error)

ListOrganizationFiles lists all files in an organization.

func (*ClientEphemeralfiles) ListOrganizations added in v0.3.0

func (c *ClientEphemeralfiles) ListOrganizations() ([]dto.Organization, error)

ListOrganizations retrieves all organizations for the authenticated user.

func (*ClientEphemeralfiles) ListRecentOrganizationFiles added in v0.3.0

func (c *ClientEphemeralfiles) ListRecentOrganizationFiles(
	orgID string,
	limit int,
) ([]dto.OrganizationFile, error)

ListRecentOrganizationFiles lists recent files in an organization.

func (*ClientEphemeralfiles) Remove

func (c *ClientEphemeralfiles) Remove(uuidFileToRemove string) error

Remove deletes a file from the ephemeralfiles service by its UUID.

func (*ClientEphemeralfiles) SendAESKeyEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) SendAESKeyEndpoint(uploadID string) string

SendAESKeyEndpoint returns the API endpoint URL for sending an AES key for a file.

func (*ClientEphemeralfiles) SendAESKeyToEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) SendAESKeyToEndpoint(endpoint, encryptedAESKey string) error

SendAESKeyToEndpoint sends an encrypted AES key to the specified endpoint.

func (*ClientEphemeralfiles) SetDebug added in v0.2.0

func (c *ClientEphemeralfiles) SetDebug()

SetDebug sets the logger to debug Disable the progress bar.

func (*ClientEphemeralfiles) SetEndpoint

func (c *ClientEphemeralfiles) SetEndpoint(endpoint string)

SetEndpoint sets the API endpoint for this client.

func (*ClientEphemeralfiles) SetHTTPClient

func (c *ClientEphemeralfiles) SetHTTPClient(client *http.Client)

SetHTTPClient sets the HTTP client for this client.

func (*ClientEphemeralfiles) SetLogger added in v0.2.0

func (c *ClientEphemeralfiles) SetLogger(logger *slog.Logger)

SetLogger sets the logger.

func (*ClientEphemeralfiles) UpdateAESKeyForDownloadTransactionEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) UpdateAESKeyForDownloadTransactionEndpoint(transactionID string) string

UpdateAESKeyForDownloadTransactionEndpoint returns the API endpoint URL for updating the AES key in a download transaction.

func (*ClientEphemeralfiles) UpdateFileTags added in v0.3.0

func (c *ClientEphemeralfiles) UpdateFileTags(
	fileID string,
	tags []string,
) (*dto.OrganizationFile, error)

UpdateFileTags updates tags for a file.

func (*ClientEphemeralfiles) Upload

func (c *ClientEphemeralfiles) Upload(fileToUpload string) error

Upload uploads a file to the ephemeralfiles service.

func (*ClientEphemeralfiles) UploadE2E added in v0.2.0

func (c *ClientEphemeralfiles) UploadE2E(fileToUpload string) error

UploadE2E uploads a file using end-to-end encryption.

func (*ClientEphemeralfiles) UploadE2EEndpoint added in v0.2.0

func (c *ClientEphemeralfiles) UploadE2EEndpoint(uploadID string) string

UploadE2EEndpoint returns the API endpoint URL for E2E encrypted file uploads.

func (*ClientEphemeralfiles) UploadEndpoint

func (c *ClientEphemeralfiles) UploadEndpoint() string

UploadEndpoint returns the API endpoint URL for file uploads.

func (*ClientEphemeralfiles) UploadFileInChunks added in v0.2.0

func (c *ClientEphemeralfiles) UploadFileInChunks(aeskey []byte, filePath, targetURL string) error

UploadFileInChunks uploads a file in encrypted chunks for E2E encryption.

func (*ClientEphemeralfiles) UploadOrganizationFile added in v0.3.0

func (c *ClientEphemeralfiles) UploadOrganizationFile(
	orgID string,
	filepath string,
	tags []string,
) (*dto.OrganizationFile, error)

UploadOrganizationFile uploads a file to an organization.

func (*ClientEphemeralfiles) UploadOrganizationFileE2E added in v0.3.0

func (c *ClientEphemeralfiles) UploadOrganizationFileE2E(
	orgID string, fileToUpload string, tags []string,
) (string, error)

UploadOrganizationFileE2E uploads a file to an organization using end-to-end encryption.

type E2EKeyBundle added in v0.2.0

type E2EKeyBundle struct {
	AESKey          []byte
	HexString       string
	EncryptedAESKey string
}

E2EKeyBundle represents an AES key with its encrypted version.

func GenerateAndEncryptAESKey added in v0.2.0

func GenerateAndEncryptAESKey(publicKey string) (*E2EKeyBundle, error)

GenerateAndEncryptAESKey creates an AES key and encrypts it with the given public key.

type OrgContext added in v0.3.0

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

OrgContext manages organization context resolution.

func NewOrgContext added in v0.3.0

func NewOrgContext(client *ClientEphemeralfiles, cfg *config.Config) *OrgContext

NewOrgContext creates a new organization context manager.

func (*OrgContext) ResolveOrganization added in v0.3.0

func (oc *OrgContext) ResolveOrganization(orgFlag string, orgIDFlag string) (*dto.Organization, error)

ResolveOrganization resolves organization from flags or config. Priority: --org-id flag > --org flag > config.DefaultOrganization.

func (*OrgContext) ResolveOrganizationID added in v0.3.0

func (oc *OrgContext) ResolveOrganizationID(nameOrID string) (string, error)

ResolveOrganizationID gets organization ID from name or returns ID directly.

Jump to

Keyboard shortcuts

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