crates.io Backend Documentation

repository·main·Indexed 25 days ago

https://github.com/rust-lang/crates.io

Documentation for the backend of crates.io, the official central package registry for the Rust programming language. Includes details on internal crates for API communication (crates_io_api_types), Cargo.toml parsing (crates_io_cargo_toml), CDN log parsing (crates_io_cdn_logs), database management (crates_io_database, crates_io_database_dump), and integrations with external services such as GitHub, docs.rs, Datadog, Fastly, and PagerDuty.

Tokens
43.3K
Snippets
68
Records
390
Agent score
87%

What's inside crates.io

  1. Overview of `crates_io_github_app`

    main

    The crates_io_github_app package is responsible for minting installation access tokens for a GitHub App. These tokens are used by background workers to:

    • Authenticate HTTPS pushes to the archive index repository.
    • Authenticate requests to the GitHub Users API to obtain higher rate limits.

    The package provides a GitHubApp trait to abstract HTTP interactions for testing purposes, and a GitHubAppClient struct which serves as the production implementation.

  2. Overview of crates_io_cargo_toml

    main
    The crates_io_cargo_toml crate provides serde definitions for reading and writing Cargo.toml manifest files. It is a simplified, vendored version of the cargo-manifest crate, specifically designed to parse only the fields relevant to crates.io. It includes support for post-processing data to emulate Cargo's workspace inheritance and autobins features, which helps determine if a crate contains a library or executable binaries.
  3. Overview of crates.io

    main
    crates.io is the official package registry for the Rust programming language. It serves as a central repository for sharing and discovering 'crates' (Rust packages or libraries). The repository contains the source code and infrastructure for both the frontend and backend components of the service.
  4. Overview of crates_io_encryption

    main
    The crates_io_encryption package provides functionality for encrypting data at rest within the database. Currently, its primary use case is the encryption and decryption of OAuth tokens. While the underlying operations work on string slices and bytes, the types are specifically named to indicate they are intended for token encryption.
  5. Use `crates_io_version` to determine the application version

    main
    The crates_io_version package provides utilities to identify the currently running version of the crates.io application. It supports multiple discovery methods, such as reading Heroku-specific environment variables or identifying the Git commit SHA of the deployed code across various deployment platforms.
  6. Use `crates_io_session` with Axum

    main
    The crates_io_session package provides tools for managing user sessions in the axum web framework. It includes a SessionExtension extractor and an attach_session() middleware. Sessions are implemented using a signed cargo_session cookie, which allows for the safe storage and retrieval of session data.
  7. Extract metadata from .crate files with `crates_io_tarball`

    main

    The crates_io_tarball package is designed to extract metadata from .crate files, the standard distribution format for Rust libraries on crates.io.

    Metadata is retrieved from two primary sources within the tarball:

    1. Cargo.toml: The main source of metadata. This file is mandatory and must be present in the .crate file.
    2. .cargo_vcs_info.json: A secondary, optional source containing version control system information from the time of publishing.

    Warning: Do not rely on .cargo_vcs_info.json for critical security or integrity information, as it can be tampered with by a malicious user prior to publishing.

  8. Use crates_io_api_types for API communication

    main

    The crates_io_api_types crate provides shared API response and request types used by the crates.io API. These types are designed for JSON serialization/deserialization and represent the public API surface that clients interact with.

    Note: These types are distinct from the internal database models found in crates_io_database. Use this crate when you need to model data for client-server communication rather than internal storage.

  9. Use `crates_io_github` to interact with the GitHub API

    main

    The crates_io_github package provides tools for interacting with GitHub. It is centered around the GitHubClient trait, which defines the operations required by the crates.io codebase.

    To perform actual HTTP requests, use the RealGitHubClient struct, which is implemented using the reqwest crate. For testing environments, you can enable the mock feature to use the MockGitHubClient struct, which is automatically generated via mockall.