Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use graphql(skip) to omit field in graphql response #1863

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ee/tabby-webserver/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ enum LicenseType {
type OAuthCredential {
provider: OAuthProvider!
clientId: String!
clientSecret: String
createdAt: DateTimeUtc!
updatedAt: DateTimeUtc!
}
Expand Down
6 changes: 2 additions & 4 deletions ee/tabby-webserver/src/oauth/github.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use anyhow::{anyhow, Result};
use anyhow::Result;
use async_trait::async_trait;
use serde::Deserialize;

Expand Down Expand Up @@ -63,9 +63,7 @@ impl GithubClient {
code: String,
credential: OAuthCredential,
) -> Result<GithubOAuthResponse> {
let Some(client_secret) = credential.client_secret else {
return Err(anyhow!("No client_secret present"));
};
let client_secret = credential.client_secret;

let params = [
("client_id", credential.client_id.as_str()),
Expand Down
6 changes: 2 additions & 4 deletions ee/tabby-webserver/src/oauth/google.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use anyhow::{anyhow, Result};
use anyhow::Result;
use async_trait::async_trait;
use serde::Deserialize;

Expand Down Expand Up @@ -65,9 +65,7 @@ impl GoogleClient {
credential: OAuthCredential,
redirect_uri: String,
) -> Result<GoogleOAuthResponse> {
let Some(client_secret) = credential.client_secret else {
return Err(anyhow!("No client_secret present"));
};
let client_secret = credential.client_secret;

let params = [
("client_id", credential.client_id.as_str()),
Expand Down
3 changes: 2 additions & 1 deletion ee/tabby-webserver/src/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ pub struct OAuthCredential {
pub provider: OAuthProvider,
pub client_id: String,

pub client_secret: Option<String>,
#[graphql(skip)]
pub client_secret: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
Expand Down
9 changes: 1 addition & 8 deletions ee/tabby-webserver/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,7 @@ impl Query {
provider: OAuthProvider,
) -> Result<Option<OAuthCredential>> {
check_admin(ctx).await?;
let Some(mut credentials) = ctx.locator.auth().read_oauth_credential(provider).await?
else {
return Ok(None);
};

// Client secret is not visible from GraphQL api.
credentials.client_secret = None;
Ok(Some(credentials))
ctx.locator.auth().read_oauth_credential(provider).await
}

async fn oauth_callback_url(ctx: &Context, provider: OAuthProvider) -> Result<String> {
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/service/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,6 @@ mod tests {
.unwrap();
assert_eq!(cred.provider, OAuthProvider::Google);
assert_eq!(cred.client_id, "id");
assert_eq!(cred.client_secret, Some("secret".into()));
assert_eq!(cred.client_secret, "secret");
}
}
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/service/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl TryFrom<OAuthCredentialDAO> for OAuthCredential {
client_id: val.client_id,
created_at: *val.created_at,
updated_at: *val.updated_at,
client_secret: Some(val.client_secret),
client_secret: val.client_secret,
})
}
}
Expand Down
Loading