sexta-feira, 21 de março de 2025

Solution to failed to acquire username/password from local configuration on rust git libs

Let's say you need to work on a Rust project that depends on other libraries hosted in a private Git repository. This project uses the repository's HTTPS URL. For example:



your-lib = { git = "ssh://git@github.com/your-company/your-lib.git"}

Then you try to start the project and encounter the following error:


$ cargo run

    Blocking waiting for file lock on package cache

    Updating crates.io index

    Updating git repository `https://github.com/your-company/your-lib.git`

error: failed to get `outbox-pattern-processor` as a dependency of package `anti-fraud-service v0.1.0 (/project/your-project)`

Caused by:

  failed to load source for dependency `your-lib`

Caused by:

  Unable to update https://github.com/your-company/your-lib.git?tag=v1.0.0#49efa247

Caused by:

  failed to fetch into: /home/tiago.motta/.cargo/git/db/your-lib-31d59910066df49a

Caused by:

  revision 49efa2476e2613cf809315b4b0abf16f079b5dcb not found

Caused by:

  failed to authenticate when downloading repository

  * attempted to find username/password via git's `credential.helper` support, but failed

  if the git CLI succeeds then `net.git-fetch-with-cli` may help here

  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:

  failed to acquire username/password from local configuration


The solution is simple. Just edit your global .gitconfig to replace HTTPS URLs with SSH by adding the following lines:


[url "ssh://git@github.com/"]

insteadOf = https://github.com/




segunda-feira, 10 de março de 2025

What is the best rust lib to post custom metric on datadog?

The best library for recording custom metrics in Datadog using Rust is dogstatsd (https://crates.io/crates/dogstatsd).

The alternative statsd (https://crates.io/crates/statsd) does not allow sending tags. There is even a fork, datadog-statsd (https://crates.io/crates/datadog-statsd), that enables tag sending. However, both define the client without deriving Clone, which prevents using this client as with_state in Axum, resulting in an error similar to this:


the trait bound `...` is not satisfied

the trait `Clone` is not implemented for `...`rustcClick for full compiler diagnostic

method_routing.rs(168, 16): required by a bound in `post`

....rs(6, 1): consider annotating `...` with `#[derive(Clone)]`: `#[derive(Clone)]

`

the trait bound `...` is not satisfied

the trait `Clone` is not implemented for `...`rustcClick for full compiler diagnostic

method_routing.rs(168, 16): required by a bound in `post`

....rs(6, 1): consider annotating `...` with `#[derive(Clone)]`: `#[derive(Clone)]

`

the trait bound `fn(axum::extract::State<...>, Json<...>) -> impl futures::Future<Output = Result<hyper::Response<axum::body::Body>, AppError>> {...::handler}: Handler<_, _>` is not satisfied


the following other types implement trait `Handler<T, S>`:

  `Layered<L, H, T, S>` implements `Handler<T, S>`

  `MethodRouter<S>` implements `Handler<(), S>`rustcClick for full compiler diagnostic

....rs(55, 32): required by a bound introduced by this call

method_routing.rs(166, 16): required by a bound in `post`

the trait bound `fn(axum::extract::State<...>, axum::Json<...>) -> impl futures::Future<Output = Result<hyper::Response<axum::body::Body>, ...>> {...}: Handler<_, _>` is not satisfied


the following other types implement trait `Handler<T, S>`:

  `Layered<L, H, T, S>` implements `Handler<T, S>`

  `MethodRouter<S>` implements `Handler<(), S>`rustcClick for full compiler diagnostic

....rs(55, 32): required by a bound introduced by this call

method_routing.rs(166, 16): required by a bound in `post`

axum::routing::method_routing

pub fn post<H, T, S>(handler: H) -> MethodRouter<S, Infallible>

where

    H: Handler<T, S>,

    T: 'static,

    S: Clone + Send + Sync + 'static,

H = fn handler(State<...>, …) -> …, S = ...