-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fixup! fixup! fixup! fixup! fixup! wip
- Loading branch information
Showing
12 changed files
with
270 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,67 @@ | ||
use crate::configuration::action::Action; | ||
use crate::configuration::Service; | ||
use crate::configuration::{FailureMode, Service}; | ||
use crate::data::Predicate; | ||
use crate::service::GrpcService; | ||
use log::error; | ||
use std::cell::OnceCell; | ||
use std::rc::Rc; | ||
|
||
pub struct AuthAction {} | ||
#[derive(Clone, Debug)] | ||
pub struct AuthAction { | ||
grpc_service: Rc<GrpcService>, | ||
scope: String, | ||
predicates: OnceCell<Vec<Predicate>>, | ||
} | ||
|
||
impl AuthAction { | ||
pub fn new(action: &Action, service: &Service) -> Result<Self, String> { | ||
todo!() | ||
let mut predicates = Vec::default(); | ||
for predicate in &action.predicates { | ||
predicates.push(Predicate::new(predicate).map_err(|e| e.to_string())?); | ||
} | ||
|
||
let auth_action = AuthAction { | ||
grpc_service: Rc::new(GrpcService::new(Rc::new(service.clone()))), | ||
scope: action.scope.clone(), | ||
predicates: OnceCell::new(), | ||
}; | ||
|
||
auth_action | ||
.predicates | ||
.set(predicates) | ||
.expect("Predicates must not be compiled yet!"); | ||
|
||
Ok(auth_action) | ||
} | ||
|
||
pub fn get_grpcservice(&self) -> Rc<GrpcService> { | ||
Rc::clone(&self.grpc_service) | ||
} | ||
|
||
pub fn service(&self) -> &str { | ||
self.grpc_service.name() | ||
} | ||
|
||
pub fn scope(&self) -> &str { | ||
self.scope.as_str() | ||
} | ||
|
||
pub fn conditions_apply(&self) -> bool { | ||
let predicates = self | ||
.predicates | ||
.get() | ||
.expect("predicates must be compiled by now"); | ||
predicates.is_empty() | ||
|| predicates.iter().all(|predicate| match predicate.test() { | ||
Ok(b) => b, | ||
Err(err) => { | ||
error!("Failed to evaluate {:?}: {}", predicate, err); | ||
panic!("Err out of this!") | ||
} | ||
}) | ||
} | ||
|
||
pub fn get_failure_mode(&self) -> FailureMode { | ||
self.grpc_service.get_failure_mode() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.