upload

package
v3.82.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBaseURL = "https://api.vdb.vulnetix.com/v1"
	// ChunkThreshold is the file size above which chunked upload is used
	ChunkThreshold = 10 * 1024 * 1024 // 10 MB
	// DefaultChunkSize is the size of each chunk for large files
	DefaultChunkSize = 5 * 1024 * 1024 // 5 MB
)

Variables

View Source
var SupportedFormats = []string{"cyclonedx", "spdx", "sarif", "openvex", "csaf_vex"}

SupportedFormats are the artifact formats the upload API accepts. A value outside this set is rejected before any bytes leave the machine.

Functions

func DetectFormat

func DetectFormat(filePath string, data []byte) string

DetectFormat inspects file extension and content to determine the artifact format

func FindVulnetixDir added in v3.3.0

func FindVulnetixDir() (string, bool)

FindVulnetixDir returns the first .vulnetix/ directory found by looking at the current working directory first, then the user home directory. Returns ("", false) if neither exists.

func ValidateFormat added in v3.56.0

func ValidateFormat(format string) error

ValidateFormat checks an explicit --format override. An empty value means "auto-detect" and is always allowed.

Types

type ChunkResponse

type ChunkResponse struct {
	OK          bool   `json:"ok"`
	ChunkNumber int    `json:"chunkNumber"`
	Received    int    `json:"received"`
	TotalChunks int    `json:"totalChunks"`
	Error       string `json:"error,omitempty"`
}

ChunkResponse is returned after uploading a chunk

type Client

type Client struct {
	BaseURL       string
	Creds         *auth.Credentials
	HTTPClient    *http.Client
	GitHubContext *GitHubActionsContext
	CliEnv        *vdb.CliEnv
}

Client handles file uploads to the Vulnetix API

func NewClient

func NewClient(baseURL string, creds *auth.Credentials) *Client

NewClient creates a new upload client

func (*Client) ChunkedUpload

func (c *Client) ChunkedUpload(fileName string, data []byte, contentType, format string) (*FinalizeResponse, error)

ChunkedUpload handles large file uploads by splitting into chunks

func (*Client) ChunkedUploadWithProgress added in v3.11.0

func (c *Client) ChunkedUploadWithProgress(fileName string, data []byte, contentType, format string, progress ProgressFunc) (*FinalizeResponse, error)

ChunkedUploadWithProgress handles large file uploads by splitting into chunks and reporting progress after session initiation, each uploaded chunk, and finalization.

func (*Client) FinalizeUpload

func (c *Client) FinalizeUpload(sessionID string) (*FinalizeResponse, error)

FinalizeUpload completes the upload session

func (*Client) InitiateSession

func (c *Client) InitiateSession(fileName string, fileSize int, contentType string, totalChunks, chunkSize int, format string) (*InitiateResponse, error)

InitiateSession starts a new upload session

func (*Client) MultipartUploadWithProgress added in v3.25.2

func (c *Client) MultipartUploadWithProgress(fileName string, data []byte, contentType, format string, progress ProgressFunc) (*FinalizeResponse, error)

MultipartUploadWithProgress performs the same single-request multipart upload used by the website drop zone, with optional CLI environment metadata.

func (*Client) SimpleUpload

func (c *Client) SimpleUpload(fileName string, data []byte, contentType, format string) (*FinalizeResponse, error)

SimpleUpload performs a single-request upload for small files

func (*Client) SimpleUploadWithProgress added in v3.11.0

func (c *Client) SimpleUploadWithProgress(fileName string, data []byte, contentType, format string, progress ProgressFunc) (*FinalizeResponse, error)

SimpleUploadWithProgress performs a single-request upload for small files.

func (*Client) UploadChunk

func (c *Client) UploadChunk(sessionID string, chunkNumber int, data []byte) (*ChunkResponse, error)

UploadChunk uploads a single chunk of data

func (*Client) UploadFile

func (c *Client) UploadFile(filePath string, formatOverride string) (*FinalizeResponse, error)

