Skip to content

Commit

Permalink
Merge branch 'dev' into add-teonite-link
Browse files Browse the repository at this point in the history
  • Loading branch information
t-aleksander authored Sep 13, 2024
2 parents 8146c1b + 96d1602 commit 1577d69
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion proto
Submodule proto updated 1 files
+2 −6 core/proxy.proto
17 changes: 14 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::proto::CoreError;
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
Json,
};
use serde_json::json;
use tonic::metadata::errors::InvalidMetadataValue;
use tonic::{Code, Status};
use tonic::{metadata::errors::InvalidMetadataValue, Code, Status};

use crate::proto::CoreError;

#[derive(thiserror::Error, Debug)]
pub enum ApiError {
Expand All @@ -24,6 +24,8 @@ pub enum ApiError {
InvalidResponseType,
#[error("Permission denied: {0}")]
PermissionDenied(String),
#[error("Enterprise not enabled")]
EnterpriseNotEnabled,
}

impl IntoResponse for ApiError {
Expand All @@ -33,6 +35,10 @@ impl IntoResponse for ApiError {
Self::Unauthorized(msg) => (StatusCode::UNAUTHORIZED, msg),
Self::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg),
Self::PermissionDenied(msg) => (StatusCode::FORBIDDEN, msg),
Self::EnterpriseNotEnabled => (
StatusCode::PAYMENT_REQUIRED,
"Enterprise features are not enabled".to_string(),
),
_ => (
StatusCode::INTERNAL_SERVER_ERROR,
"Internal server error".to_string(),
Expand All @@ -55,6 +61,11 @@ impl From<CoreError> for ApiError {
Code::Unauthenticated => ApiError::Unauthorized(status.message().to_string()),
Code::InvalidArgument => ApiError::BadRequest(status.message().to_string()),
Code::PermissionDenied => ApiError::PermissionDenied(status.message().to_string()),
Code::FailedPrecondition => match status.message().to_lowercase().as_str() {
// TODO: find a better way than matching on the error message
"no valid license" => ApiError::EnterpriseNotEnabled,
_ => ApiError::Unexpected(status.to_string()),
},
_ => ApiError::Unexpected(status.to_string()),
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::{error::ApiError, proto::core_response::Payload};
use std::time::Duration;

use axum::{extract::FromRequestParts, http::request::Parts};
use axum_client_ip::{InsecureClientIp, LeftmostXForwardedFor};
use axum_extra::{headers::UserAgent, TypedHeader};
use std::time::Duration;
use tokio::{sync::oneshot::Receiver, time::timeout};

use super::proto::DeviceInfo;
use crate::{error::ApiError, proto::core_response::Payload};

pub(crate) mod desktop_client_mfa;
pub(crate) mod enrollment;
Expand Down

0 comments on commit 1577d69

Please sign in to comment.