Documentation
¶
Index ¶
- Constants
- func GenerateNpmrc(entries []RegistryEntry, placeholder string) string
- func MarshalEntries(entries []RegistryEntry) (string, error)
- func WithGrantOptions(ctx context.Context, host string) context.Context
- type Provider
- func (p *Provider) Cleanup(cleanupPath string)
- func (p *Provider) ConfigureProxy(proxy provider.ProxyConfigurer, cred *provider.Credential)
- func (p *Provider) ContainerEnv(cred *provider.Credential) []string
- func (p *Provider) ContainerMounts(cred *provider.Credential, containerHome string) ([]provider.MountConfig, string, error)
- func (p *Provider) Grant(ctx context.Context) (*provider.Credential, error)
- func (p *Provider) ImpliedDependencies() []string
- func (p *Provider) Name() string
- type RegistryEntry
Constants ¶
const ( SourceNpmrc = "npmrc" // Discovered from .npmrc file SourceEnv = "env" // From NPM_TOKEN environment variable SourceManual = "manual" // Entered interactively )
Token source constants.
const DefaultRegistry = "registry.npmjs.org"
DefaultRegistry is the default npm registry host.
const NpmTokenPlaceholder = "npm_moatProxyInjected00000000"
NpmTokenPlaceholder is a format-valid npm token placeholder for container .npmrc files. The proxy replaces the real Authorization header at the network layer. npm tokens use the format "npm_" followed by base36 characters.
Variables ¶
This section is empty.
Functions ¶
func GenerateNpmrc ¶
func GenerateNpmrc(entries []RegistryEntry, placeholder string) string
GenerateNpmrc generates a stub .npmrc for use inside containers. Scope-to-registry routing is real (npm needs this), but tokens are placeholders.
func MarshalEntries ¶
func MarshalEntries(entries []RegistryEntry) (string, error)
MarshalEntries encodes registry entries as JSON for storage in the Token field.
Types ¶
type Provider ¶
type Provider struct{}
Provider implements provider.CredentialProvider for npm registries.
func (*Provider) ConfigureProxy ¶
func (p *Provider) ConfigureProxy(proxy provider.ProxyConfigurer, cred *provider.Credential)
ConfigureProxy sets up proxy headers for npm registries. Parses the Token JSON and sets per-host Bearer credentials.
func (*Provider) ContainerEnv ¶
func (p *Provider) ContainerEnv(cred *provider.Credential) []string
ContainerEnv returns environment variables for npm. No env vars needed — npm reads ~/.npmrc by default, and ContainerMounts places the generated .npmrc at containerHome/.npmrc.
func (*Provider) ContainerMounts ¶
func (p *Provider) ContainerMounts(cred *provider.Credential, containerHome string) ([]provider.MountConfig, string, error)
ContainerMounts generates a stub .npmrc in a temp directory and returns mount configs. The .npmrc contains real scope-to-registry routing but placeholder tokens.
func (*Provider) Grant ¶
Grant acquires npm credentials by discovering registries or prompting for a specific host.
When called without --host: discovers registries from .npmrc and NPM_TOKEN env var. When called with --host: prompts for token and scopes for a specific registry.
func (*Provider) ImpliedDependencies ¶
ImpliedDependencies returns dependencies implied by this provider. node provides the runtime; npm upgrades to version 11 (node bundles an older npm).
type RegistryEntry ¶
type RegistryEntry struct {
Host string `json:"host"` // "registry.npmjs.org"
Token string `json:"token"` // "npm_aaaa..."
Scopes []string `json:"scopes,omitempty"` // ["@myorg"] — empty for default registry
TokenSource string `json:"token_source,omitempty"` // "npmrc", "env", "manual"
}
RegistryEntry represents a single npm registry with its authentication token.
func MergeEntry ¶
func MergeEntry(entries []RegistryEntry, newEntry RegistryEntry) []RegistryEntry
MergeEntry merges a new entry into the existing entries, replacing any with the same host.
func ParseNpmrc ¶
func ParseNpmrc(r io.Reader) ([]RegistryEntry, error)
ParseNpmrc parses an .npmrc file and extracts registry entries.
It handles two types of lines:
- Token lines: //registry.npmjs.org/:_authToken=npm_xxxx
- Scope lines: @myorg:registry=https://npm.company.com/
Returns the discovered entries with host-to-token and scope-to-host mappings merged.
func UnmarshalEntries ¶
func UnmarshalEntries(token string) ([]RegistryEntry, error)
UnmarshalEntries decodes registry entries from the JSON-encoded Token field.