UploadFile uploads a file to Vulnetix, choosing simple or chunked based on size

func (*Client) UploadFileWithProgress added in v3.11.0

func (c *Client) UploadFileWithProgress(filePath string, formatOverride string, progress ProgressFunc) (*FinalizeResponse, error)

UploadFileWithProgress uploads a file and reports per-file upload progress when progress is non-nil.

func (*Client) VerifyAuth

func (c *Client) VerifyAuth() (*VerifyResponse, error)

VerifyAuth checks that the provided credentials are valid

type CycloneDXValidationError added in v3.25.2

type CycloneDXValidationError struct {
	SpecVersion string                          `json:"specVersion,omitempty"`
	Violations  []cyclonedx.ValidationViolation `json:"violations"`
}

func (*CycloneDXValidationError) Error added in v3.25.2

func (e *CycloneDXValidationError) Error() string

type DiscoveredFile added in v3.3.0

type DiscoveredFile struct {
	Path   string
	Format string // "cyclonedx" | "spdx" | "sarif" | "openvex" | "csaf_vex"
}

DiscoveredFile is an artifact file ready for upload.

func DiscoverVulnetixFiles added in v3.3.0

func DiscoverVulnetixFiles(dir string) ([]DiscoveredFile, []string, error)

DiscoverVulnetixFiles returns all uploadable artifact files in dir. Files are matched by extension (*.json, *.xml, *.sarif, *.cdx), filtered by non-artifact names, and accepted only when DetectFormat returns a recognised format (not "auto"). CycloneDX files are also validated against the embedded JSON schema; schema failures produce a warning and skip the file rather than aborting the whole discovery.

type FinalizeResponse

type FinalizeResponse struct {
	OK             bool            `json:"ok"`
	PipelineRecord *PipelineRecord `json:"pipelineRecord,omitempty"`
	IsDuplicate    bool            `json:"isDuplicate,omitempty"`
	Error          string          `json:"error,omitempty"`
}

FinalizeResponse is returned after finalizing an upload

type GitHubActionsContext

type GitHubActionsContext struct {
	Repository      string            `json:"repository"`
	RepositoryOwner string            `json:"repositoryOwner"`
	RunID           string            `json:"runId"`
	RunNumber       string            `json:"runNumber"`
	WorkflowName    string            `json:"workflowName"`
	JobName         string            `json:"jobName"`
	SHA             string            `json:"sha"`
	RefName         string            `json:"refName"`
	RefType         string            `json:"refType"`
	EventName       string            `json:"eventName"`
	Actor           string            `json:"actor"`
	ServerURL       string            `json:"serverUrl"`
	APIURL          string            `json:"apiUrl"`
	ExtraEnvVars    map[string]string `json:"extraEnvVars,omitempty"`
}

GitHubActionsContext contains GitHub Actions environment metadata sent with uploads

type InitiateResponse

type InitiateResponse struct {
	OK              bool   `json:"ok"`
	UploadSessionID string `json:"uploadSessionId"`
	ExpiresAt       int64  `json:"expiresAt,omitempty"`
	Error           string `json:"error,omitempty"`
}

InitiateResponse is returned when starting an upload session

type PipelineRecord

type PipelineRecord struct {
	UUID             string `json:"uuid"`
	DetectedType     string `json:"detectedType"`
	ProcessingState  string `json:"processingState"`
	OriginalFileName string `json:"originalFileName"`
	SHA256           string `json:"sha256,omitempty"`
}

PipelineRecord represents the artifact pipeline record from the SaaS

type ProgressFunc added in v3.11.0

type ProgressFunc func(done, total int, stage string)

ProgressFunc reports upload stage progress against a fixed per-file goal.

type VerifyResponse

type VerifyResponse struct {
	OK    bool   `json:"ok"`
	OrgID string `json:"orgId,omitempty"`
	Error string `json:"error,omitempty"`
}

VerifyResponse is returned by the /api/cli/verify endpoint

Jump to

Keyboard shortcuts

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