Skip to content

Commit

Permalink
Revert "revert auth json (#6883)" (#6889)
Browse files Browse the repository at this point in the history
This reverts commit d965c4c.

### Description
Basically putting back `auth.json` stuff.

### Testing Instructions
Build Turborepo


Closes TURBO-1993
  • Loading branch information
Zertsov committed Jan 4, 2024
1 parent 81e48ff commit 2ab5616
Show file tree
Hide file tree
Showing 39 changed files with 1,632 additions and 846 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion crates/turborepo-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use serde::Deserialize;
use turborepo_ci::{is_ci, Vendor};
use turborepo_vercel_api::{
APIError, CachingStatus, CachingStatusResponse, PreflightResponse, SpacesResponse, Team,
TeamsResponse, UserResponse, VerificationResponse, VerifiedSsoUser,
TeamsResponse, TokenMetadata, TokenMetadataResponse, UserResponse, VerificationResponse,
VerifiedSsoUser,
};
use url::Url;

Expand All @@ -32,6 +33,7 @@ lazy_static! {

#[async_trait]
pub trait Client {
fn base_url(&self) -> &str;
async fn get_user(&self, token: &str) -> Result<UserResponse>;
async fn get_teams(&self, token: &str) -> Result<TeamsResponse>;
async fn get_team(&self, token: &str, team_id: &str) -> Result<Option<Team>>;
Expand All @@ -44,6 +46,7 @@ pub trait Client {
) -> Result<CachingStatusResponse>;
async fn get_spaces(&self, token: &str, team_id: Option<&str>) -> Result<SpacesResponse>;
async fn verify_sso_token(&self, token: &str, token_name: &str) -> Result<VerifiedSsoUser>;
async fn get_token_metadata(&self, token: &str) -> Result<TokenMetadata>;
#[allow(clippy::too_many_arguments)]
async fn put_artifact(
&self,
Expand Down Expand Up @@ -105,6 +108,24 @@ pub struct APIAuth {

#[async_trait]
impl Client for APIClient {
fn base_url(&self) -> &str {
&self.base_url
}
async fn get_token_metadata(&self, token: &str) -> Result<TokenMetadata> {
let url = self.make_url("/v5/user/tokens/current");
let request_builder = self
.client
.get(url)
.header("User-Agent", self.user_agent.clone())
.header("Authorization", format!("Bearer {}", token))
.header("Content-Type", "application/json");
let response = retry::make_retryable_request(request_builder)
.await?
.error_for_status()?;
let json: TokenMetadataResponse = response.json().await?;

Ok(json.token)
}
async fn get_user(&self, token: &str) -> Result<UserResponse> {
let url = self.make_url("/v2/user");
let request_builder = self
Expand Down
4 changes: 4 additions & 0 deletions crates/turborepo-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ async-trait.workspace = true
axum-server = { workspace = true }
axum.workspace = true
chrono.workspace = true
dirs-next = "2.0.0"
hostname = "0.3.1"
lazy_static.workspace = true
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
tempfile.workspace = true
thiserror = "1.0.38"
tokio.workspace = true
tracing.workspace = true
turbopath = { workspace = true }
turborepo-api-client = { workspace = true }
turborepo-ui.workspace = true
turborepo-vercel-api = { workspace = true }
Expand Down

1 comment on commit 2ab5616

@vercel
Copy link

@vercel vercel bot commented on 2ab5616 Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.