Skip to content

Commit

Permalink
remove namespace first part
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburniske committed Mar 27, 2024
1 parent 41c2dd1 commit 94c65bf
Show file tree
Hide file tree
Showing 17 changed files with 481 additions and 664 deletions.
28 changes: 28 additions & 0 deletions golem-service-base/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3116,3 +3116,31 @@ impl From<GrpcRoutingTableEntry> for RoutingTableEntry {
}
}
}

#[derive(
Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, serde::Serialize, serde::Deserialize, Object,
)]
#[serde(rename_all = "camelCase")]
#[oai(rename_all = "camelCase")]
pub struct ResourceLimits {
pub available_fuel: i64,
pub max_memory_per_worker: i64,
}

impl From<ResourceLimits> for golem_api_grpc::proto::golem::common::ResourceLimits {
fn from(value: ResourceLimits) -> Self {
Self {
available_fuel: value.available_fuel,
max_memory_per_worker: value.max_memory_per_worker,
}
}
}

impl From<golem_api_grpc::proto::golem::common::ResourceLimits> for ResourceLimits {
fn from(value: golem_api_grpc::proto::golem::common::ResourceLimits) -> Self {
Self {
available_fuel: value.available_fuel,
max_memory_per_worker: value.max_memory_per_worker,
}
}
}
7 changes: 0 additions & 7 deletions golem-worker-service-base/src/api/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ impl ApiEndpointError {
}

mod conversion {
use golem_service_base::service::auth::AuthError;
use poem_openapi::payload::Json;

use super::{
Expand All @@ -112,12 +111,6 @@ mod conversion {
impl From<ApiRegistrationError> for ApiEndpointError {
fn from(error: ApiRegistrationError) -> Self {
match error {
ApiRegistrationError::AuthenticationError(auth) => match auth {
AuthError::Forbidden(_) => ApiEndpointError::forbidden(auth),
AuthError::Unauthorized(_) => ApiEndpointError::unauthorized(auth),
AuthError::Internal(_) => ApiEndpointError::internal(auth),
AuthError::NotFound(_) => ApiEndpointError::not_found(auth),
},
ApiRegistrationError::RepoError(error) => match error {
ApiRegistrationRepoError::AlreadyExists(_) => {
ApiEndpointError::already_exists(error)
Expand Down
47 changes: 9 additions & 38 deletions golem-worker-service-base/src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use std::fmt::{Display, Formatter};

use async_trait::async_trait;
use golem_api_grpc::proto::golem::common::ResourceLimits;
use golem_common::model::AccountId;
use golem_service_base::service::auth::{AuthError, AuthService, Permission};
use serde::Deserialize;

pub struct AuthServiceNoop {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct EmptyAuthCtx {}

Expand All @@ -16,6 +11,15 @@ impl Display for EmptyAuthCtx {
}
}

impl IntoIterator for EmptyAuthCtx {
type Item = (String, String);
type IntoIter = std::iter::Empty<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
std::iter::empty()
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, bincode::Encode, bincode::Decode, Deserialize)]
pub struct CommonNamespace(String);

Expand All @@ -30,36 +34,3 @@ impl Display for CommonNamespace {
write!(f, "{}", self.0)
}
}

#[async_trait]
impl<AuthCtx, Namespace: Default> AuthService<AuthCtx, Namespace> for AuthServiceNoop {
async fn is_authorized(
&self,
_permission: Permission,
_ctx: &AuthCtx,
) -> Result<Namespace, AuthError> {
Ok(Namespace::default())
}
}

// TODO: Replace with metadata map
pub trait HasMetadata {
fn get_metadata(&self) -> WorkerMetadata;
}

#[derive(Clone, Debug)]
pub struct WorkerMetadata {
pub account_id: Option<AccountId>,
pub limits: Option<ResourceLimits>,
}

impl HasMetadata for CommonNamespace {
fn get_metadata(&self) -> WorkerMetadata {
WorkerMetadata {
account_id: Some(golem_common::model::AccountId {
value: "-1".to_string(),
}),
limits: None,
}
}
}
Loading

0 comments on commit 94c65bf

Please sign in to comment.