Watch
0
0
Fork
You've already forked hyperhive
0

forge-client: take the token as a string, drop TokenSource and StaticToken

This commit is contained in:
atlas 2026-11-15 23:22:48 +01:00
commit 6d968c7fe6
8 changed files with 44 additions and 81 deletions

View file

@ -18,7 +18,7 @@ use std::collections::BTreeSet;
use std::sync::Arc;
use anyhow::{Context, Result, bail};
use forge_client::{StaticToken, async_client};
use forge_client::async_client;
use forgejo_api::structs::{AccessToken, CreateAccessTokenOption};
use forgejo_api::{ApiErrorKind, ForgejoError};
use reqwest::StatusCode;
@ -243,7 +243,7 @@ impl Client {
)
.await?;
let as_agent = async_client(self.url.clone(), &StaticToken::new(&credential.value))
let as_agent = async_client(self.url.clone(), &credential.value)
.context("building a forge client with the new token")?;
let me = as_agent
.user_get_current()

View file

@ -9,7 +9,7 @@
use std::sync::{Arc, Mutex};
use forge_client::{StaticToken, async_client};
use forge_client::async_client;
use forgejo_api::{ApiErrorKind, Forgejo, ForgejoError};
use futures_util::future::BoxFuture;
use reqwest::StatusCode;
@ -33,7 +33,7 @@ impl Api {
/// `url` is not http(s), or the token is not ASCII.
pub(crate) fn new(url: url::Url, token: StoredSecret) -> Result<Self, ForgejoError> {
let current = token.current();
let api = Arc::new(async_client(url.clone(), &StaticToken::new(&current))?);
let api = Arc::new(async_client(url.clone(), &current)?);
Ok(Self {
url,
token,
@ -46,7 +46,7 @@ impl Api {
let token = self.token.current();
let mut built = self.built.lock().expect("unpoisoned");
if built.0 != token {
let api = Arc::new(async_client(self.url.clone(), &StaticToken::new(&token))?);
let api = Arc::new(async_client(self.url.clone(), &token)?);
*built = (token.clone(), api);
}
Ok((token, Arc::clone(&built.1)))

View file

@ -15,7 +15,7 @@
use std::sync::Arc;
use anyhow::{Context, Result, bail};
use forge_client::{StaticToken, async_client};
use forge_client::async_client;
use forgejo_api::structs::RepoSearchQuery;
use swarm_secret_client::builder::forge_token_path;
use swarm_secret_client::forge;
@ -93,7 +93,7 @@ impl Client {
.replace_token(&store, LOGIN, TOKEN_NAME, TOKEN_SCOPES, &listed, &path)
.await?;
async_client(self.url.clone(), &StaticToken::new(&credential.value))
async_client(self.url.clone(), &credential.value)
.context("building a forge client with the new token")?
.repo_search(RepoSearchQuery::default())
.await

View file

@ -17,7 +17,7 @@
use std::sync::Arc;
use anyhow::{Context, Result, bail};
use forge_client::{StaticToken, async_client};
use forge_client::async_client;
use forgejo_api::structs::{
CreateTeamOption, CreateTeamOptionPermission, EditTeamOption, EditTeamOptionPermission,
RepoSearchQuery, Team, TeamPermission,
@ -124,7 +124,7 @@ impl Client {
.replace_token(&store, LOGIN, TOKEN_NAME, TOKEN_SCOPES, &listed, &path)
.await?;
async_client(self.url.clone(), &StaticToken::new(&credential.value))
async_client(self.url.clone(), &credential.value)
.context("building a forge client with the new token")?
.repo_search(RepoSearchQuery::default())
.await

View file

@ -20,7 +20,7 @@
use std::sync::Arc;
use anyhow::{Context, Result, bail};
use forge_client::{StaticToken, async_client};
use forge_client::async_client;
use forgejo_api::Forgejo;
use forgejo_api::structs::{
ChangeFileOperation, ChangeFileOperationOperation, ChangeFilesOptions, CreatePullReviewOptions,
@ -123,7 +123,7 @@ impl Client {
.replace_token(&store, LOGIN, TOKEN_NAME, TOKEN_SCOPES, &listed, &path)
.await?;
async_client(self.url.clone(), &StaticToken::new(&credential.value))
async_client(self.url.clone(), &credential.value)
.context("building a forge client with the new token")?
.repo_search(RepoSearchQuery::default())
.await
@ -222,7 +222,7 @@ impl Client {
else {
bail!("nothing at {path}: the classifier's forge token is not minted yet");
};
async_client(self.url.clone(), &StaticToken::new(&credential.value))
async_client(self.url.clone(), &credential.value)
.context("building a forge client with the classifier's token")
}
@ -463,7 +463,7 @@ mod tests {
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let url = url::Url::parse(&format!("http://{}/", listener.local_addr().unwrap())).unwrap();
tokio::spawn(async move { axum::serve(listener, app).await });
let forge = async_client(url, &StaticToken::new("stub-token")).unwrap();
let forge = async_client(url, "stub-token").unwrap();
let commit = BranchCommit {
base: "main".to_owned(),
branch: "review-classifier/alice-0a1b2c3d".to_owned(),

View file

@ -19,7 +19,7 @@
use std::sync::Arc;
use anyhow::{Context, Result, bail};
use forge_client::{StaticToken, async_client};
use forge_client::async_client;
use forgejo_api::structs::{
AccessToken, CreateTeamOption, CreateTeamOptionPermission, EditTeamOption,
EditTeamOptionPermission, RepoSearchQuery, Team, TeamPermission,
@ -175,7 +175,7 @@ impl Client {
)
.await?;
async_client(self.url.clone(), &StaticToken::new(&credential.value))
async_client(self.url.clone(), &credential.value)
.context("building a forge client with the new token")?
.repo_search(RepoSearchQuery::default())
.await

View file

@ -21,7 +21,7 @@ use std::time::Duration;
use anyhow::{Context, Result};
use base64::Engine as _;
use forge_client::{StaticToken, async_client};
use forge_client::async_client;
use forgejo_api::structs::{CreateAccessTokenOption, UpdateUserAvatarOption};
use sha2::{Digest as _, Sha256};
@ -177,7 +177,7 @@ impl Client {
.sha1
.filter(|v| !v.is_empty())
.with_context(|| format!("the forge created {login}'s token but returned no value"))?;
let uploaded = async_client(self.url.clone(), &StaticToken::new(&token))
let uploaded = async_client(self.url.clone(), &token)
.context("building a forge client with the avatar token")?
.user_update_avatar(UpdateUserAvatarOption {
image: Some(base64::engine::general_purpose::STANDARD.encode(image)),

View file

@ -2542,8 +2542,7 @@ mod tests {
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let url = url::Url::parse(&format!("http://{}/", listener.local_addr().unwrap())).unwrap();
drop(listener);
let forge =
forge_client::async_client(url, &forge_client::StaticToken::new("stub-token")).unwrap();
let forge = forge_client::async_client(url, "stub-token").unwrap();
forge.user_get_current().await.expect_err("nothing listens")
}