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

Config polling #86

Merged
merged 10 commits into from
Sep 6, 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
2 changes: 1 addition & 1 deletion proto
Submodule proto updated 1 files
+12 −0 core/proxy.proto
3 changes: 1 addition & 2 deletions src/handlers/enrollment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ pub async fn activate_user(
let payload = get_core_response(rx).await?;
debug!("Receving payload from the core service. Trying to remove private cookie...");
if let core_response::Payload::Empty(()) = payload {
info!("Activated user - phone number {phone:?}");
if let Some(cookie) = private_cookies.get(ENROLLMENT_COOKIE_NAME) {
info!("Activated user - phone number {phone:?}");
debug!("Enrollment finished. Removing session cookie");
private_cookies = private_cookies.remove(cookie);
}

Ok(private_cookies)
} else {
error!("Received invalid gRPC response type: {payload:#?}");
Expand Down
9 changes: 5 additions & 4 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
pub(crate) mod desktop_client_mfa;
pub(crate) mod enrollment;
pub(crate) mod password_reset;

use crate::{error::ApiError, proto::core_response::Payload};
use axum::{extract::FromRequestParts, http::request::Parts};
use axum_client_ip::{InsecureClientIp, LeftmostXForwardedFor};
Expand All @@ -11,6 +7,11 @@ use tokio::{sync::oneshot::Receiver, time::timeout};

use super::proto::DeviceInfo;

pub(crate) mod desktop_client_mfa;
pub(crate) mod enrollment;
pub(crate) mod password_reset;
pub(crate) mod polling;

// timeout in seconds for awaiting core response
const CORE_RESPONSE_TIMEOUT: u64 = 5;

Expand Down
28 changes: 28 additions & 0 deletions src/handlers/polling.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use axum::{extract::State, Json};

use crate::{
error::ApiError,
handlers::get_core_response,
http::AppState,
proto::{core_request, core_response, InstanceInfoRequest, InstanceInfoResponse},
};

#[instrument(level = "debug", skip(state))]
pub async fn info(
State(state): State<AppState>,
Json(req): Json<InstanceInfoRequest>,
) -> Result<Json<InstanceInfoResponse>, ApiError> {
debug!("Retrieving info for polling request");
let rx = state
.grpc_server
.send(Some(core_request::Payload::InstanceInfo(req.clone())), None)?;
let payload = get_core_response(rx).await?;

if let core_response::Payload::InstanceInfo(response) = payload {
info!("Retrieved info for polling request");
Ok(Json(response))
} else {
error!("Received invalid gRPC response type: {payload:#?}");
Err(ApiError::InvalidResponseType)
}
}
5 changes: 3 additions & 2 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use axum::{
body::Body,
extract::{ConnectInfo, FromRef, State},
http::{Request, StatusCode},
routing::get,
routing::{get, post},
serve, Json, Router,
};
use axum_extra::extract::cookie::Key;
Expand All @@ -29,7 +29,7 @@ use crate::{
config::Config,
error::ApiError,
grpc::ProxyServer,
handlers::{desktop_client_mfa, enrollment, password_reset},
handlers::{desktop_client_mfa, enrollment, password_reset, polling},
proto::proxy_server,
};

Expand Down Expand Up @@ -188,6 +188,7 @@ pub async fn run_server(config: Config) -> anyhow::Result<()> {
.nest("/enrollment", enrollment::router())
.nest("/password-reset", password_reset::router())
.nest("/client-mfa", desktop_client_mfa::router())
.route("/poll", post(polling::info))
.route("/health", get(healthcheck))
.route("/health-grpc", get(healthcheckgrpc))
.route("/info", get(app_info)),
Expand Down
2 changes: 1 addition & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
plugins: [react()],
server: {
strictPort: true,
port: 3000,
port: 3002,
proxy: {
'/api': {
target: 'http://127.0.0.1:8080/',
Expand Down