Skip to content

Commit

Permalink
remove AuthService
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburniske committed Mar 27, 2024
1 parent 94c65bf commit 220c8b6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 145 deletions.
71 changes: 0 additions & 71 deletions golem-service-base/src/service/auth.rs

This file was deleted.

1 change: 0 additions & 1 deletion golem-service-base/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod auth;
pub mod template_object_store;
32 changes: 9 additions & 23 deletions golem-worker-service-base/src/api/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::service::template::TemplateServiceError;
use crate::service::worker::WorkerServiceError;
use golem_service_base::model::*;
use golem_service_base::service::auth::AuthError;
use poem_openapi::payload::Json;
use poem_openapi::*;
use tonic::Status;
Expand Down Expand Up @@ -67,7 +66,6 @@ impl From<WorkerServiceError> for WorkerApiBaseError {
}

match error {
ServiceError::Auth(error) => error.into(),
ServiceError::Internal(_) => internal(error.to_string()),
ServiceError::TypeChecker(_) => WorkerApiBaseError::BadRequest(Json(ErrorsBody {
errors: vec![error.to_string()],
Expand Down Expand Up @@ -102,28 +100,16 @@ impl From<TemplateServiceError> for WorkerApiBaseError {
}),
}))
}
TemplateServiceError::Auth(error) => error.into(),
}
}
}

impl From<AuthError> for WorkerApiBaseError {
fn from(error: AuthError) -> Self {
match error {
AuthError::Unauthorized(_) => WorkerApiBaseError::Unauthorized(Json(ErrorBody {
error: error.to_string(),
})),
AuthError::Forbidden(_) => WorkerApiBaseError::Forbidden(Json(ErrorBody {
error: error.to_string(),
})),
AuthError::NotFound(_) => WorkerApiBaseError::NotFound(Json(ErrorBody {
error: error.to_string(),
})),
AuthError::Internal(_) => WorkerApiBaseError::InternalError(Json(GolemErrorBody {
golem_error: GolemError::Unknown(GolemErrorUnknown {
details: error.to_string(),
}),
})),
TemplateServiceError::NotFound(error) => {
WorkerApiBaseError::NotFound(Json(ErrorBody { error }))
}
TemplateServiceError::Unauthorized(error) => {
WorkerApiBaseError::Unauthorized(Json(ErrorBody { error }))
}
TemplateServiceError::Forbidden(error) => {
WorkerApiBaseError::Forbidden(Json(ErrorBody { error }))
}
}
}
}
42 changes: 18 additions & 24 deletions golem-worker-service-base/src/service/template/error.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use golem_api_grpc::proto::golem::worker::{
self, worker_error, worker_execution_error, UnknownError, WorkerError as GrpcWorkerError,
};
use golem_service_base::service::auth::AuthError;
use tonic::Status;

