-
Notifications
You must be signed in to change notification settings - Fork 3
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
Adding the option to use a new crd modules in policies #2
base: main
Are you sure you want to change the base?
Changes from 1 commit
04e5df2
4bd5fea
350e139
b06776f
8832169
ce165df
541b8a1
cde6a42
1bc3a93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ pub struct PolicyStore { | |
pub policies: HashMap<String, PolicyInfo>, | ||
} | ||
|
||
pub type PolicyStoreRef = Arc<Mutex<PolicyStore>>; | ||
pub type PolicyStoreRef = Arc<Mutex<dyn ObjectStore<Policy, HashMap<String, PolicyInfo>> + Send>>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to use the trait here. |
||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct PolicyInfo { | ||
|
@@ -94,7 +94,7 @@ impl PolicyInfo { | |
} | ||
} | ||
|
||
impl ObjectStore<Policy> for PolicyStore { | ||
impl ObjectStore<Policy, HashMap<String, PolicyInfo>> for PolicyStore { | ||
fn add_object(&mut self, policy: Policy) -> Option<ObjectReference> { | ||
let ref_info = create_object_reference(&policy); | ||
let name = policy.metadata.name.expect("name is always set"); | ||
|
@@ -122,6 +122,10 @@ impl ObjectStore<Policy> for PolicyStore { | |
self.policies.remove(&name); | ||
ACTIVE_POLICIES.dec(); | ||
} | ||
|
||
fn get_objects(&self) -> HashMap<String, PolicyInfo> { | ||
return self.policies.clone(); | ||
} | ||
} | ||
|
||
pub fn load_policies_from_file(policies: PolicyStoreRef, filename: &str) -> Result<usize> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use crate::util::types::ObjectReference; | ||
|
||
pub trait ObjectStore<T> { | ||
pub trait ObjectStore<T, V> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if using a trait is actually beneficial. At the moment all code that uses either policies or modules is specific for that so we cannot really take advantage of the trait. |
||
fn add_object(&mut self, object: T) -> Option<ObjectReference>; | ||
fn remove_object(&mut self, object: T); | ||
fn get_objects(&self) -> V; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to use the trait here.