Skip to content

Commit

Permalink
chore: revert auth json (#7026)
Browse files Browse the repository at this point in the history
### Description

Given current staffing and the fact that the `auth.json` isn't a big
feature for the next minor release we want to get more testing to make
sure that all of our existing authentication strategies still work with
`auth.json`. At the moment `TURBO_TOKEN` isn't respected, this PR should
fix that.
```
[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ TURBO_TOKEN=*** turbo_dev build --filter=docs --remote-only --output-logs new-only
 WARNING  no caches are enabled
...
```

This is a revert of the following PRs
- #6880 
- #6889 
- #6927 
which make up all of the usage of `auth.json`.

### Testing Instructions

Existing tests and 👀 making sure that I reverted everything correctly

Make sure that setting `TURBO_TOKEN` works as expected:
```
[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ turbo_dev info | head -n 3
You are not logged in
44 packages found in workspace

[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ TURBO_TOKEN=*** turbo_dev build --filter=docs --remote-only --output-logs new-only
• Packages in scope: docs
• Running build in 1 packages
• Remote caching enabled
@turbo/workspaces:build: cache hit (outputs already on disk), suppressing logs 01ead40ee62658af
docs:rss: cache hit, suppressing logs c569e716da69384d
docs:schema: cache hit, suppressing logs c7438141455c2a98
@turbo/gen:build: cache hit, suppressing logs e0ef70531aac79d7
docs:build: cache hit (outputs already on disk), suppressing logs 9e268e56e4cb8842

 Tasks:    5 successful, 5 total
Cached:    5 cached, 5 total
  Time:    1.01s >>> FULL TURBO
```

Closes TURBO-2061
  • Loading branch information
chris-olszewski authored Jan 19, 2024
1 parent ccda1e3 commit 4d2ce96
Show file tree
Hide file tree
Showing 44 changed files with 841 additions and 1,753 deletions.
5 changes: 0 additions & 5 deletions Cargo.lock

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

5 changes: 0 additions & 5 deletions cli/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ func (c *APIClient) SetToken(token string) {
c.token = token
}

// BaseURL returns the APIClient's base URL
func (c *APIClient) BaseURL() string {
return c.baseURL
}

// NewClient creates a new APIClient
func NewClient(config turbostate.APIClientConfig, logger hclog.Logger, turboVersion string) *APIClient {
client := &APIClient{
Expand Down
15 changes: 0 additions & 15 deletions cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
gocontext "context"
"fmt"
"sort"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -433,20 +432,6 @@ func (r *run) initAnalyticsClient(ctx gocontext.Context) analytics.Client {

if apiClient.IsLinked() {
analyticsSink = apiClient
if r.base.Config.Token == "" {
apiBase := r.base.APIClient.BaseURL()
// If it's a third party cache, tell the user to login with that API.
loginCommand := fmt.Sprintf("turbo login%s", func() string {
if strings.Contains(apiBase, "vercel") {
return ""
}
return fmt.Sprintf(" --api %s", apiBase)
}())

missingTokenMessage := fmt.Sprintf("No token found for %s. Run `turbo link` or %s first.", apiBase, loginCommand)

r.base.UI.Warn(missingTokenMessage)
}
} else {
r.opts.cacheOpts.SkipRemote = true
analyticsSink = analytics.NullSink
Expand Down
23 changes: 1 addition & 22 deletions crates/turborepo-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use serde::Deserialize;
use turborepo_ci::{is_ci, Vendor};
use turborepo_vercel_api::{
APIError, CachingStatus, CachingStatusResponse, PreflightResponse, SpacesResponse, Team,
TeamsResponse, TokenMetadata, TokenMetadataResponse, UserResponse, VerificationResponse,
VerifiedSsoUser,
TeamsResponse, UserResponse, VerificationResponse, VerifiedSsoUser,
};
use url::Url;

Expand All @@ -33,7 +32,6 @@ 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 @@ -46,7 +44,6 @@ 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 @@ -101,24 +98,6 @@ 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: 0 additions & 4 deletions crates/turborepo-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ 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
Loading

1 comment on commit 4d2ce96

@vercel
Copy link

@vercel vercel bot commented on 4d2ce96 Jan 19, 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.