210 lines · 7.3 KB · Go
RawDownload
// Package pluginstore exposes plugin registry and artifact installation helpers// for embedders such as CLIProxyAPIHome.package pluginstore import (	"context"	"net/http"	"strings"	"time" 	internalpluginstore "github.com/router-for-me/CLIProxyAPI/v7/internal/pluginstore") const (	DefaultRegistryURL = internalpluginstore.DefaultRegistryURL	DefaultSourceID    = internalpluginstore.DefaultSourceID	DefaultSourceName  = internalpluginstore.DefaultSourceName	SchemaVersion      = internalpluginstore.SchemaVersion	SchemaVersionV2    = internalpluginstore.SchemaVersionV2 	InstallTypeGitHubRelease = internalpluginstore.InstallTypeGitHubRelease	InstallTypeDirect        = internalpluginstore.InstallTypeDirect 	RequestKindRegistry = internalpluginstore.RequestKindRegistry	RequestKindMetadata = internalpluginstore.RequestKindMetadata	RequestKindArtifact = internalpluginstore.RequestKindArtifact 	AuthTypeNone        = internalpluginstore.AuthTypeNone	AuthTypeBearer      = internalpluginstore.AuthTypeBearer	AuthTypeBasic       = internalpluginstore.AuthTypeBasic	AuthTypeHeader      = internalpluginstore.AuthTypeHeader	AuthTypeGitHubToken = internalpluginstore.AuthTypeGitHubToken 	PluginSyncSchemaVersion = internalpluginstore.PluginSyncSchemaVersion) type Source = internalpluginstore.Sourcetype Registry = internalpluginstore.Registrytype Plugin = internalpluginstore.Plugintype Version = internalpluginstore.Versiontype Release = internalpluginstore.Releasetype ReleaseAsset = internalpluginstore.ReleaseAssettype InstallOptions = internalpluginstore.InstallOptionstype InstallResult = internalpluginstore.InstallResulttype InstallPlan = internalpluginstore.InstallPlantype Artifact = internalpluginstore.Artifacttype Platform = internalpluginstore.Platformtype Manifest = internalpluginstore.Manifesttype AuthConfig = internalpluginstore.AuthConfigtype Secret = internalpluginstore.Secrettype ResolvedAuthConfig = internalpluginstore.ResolvedAuthConfigtype PluginSyncRequest = internalpluginstore.PluginSyncRequesttype PluginSyncItem = internalpluginstore.PluginSyncItemtype PluginSyncResponse = internalpluginstore.PluginSyncResponse type HTTPDoer interface {	Do(*http.Request) (*http.Response, error)} var ErrLoadedPluginLocked = internalpluginstore.ErrLoadedPluginLocked type Client struct {	inner internalpluginstore.Client} func NewClient(httpClient HTTPDoer, registryURL string) Client {	return Client{inner: internalpluginstore.Client{		HTTPClient:  httpClient,		RegistryURL: strings.TrimSpace(registryURL),	}}} func NewClientWithAuth(httpClient HTTPDoer, registryURL string, auth []AuthConfig) Client {	return Client{inner: internalpluginstore.Client{		HTTPClient:  httpClient,		RegistryURL: strings.TrimSpace(registryURL),		Auth:        internalpluginstore.NormalizeAuthConfigs(auth),	}}} func NewClientWithResolvedAuth(httpClient HTTPDoer, registryURL string, auth []ResolvedAuthConfig) Client {	return NewClientWithResolvedAuthExpiry(httpClient, registryURL, auth, time.Time{})} func NewClientWithResolvedAuthExpiry(httpClient HTTPDoer, registryURL string, auth []ResolvedAuthConfig, expiresAt time.Time) Client {	return Client{inner: internalpluginstore.Client{		HTTPClient:            httpClient,		RegistryURL:           strings.TrimSpace(registryURL),		ResolvedAuth:          auth,		ResolvedAuthExpiresAt: expiresAt,	}}} // WithNetworkScope returns a copy with the given proxy/egress identity for shared// GitHub API cooldowns. Use the same scope for clients with the same egress and// credentials; an empty scope denotes direct connections. This does not configure// the HTTP transport, which must use the corresponding proxy/egress separately.func (c Client) WithNetworkScope(networkScope string) Client {	c.inner.NetworkScope = strings.TrimSpace(networkScope)	return c} func (c *Client) ClearAuth() {	if c == nil {		return	}	internalpluginstore.ClearResolvedAuthConfigs(c.inner.ResolvedAuth)	c.inner.ResolvedAuth = nil	c.inner.ResolvedAuthExpiresAt = time.Time{}} func DefaultSource() Source {	return internalpluginstore.DefaultSource()} func NormalizeSources(registryURLs []string) ([]Source, error) {	return internalpluginstore.NormalizeSources(registryURLs)} func SourceID(registryURL string) string {	return internalpluginstore.SourceID(registryURL)} func ValidatePlugin(plugin Plugin) error {	return internalpluginstore.ValidatePlugin(plugin)} func PluginInstallType(plugin Plugin) string {	return internalpluginstore.PluginInstallType(plugin)} func PluginPlatforms(plugin Plugin) []Platform {	return internalpluginstore.PluginPlatforms(plugin)} func PluginArtifacts(plugin Plugin) []Artifact {	return internalpluginstore.PluginArtifacts(plugin)} func SelectArtifact(plan InstallPlan, goos string, goarch string) (Artifact, error) {	return internalpluginstore.SelectArtifact(plan, goos, goarch)} func GitHubRepositoryParts(repository string) (string, string, error) {	return internalpluginstore.GitHubRepositoryParts(repository)} func NormalizeAuthConfigs(auth []AuthConfig) []AuthConfig {	return internalpluginstore.NormalizeAuthConfigs(auth)} func ClearResolvedAuthConfigs(auth []ResolvedAuthConfig) {	internalpluginstore.ClearResolvedAuthConfigs(auth)} func ResolvedAuthForRequest(auth []ResolvedAuthConfig, requestURL string, kind string) (ResolvedAuthConfig, bool) {	return internalpluginstore.ResolvedAuthForRequest(auth, requestURL, kind)} func ValidateResolvedAuthConfig(auth ResolvedAuthConfig) error {	return internalpluginstore.ValidateResolvedAuthConfig(auth)} func AuthConfigured(auth []AuthConfig, requestURL string, kind string) bool {	return internalpluginstore.AuthConfigured(auth, requestURL, kind)} func PluginAuthConfigured(source Source, plugin Plugin, auth []AuthConfig) bool {	return internalpluginstore.PluginAuthConfigured(source, plugin, auth)} func UpdateAvailable(installed, latest string) bool {	return internalpluginstore.UpdateAvailable(installed, latest)} func ReleaseVersion(release Release) (string, error) {	return internalpluginstore.ReleaseVersion(release)} func ManifestFromRelease(source Source, plugin Plugin, release Release) (Manifest, error) {	return internalpluginstore.ManifestFromRelease(source, plugin, release)} func ManifestFromPlugin(source Source, plugin Plugin) (Manifest, error) {	return internalpluginstore.ManifestFromPlugin(source, plugin)} func (c Client) FetchRegistry(ctx context.Context) (Registry, error) {	return c.inner.FetchRegistry(ctx)} func (c Client) FetchLatestRelease(ctx context.Context, plugin Plugin) (Release, error) {	return c.inner.FetchLatestRelease(ctx, plugin)} func (c Client) FetchReleaseByTag(ctx context.Context, plugin Plugin, tag string) (Release, error) {	return c.inner.FetchReleaseByTag(ctx, plugin, tag)} func (c Client) Install(ctx context.Context, plugin Plugin, options InstallOptions) (InstallResult, error) {	return c.inner.Install(ctx, plugin, options)} func (c Client) InstallVersion(ctx context.Context, plugin Plugin, releaseTag string, version string, options InstallOptions) (InstallResult, error) {	return c.inner.InstallVersion(ctx, plugin, releaseTag, version, options)} func (c Client) InstallManifest(ctx context.Context, manifest Manifest, options InstallOptions) (InstallResult, error) {	return c.inner.InstallManifest(ctx, manifest, options)}