// The dependents of golem-worker-service-base is expected
// to have a template service internally that can depend on this base error
#[derive(Debug, thiserror::Error)]
pub enum TemplateServiceError {
#[error(transparent)]
Auth(#[from] AuthError),
#[error("Unauthorized: {0}")]
Unauthorized(String),
#[error("Forbidden: {0}")]
Forbidden(String),
#[error("Not found: {0}")]
NotFound(String),
#[error("Bad Request: {0:?}")]
BadRequest(Vec<String>),
#[error("Already Exists: {0}")]
Expand Down Expand Up @@ -44,9 +47,9 @@ impl From<golem_api_grpc::proto::golem::template::TemplateError> for TemplateSer
use golem_api_grpc::proto::golem::template::template_error::Error;
match error.error {
Some(Error::BadRequest(errors)) => TemplateServiceError::BadRequest(errors.errors),
Some(Error::Unauthorized(error)) => AuthError::Unauthorized(error.error).into(),
Some(Error::LimitExceeded(error)) => AuthError::Forbidden(error.error).into(),
Some(Error::NotFound(error)) => AuthError::NotFound(error.error).into(),
Some(Error::Unauthorized(error)) => TemplateServiceError::Unauthorized(error.error),
Some(Error::LimitExceeded(error)) => TemplateServiceError::Forbidden(error.error),
Some(Error::NotFound(error)) => TemplateServiceError::NotFound(error.error),
Some(Error::AlreadyExists(error)) => TemplateServiceError::AlreadyExists(error.error),
Some(Error::InternalError(error)) => {
TemplateServiceError::Internal(anyhow::Error::msg(error.error))
Expand All @@ -69,24 +72,15 @@ impl From<TemplateServiceError> for worker_error::Error {
use golem_api_grpc::proto::golem::common::{ErrorBody, ErrorsBody};

match value {
TemplateServiceError::Auth(error) => match error {
AuthError::Unauthorized(_) => worker_error::Error::Unauthorized(ErrorBody {
error: error.to_string(),
}),
AuthError::Forbidden(_) => worker_error::Error::LimitExceeded(ErrorBody {
error: error.to_string(),
}),
AuthError::NotFound(_) => worker_error::Error::NotFound(ErrorBody {
error: error.to_string(),
}),
AuthError::Internal(_) => {
worker_error::Error::InternalError(worker::WorkerExecutionError {
error: Some(worker_execution_error::Error::Unknown(UnknownError {
details: error.to_string(),
})),
})
}
},
TemplateServiceError::Unauthorized(error) => {
worker_error::Error::Unauthorized(ErrorBody { error })
}
TemplateServiceError::Forbidden(error) => {
worker_error::Error::LimitExceeded(ErrorBody { error })
}
TemplateServiceError::NotFound(error) => {
worker_error::Error::NotFound(ErrorBody { error })
}
TemplateServiceError::AlreadyExists(error) => {
worker_error::Error::AlreadyExists(ErrorBody { error })
}
Expand Down
29 changes: 3 additions & 26 deletions golem-worker-service-base/src/service/worker/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ use golem_api_grpc::proto::golem::worker::{
worker_error, worker_execution_error, UnknownError, WorkerError as GrpcWorkerError,
};
use golem_common::model::{AccountId, TemplateId, WorkerId};
use golem_service_base::{
model::{GolemError, VersionedTemplateId},
service::auth::AuthError,
};
use golem_service_base::model::{GolemError, VersionedTemplateId};

use crate::service::template::TemplateServiceError;

#[derive(Debug, thiserror::Error)]
pub enum WorkerServiceError {
#[error(transparent)]
Auth(#[from] AuthError),
#[error("Internal error: {0}")]
Internal(#[from] anyhow::Error),
#[error(transparent)]
Template(#[from] TemplateServiceError),
// TODO: This should prob be a vec?
Expand All @@ -29,6 +22,8 @@ pub enum WorkerServiceError {
// TODO: Once worker is independent of account
#[error("Worker not found: {0}")]
WorkerNotFound(WorkerId),
#[error("Internal error: {0}")]
Internal(#[from] anyhow::Error),
// TODO: Fix display impl.
#[error("Golem error")]
Golem(GolemError),
Expand Down Expand Up @@ -57,24 +52,6 @@ impl From<WorkerServiceError> for worker_error::Error {
use golem_api_grpc::proto::golem::worker::WorkerExecutionError;

match error {
WorkerServiceError::Auth(error) => match error {
AuthError::Unauthorized(_) => worker_error::Error::Unauthorized(ErrorBody {
error: error.to_string(),
}),
AuthError::Forbidden(_) => worker_error::Error::LimitExceeded(ErrorBody {
error: error.to_string(),
}),
AuthError::NotFound(_) => worker_error::Error::NotFound(ErrorBody {
error: error.to_string(),
}),
AuthError::Internal(_) => {
worker_error::Error::InternalError(WorkerExecutionError {
error: Some(worker_execution_error::Error::Unknown(UnknownError {
details: error.to_string(),
})),
})
}
},
error @ (WorkerServiceError::TemplateNotFound(_)
| WorkerServiceError::AccountIdNotFound(_)
| WorkerServiceError::VersionedTemplateIdNotFound(_)
Expand Down

0 comments on commit 220c8b6

Please sign in to comment.