storage

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ArtifactoryTokenEnvKey = "ARTIFACTORY_TOKEN"

Variables

This section is empty.

Functions

func ExtensionID added in v1.2.0

func ExtensionID(manifest *VSIXManifest) string

ExtensionID returns the full ID of an extension.

func ExtractZip

func ExtractZip(rawZip []byte, fn func(name string, reader io.Reader) error) error

ExtractZip applies a function with a reader for every file in the zip. If the function returns an error the walk is aborted.

func GetZipFileReader

func GetZipFileReader(rawZip []byte, filename string) (io.ReadCloser, error)

GetZipFileReader returns a reader for a single file in a zip.

func ParseExtensionID added in v1.2.0

func ParseExtensionID(id string) (string, string, string, error)

ParseExtensionID parses an extension ID into its separate parts: publisher, name, and version (version may be blank).

func ReadVSIX added in v1.2.0

func ReadVSIX(ctx context.Context, source string) ([]byte, error)

ReadVSIX reads the bytes of a VSIX from the specified source. The source might be a URI or a local file path.

func WalkZip

func WalkZip(rawZip []byte, fn func(*zip.File) (bool, error)) (io.ReadCloser, error)

WalkZip applies a function over every file in the zip. If the function returns true a reader for that file will be immediately returned. If it returns an error the error will immediately be returned. Otherwise `nil` will be returned once the archive's end is reached.

Types

type Artifactory added in v1.2.0

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

Artifactory implements Storage. It stores extensions remotely through Artifactory by both copying the VSIX and extracting said VSIX to a tree structure in the form of publisher/extension/version to easily serve individual assets via HTTP.

func NewArtifactoryStorage added in v1.2.0

func NewArtifactoryStorage(uri, repo string, logger slog.Logger) (*Artifactory, error)

func (*Artifactory) AddExtension added in v1.2.0

func (s *Artifactory) AddExtension(ctx context.Context, manifest *VSIXManifest, vsix []byte) (string, error)

func (*Artifactory) FileServer added in v1.2.0

func (s *Artifactory) FileServer() http.Handler

func (*Artifactory) Manifest added in v1.2.0

func (s *Artifactory) Manifest(ctx context.Context, publisher, name, version string) (*VSIXManifest, error)

func (*Artifactory) RemoveExtension added in v1.2.0

func (s *Artifactory) RemoveExtension(ctx context.Context, publisher, name, version string) error

func (*Artifactory) Versions added in v1.2.0

func (s *Artifactory) Versions(ctx context.Context, publisher, name string) ([]string, error)

func (*Artifactory) WalkExtensions added in v1.2.0

func (s *Artifactory) WalkExtensions(ctx context.Context, fn func(manifest *VSIXManifest, versions []string) error) error

type ArtifactoryError added in v1.2.0

type ArtifactoryError struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

type ArtifactoryFile added in v1.2.0

type ArtifactoryFile struct {
	URI    string `json:"uri"`
	Folder bool   `json:"folder"`
}

type ArtifactoryFolder added in v1.2.0

type ArtifactoryFolder struct {
	Children []ArtifactoryFile `json:"children"`
}

type ArtifactoryResponse added in v1.2.0

type ArtifactoryResponse struct {
	Errors []ArtifactoryError `json:"errors"`
}

type AssetType

type AssetType string
const (
	ManifestAssetType AssetType = "Microsoft.VisualStudio.Code.Manifest" // This is the package.json.
	VSIXAssetType     AssetType = "Microsoft.VisualStudio.Services.VSIXPackage"
)

type Local

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

Local implements Storage. It stores extensions locally on disk by both copying the VSIX and extracting said VSIX to a tree structure in the form of publisher/extension/version to easily serve individual assets via HTTP.

func NewLocalStorage added in v1.2.0

func NewLocalStorage(extdir string, logger slog.Logger) (*Local, error)

func (*Local) AddExtension

func (s *Local) AddExtension(ctx context.Context, manifest *VSIXManifest, vsix []byte) (string, error)

func (*Local) FileServer

func (s *Local) FileServer() http.Handler

func (*Local) Manifest

func (s *Local) Manifest(ctx context.Context, publisher, name, version string) (*VSIXManifest, error)

func (*Local) RemoveExtension

func (s *Local) RemoveExtension(ctx context.Context, publisher, name, version string) error

func (*Local) Versions added in v1.2.0

func (s *Local) Versions(ctx context.Context, publisher, name string) ([]string, error)

func (*Local) WalkExtensions

func (s *Local) WalkExtensions(ctx context.Context, fn func(manifest *VSIXManifest, versions []string) error) error

type Options added in v1.2.0

type Options struct {
	Artifactory string
	ExtDir      string
	Repo        string
	Logger      slog.Logger
}

type PropertyType

type PropertyType string
const (
	DependencyPropertyType PropertyType = "Microsoft.VisualStudio.Code.ExtensionDependencies"
	PackPropertyType       PropertyType = "Microsoft.VisualStudio.Code.ExtensionPack"
)

