Skip to content

Commit

Permalink
RebacServiceImpl: inject default properties
Browse files Browse the repository at this point in the history
  • Loading branch information
s373r committed Jan 17, 2025
1 parent bfb5e89 commit db7bf39
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ impl DatasetAuthorizerHarness {
.add_value(predefined_accounts_config)
.add::<PredefinedAccountsRegistrator>()
.add::<kamu_auth_rebac_services::RebacServiceImpl>()
.add_value(kamu_auth_rebac_services::DefaultAccountProperties { is_admin: false })
.add_value(kamu_auth_rebac_services::DefaultDatasetProperties {
allows_anonymous_read: false,
allows_public_read: false,
})
.add::<kamu_auth_rebac_services::MultiTenantRebacDatasetLifecycleMessageConsumer>()
.add::<InMemoryRebacRepository>()
.add_builder(
Expand Down
5 changes: 5 additions & 0 deletions src/adapter/graphql/tests/tests/test_gql_datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,11 @@ impl GraphQLDatasetsHarness {
.bind::<dyn AuthenticationService, MockAuthenticationService>()
.add::<auth::AlwaysHappyDatasetActionAuthorizer>()
.add::<RebacServiceImpl>()
.add_value(kamu_auth_rebac_services::DefaultAccountProperties { is_admin: false })
.add_value(kamu_auth_rebac_services::DefaultDatasetProperties {
allows_anonymous_read: false,
allows_public_read: false,
})
.add::<InMemoryRebacRepository>();

if tenancy_config == TenancyConfig::MultiTenant {
Expand Down
5 changes: 5 additions & 0 deletions src/app/cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ pub fn configure_base_catalog(
b.add::<DatabaseTransactionRunner>();

b.add::<kamu_auth_rebac_services::RebacServiceImpl>();
b.add_value(kamu_auth_rebac_services::DefaultAccountProperties { is_admin: false });
b.add_value(kamu_auth_rebac_services::DefaultDatasetProperties {
allows_anonymous_read: false,
allows_public_read: false,
});

b.add::<kamu_adapter_flight_sql::SessionAuthAnonymous>();
b.add::<kamu_adapter_flight_sql::SessionManagerCaching>();
Expand Down
4 changes: 2 additions & 2 deletions src/domain/auth-rebac/domain/src/services/rebac_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub trait RebacService: Send + Sync {

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(Debug, Default)]
#[derive(Debug, Clone)]
pub struct AccountProperties {
pub is_admin: bool,
}
Expand All @@ -120,7 +120,7 @@ impl AccountProperties {

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(Debug, Default)]
#[derive(Debug, Clone)]
pub struct DatasetProperties {
pub allows_anonymous_read: bool,
pub allows_public_read: bool,
Expand Down
28 changes: 23 additions & 5 deletions src/domain/auth-rebac/services/src/rebac_service_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,30 @@ use opendatafabric as odf;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

pub type DefaultAccountProperties = AccountProperties;
pub type DefaultDatasetProperties = DatasetProperties;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

pub struct RebacServiceImpl {
rebac_repo: Arc<dyn RebacRepository>,
default_account_properties: Arc<DefaultAccountProperties>,
default_dataset_properties: Arc<DefaultDatasetProperties>,
}

#[component(pub)]
#[interface(dyn RebacService)]
impl RebacServiceImpl {
pub fn new(rebac_repo: Arc<dyn RebacRepository>) -> Self {
Self { rebac_repo }
pub fn new(
rebac_repo: Arc<dyn RebacRepository>,
default_account_properties: Arc<DefaultAccountProperties>,
default_dataset_properties: Arc<DefaultDatasetProperties>,
) -> Self {
Self {
rebac_repo,
default_account_properties,
default_dataset_properties,
}
}
}

Expand Down Expand Up @@ -103,13 +118,14 @@ impl RebacService for RebacServiceImpl {
.await
.int_err()?;

let default_account_properties = (*self.default_account_properties).clone();
let account_properties = entity_properties
.into_iter()
.map(|(name, value)| match name {
PropertyName::Dataset(_) => unreachable!(),
PropertyName::Account(account_property_name) => (account_property_name, value),
})
.fold(AccountProperties::default(), |mut acc, (name, value)| {
.fold(default_account_properties, |mut acc, (name, value)| {
acc.apply(name, &value);
acc
});
Expand Down Expand Up @@ -180,13 +196,14 @@ impl RebacService for RebacServiceImpl {
.await
.int_err()?;

let default_dataset_properties = (*self.default_dataset_properties).clone();
let dataset_properties = entity_properties
.into_iter()
.map(|(name, value)| match name {
PropertyName::Dataset(dataset_property_name) => (dataset_property_name, value),
PropertyName::Account(_) => unreachable!(),
})
.fold(DatasetProperties::default(), |mut acc, (name, value)| {
.fold(default_dataset_properties, |mut acc, (name, value)| {
acc.apply(name, &value);
acc
});
Expand All @@ -210,9 +227,10 @@ impl RebacService for RebacServiceImpl {
.int_err()?;

let mut dataset_properties_map = HashMap::new();
let default_dataset_properties = (*self.default_dataset_properties).clone();

for dataset_id in dataset_ids {
dataset_properties_map.insert(dataset_id.clone(), DatasetProperties::default());
dataset_properties_map.insert(dataset_id.clone(), default_dataset_properties.clone());
}

let entity_properties_it =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ impl MultiTenantRebacDatasetLifecycleMessageConsumerHarness {
catalog_builder
.add::<MultiTenantRebacDatasetLifecycleMessageConsumer>()
.add::<RebacServiceImpl>()
.add_value(kamu_auth_rebac_services::DefaultAccountProperties { is_admin: false })
.add_value(kamu_auth_rebac_services::DefaultDatasetProperties {
allows_anonymous_read: false,
allows_public_read: false,
})
.add::<InMemoryRebacRepository>();

let catalog = catalog_builder.build();
Expand Down

0 comments on commit db7bf39

Please sign in to comment.