Skip to content

Commit

Permalink
feat(query): add api /v1/verify (#16665)
Browse files Browse the repository at this point in the history
* feat(query): add api /v1/verify

* z

* z

* z

---------

Co-authored-by: Bohu <overred.shuttler@gmail.com>
  • Loading branch information
everpcpc and BohuTANG authored Oct 28, 2024
1 parent a2b8adc commit bd380ee
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/query/service/src/servers/http/v1/http_query_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use crate::servers::http::v1::query::string_block::StringBlock;
use crate::servers::http::v1::query::Progresses;
use crate::servers::http::v1::refresh_handler;
use crate::servers::http::v1::upload_to_stage;
use crate::servers::http::v1::verify_handler;
use crate::servers::http::v1::HttpQueryContext;
use crate::servers::http::v1::HttpQueryManager;
use crate::servers::http::v1::HttpSessionConf;
Expand Down Expand Up @@ -446,7 +447,7 @@ pub fn query_route() -> Route {
post(refresh_handler),
EndpointKind::Refresh,
),
("/auth/verify", post(refresh_handler), EndpointKind::Verify),
("/verify", post(verify_handler), EndpointKind::Verify),
(
"/upload_to_stage",
put(upload_to_stage),
Expand Down
2 changes: 2 additions & 0 deletions src/query/service/src/servers/http/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod query;
mod session;
mod stage;
mod suggestions;
mod verify;

pub use discovery::discovery_nodes;
pub use http_query_handlers::make_final_uri;
Expand All @@ -44,6 +45,7 @@ pub use stage::upload_to_stage;
pub use stage::UploadToStageResponse;
pub use suggestions::list_suggestions;
pub use suggestions::SuggestionsResponse;
pub use verify::verify_handler;

pub use crate::servers::http::clickhouse_handler::clickhouse_router;
pub use crate::servers::http::error::QueryError;
43 changes: 43 additions & 0 deletions src/query/service/src/servers/http/v1/verify.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use jwt_simple::prelude::Serialize;
use poem::error::Result as PoemResult;
use poem::web::Json;
use poem::IntoResponse;

use crate::servers::http::error::HttpErrorCode;
use crate::servers::http::v1::HttpQueryContext;

#[derive(Serialize, Debug, Clone)]
pub struct VerifyResponse {
tenant: String,
user: String,
roles: Vec<String>,
}

#[poem::handler]
#[async_backtrace::framed]
pub async fn verify_handler(ctx: &HttpQueryContext) -> PoemResult<impl IntoResponse> {
let tenant = ctx.session.get_current_tenant();
let user = ctx
.session
.get_current_user()
.map_err(HttpErrorCode::server_error)?;
Ok(Json(VerifyResponse {
tenant: tenant.tenant_name().to_string(),
user: user.name.to_string(),
roles: user.grants.roles(),
}))
}
2 changes: 1 addition & 1 deletion tests/suites/1_stateful/09_http_handler/09_0007_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
login_url = "http://localhost:8000/v1/session/login"
logout_url = "http://localhost:8000/v1/session/logout"
renew_url = "http://localhost:8000/v1/session/refresh"
verify_url = "http://localhost:8000/v1/auth/verify"
verify_url = "http://localhost:8000/v1/verify"
auth = ("root", "")


Expand Down

0 comments on commit bd380ee

Please sign in to comment.