type Storage

type Storage interface {
	// AddExtension adds the provided VSIX into storage and returns the location
	// for verification purposes.
	AddExtension(ctx context.Context, manifest *VSIXManifest, vsix []byte) (string, error)
	// FileServer provides a handler for fetching extension repository files from
	// a client.
	FileServer() http.Handler
	// Manifest returns the manifest bytes for the provided extension.  The
	// extension asset itself (the VSIX) will be included on the manifest even if
	// it does not exist on the manifest on disk.
	Manifest(ctx context.Context, publisher, name, version string) (*VSIXManifest, error)
	// RemoveExtension removes the provided version of the extension.  It errors
	// if the provided version does not exist or if removing it fails.  If version
	// is blank all versions of that extension will be removed.
	RemoveExtension(ctx context.Context, publisher, name, version string) error
	// Versions returns the available versions of the provided extension in sorted
	// order.  If the extension does not exits it returns an error.
	Versions(ctx context.Context, publisher, name string) ([]string, error)
	// WalkExtensions applies a function over every extension.  The extension
	// points to the latest version and the versions slice includes all the
	// versions in sorted order including the latest version (which will be in
	// [0]).  If the function returns an error the error is immediately returned
	// which aborts the walk.
	WalkExtensions(ctx context.Context, fn func(manifest *VSIXManifest, versions []string) error) error
}

func NewStorage added in v1.2.0

func NewStorage(options *Options) (Storage, error)

NewStorage returns a storage instance based on the provided extension directory or Artifactory URL. If neither or both are provided an error is returned.

type VSIXAsset

type VSIXAsset struct {
	Type        AssetType `xml:",attr"`
	Path        string    `xml:",attr"`
	Addressable string    `xml:",attr"`
}

VSIXAsset implements XMLManifest.PackageManifest.Assets.Asset. https://github.com/microsoft/vscode-vsce/blob/main/src/xml.ts#L25

type VSIXAssets

type VSIXAssets struct {
	Asset []VSIXAsset
}

VSIXAssets implements XMLManifest.PackageManifest.Assets. https://github.com/microsoft/vscode-vsce/blob/main/src/xml.ts#L25

type VSIXIdentity

type VSIXIdentity struct {
	// ID correlates to ExtensionName, *not* ExtensionID.
	ID             string `xml:"Id,attr"`
	Version        string `xml:",attr"`
	Publisher      string `xml:",attr"`
	TargetPlatform string `xml:",attr"`
}

VSIXManifest implement XMLManifest.PackageManifest.Metadata.Identity. https://github.com/microsoft/vscode-vsce/blob/main/src/xml.ts#L14

type VSIXManifest

type VSIXManifest struct {
	Metadata     VSIXMetadata
	Installation struct {
		InstallationTarget struct {
			ID string `xml:"Id,attr"`
		}
	}
	Dependencies []string
	Assets       VSIXAssets
}

VSIXManifest implement XMLManifest.PackageManifest. https://github.com/microsoft/vscode-vsce/blob/main/src/xml.ts#L9-L26

func ReadVSIXManifest added in v1.2.0

func ReadVSIXManifest(vsix []byte) (*VSIXManifest, error)

ReadVSIXManifest reads and parses an extension manifest from a vsix file. If the manifest is invalid it will be returned along with the validation error.

type VSIXMetadata

type VSIXMetadata struct {
	Description  string
	DisplayName  string
	Identity     VSIXIdentity
	Tags         string
	GalleryFlags string
	License      string
	Icon         string
	Properties   VSIXProperties
	Categories   string
}

VSIXManifest implement XMLManifest.PackageManifest.Metadata. https://github.com/microsoft/vscode-vsce/blob/main/src/xml.ts#L11-L22

type VSIXPackageJSON added in v1.2.0

type VSIXPackageJSON struct {
	Browser string `json:"browser"`
}

VSIXPackageJSON partially implements Manifest. https://github.com/microsoft/vscode-vsce/blob/main/src/manifest.ts#L40-L99

func ReadVSIXPackageJSON added in v1.2.0

func ReadVSIXPackageJSON(vsix []byte, packageJsonPath string) (*VSIXPackageJSON, error)

ReadVSIXPackageJSON reads and parses an extension's package.json from a vsix file.

type VSIXProperties

type VSIXProperties struct {
	Property []VSIXProperty
}

VSIXProperties implements XMLManifest.PackageManifest.Metadata.Properties. https://github.com/microsoft/vscode-vsce/blob/main/src/xml.ts#L19

type VSIXProperty

type VSIXProperty struct {
	ID    PropertyType `xml:"Id,attr"`
	Value string       `xml:",attr"`
}

VSIXProperty implements XMLManifest.PackageManifest.Metadata.Properties.Property. https://github.com/microsoft/vscode-vsce/blob/main/src/xml.ts#L19

Jump to

Keyboard shortcuts

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