Expand description
§node-auth
A fast, lightweight, standalone Rust CLI and library that authenticates Node package managers (npm, yarn, and pnpm) to private Google Artifact Registry (GAR) npm repositories using Google Cloud Application Default Credentials (ADC).
§Overview
node-auth replicates and improves upon Google’s @google-cloud/artifact-registry-npm-tools
without requiring Node, npm, or pnpm to be installed or configured beforehand.
§Key Features
- Automatic Credential Discovery: Searches for explicit tokens, Application Default Credentials (ADC),
and falls back to
gcloud auth print-access-token. - Credential Isolation: Reads registry endpoints from project-level
.npmrcand writes secrets to user-level~/.npmrcby default, preventing sensitive tokens from being checked into source control. - Git Safety Checks: When
--local-credentialis used, checks.gitignoreand emits warnings if.npmrcis not properly ignored. - Yarn Modern Support: Detects and updates
npmScopesauthentication in.yarnrc.yml.
§Library Usage Example
use node_auth::{run, Options};
#[tokio::main]
async fn main() -> Result<(), node_auth::AuthError> {
let options = Options {
token: Some("custom-token".to_string()),
..Default::default()
};
run(&options).await?;
Ok(())
}Re-exports§
pub use error::AuthError;
Modules§
- auth
- Google Cloud credential retrieval and authentication handling.
- cli
- Command-line argument parsing and CLI definitions for
node-auth. - error
- Error types for authentication and configuration failures.
- fs
- Path resolution and isolated, atomic configuration-file replacement.
- logger
- CLI-only logging and presentation. Library operations never initialize this logger.
- npmrc
.npmrcconfiguration parsing, formatting, and transformation.- registry
- Shared URL validation for npm and Yarn registries.
- token
- Access-token validation.
- vcs
- Git-backed inspection of local credential file safety.
- yarnrc
- Yarn Berry / Yarn Modern (
.yarnrc.yml) configuration management.
Structs§
- Options
- Configuration options for configuring Node authentication.
Enums§
- RunOutcome
- Useful result of a library authentication run, with presentation left to callers.
Functions§
- run
- Executes authentication and updates
.npmrcand.yarnrc.ymlconfiguration files.