Skip to content

Commit

Permalink
fix: Making token:account as available instead of token:platform (#357)
Browse files Browse the repository at this point in the history
* fix: Making token:account as available instead of token:platform
  • Loading branch information
Karthick-Somasundaresan authored Feb 28, 2024
1 parent ea3c333 commit 1752167
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 53 deletions.
33 changes: 2 additions & 31 deletions core/main/src/firebolt/handlers/account_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use jsonrpsee::{
use ripple_sdk::{
api::{
distributor::distributor_encoder::EncoderRequest,
firebolt::fb_capabilities::{CapEvent, FireboltCap},
gateway::rpc_gateway_api::CallContext,
session::{AccountSessionRequest, AccountSessionTokenRequest},
},
Expand All @@ -32,8 +31,7 @@ use ripple_sdk::{
};

use crate::{
firebolt::rpc::RippleRPCProvider,
state::{cap::cap_state::CapState, platform_state::PlatformState},
firebolt::rpc::RippleRPCProvider, state::platform_state::PlatformState,
utils::rpc_utils::rpc_err,
};

Expand Down Expand Up @@ -67,34 +65,7 @@ impl AccountServer for AccountImpl {
error!("Error in session {:?}", resp);
return Err(rpc_err("session error response TBD"));
}

match resp {
Ok(payload) => match payload.payload.extract().unwrap() {
ExtnResponse::None(()) => {
CapState::emit(
&self.platform_state,
CapEvent::OnAvailable,
FireboltCap::Short("token:platform".to_owned()),
None,
)
.await;
Ok(())
}
_ => {
CapState::emit(
&self.platform_state,
CapEvent::OnUnavailable,
FireboltCap::Short("token:platform".to_owned()),
None,
)
.await;
Err(rpc_err("Provision Status error response TBD"))
}
},
Err(_e) => Err(jsonrpsee::core::Error::Custom(String::from(
"Provision Status error response TBD",
))),
}
Ok(())
}

async fn id_rpc(&self, _ctx: CallContext) -> RpcResult<String> {
Expand Down
9 changes: 8 additions & 1 deletion core/main/src/processor/main_context_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ impl MainContextProcessor {
}
CapState::emit(
state,
event,
&event,
FireboltCap::Short("token:account".to_owned()),
None,
)
.await;
CapState::emit(
state,
&event,
FireboltCap::Short("token:platform".to_owned()),
None,
)
.await;
token_available
}

Expand Down
4 changes: 2 additions & 2 deletions core/main/src/service/apps/provider_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl ProviderBroker {

CapState::emit(
pst,
CapEvent::OnAvailable,
&CapEvent::OnAvailable,
FireboltCap::Full(capability),
None,
)
Expand Down Expand Up @@ -379,7 +379,7 @@ impl ProviderBroker {
.map(|x| FireboltCap::Full(x.clone()))
.collect();
for cap in caps {
CapState::emit(pst, CapEvent::OnUnavailable, cap, None).await
CapState::emit(pst, &CapEvent::OnUnavailable, cap, None).await
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/main/src/service/user_grants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ impl GrantPolicyEnforcer {
debug!("grant step execute Err. step={:?} e={:?}", step, e);
CapState::emit(
platform_state,
CapEvent::OnRevoked,
&CapEvent::OnRevoked,
permission.cap.clone(),
Some(permission.role),
)
Expand All @@ -1556,7 +1556,7 @@ impl GrantPolicyEnforcer {

CapState::emit(
platform_state,
CapEvent::OnGranted,
&CapEvent::OnGranted,
permission.cap.clone(),
Some(permission.role),
)
Expand Down
14 changes: 7 additions & 7 deletions core/main/src/state/cap/cap_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ impl CapState {

fn check_primed(
ps: &PlatformState,
event: CapEvent,
cap: FireboltCap,
_event: &CapEvent,
cap: &FireboltCap,
app_id: Option<String>,
) -> bool {
let r = ps.cap_state.primed_listeners.read().unwrap();
debug!("primed entries {:?}", r);
if r.iter().any(|x| {
if x.event == event && x.cap == cap {
if matches!(&x.event, _event) && &x.cap == cap {
if let Some(a) = &app_id {
x.app_id.eq(a)
} else {
Expand All @@ -134,11 +134,11 @@ impl CapState {

pub async fn emit(
ps: &PlatformState,
event: CapEvent,
event: &CapEvent,
cap: FireboltCap,
role: Option<CapabilityRole>,
) {
match &event {
match event {
CapEvent::OnAvailable => ps
.cap_state
.generic
Expand All @@ -150,7 +150,7 @@ impl CapState {
_ => {}
}
// check if given event and capability needs emitting
if Self::check_primed(ps, event.clone(), cap.clone(), None) {
if Self::check_primed(ps, event, &cap, None) {
debug!("preparing cap event emit {}", cap.as_str());
// if its a grant or revoke it could be done per app
// these require additional
Expand All @@ -174,7 +174,7 @@ impl CapState {
let cc = listener.call_ctx.clone();
// Step 2: Check if the given event is valid for the app
if is_app_check_necessary
&& !Self::check_primed(ps, event.clone(), cap.clone(), Some(cc.app_id.clone()))
&& !Self::check_primed(ps, event, &cap, Some(cc.app_id.clone()))
{
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions core/main/src/state/cap/generic_cap_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl GenericCapState {
let caps = vec![
FireboltCap::Short("input:keyboard".to_owned()),
FireboltCap::Short("token:account".to_owned()),
FireboltCap::Short("token:platform".to_owned()),
FireboltCap::Short("usergrant:acknowledgechallenge".to_owned()),
FireboltCap::Short("usergrant:pinchallenge".to_owned()),
];
Expand All @@ -72,6 +73,7 @@ impl GenericCapState {
not_available.insert(cap.as_str());
}
}
debug!("Caps that are not available: {:?}", not_available);
}

pub fn check_for_processor(&self, request: Vec<String>) -> HashMap<String, bool> {
Expand Down
2 changes: 1 addition & 1 deletion core/main/src/state/metrics_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct MetricsState {

impl MetricsState {
fn send_context_update_request(platform_state: &PlatformState) {
let mut extn_client = platform_state.get_client().get_extn_client();
let extn_client = platform_state.get_client().get_extn_client();
let metrics_context = platform_state.metrics.context.read().unwrap().clone();

if let Err(e) = extn_client
Expand Down
6 changes: 5 additions & 1 deletion core/sdk/src/api/firebolt/fb_openrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ impl FireboltOpenRpc {

let setter = self.get_setter_method_for_property(tokens[1]);
setter.filter(|method| {
if let Some(suffix) = method.name.to_lowercase().strip_prefix(tokens[0]) {
if let Some(suffix) = method
.name
.to_lowercase()
.strip_prefix(tokens[0].to_lowercase().as_str())
{
!suffix.is_empty() && suffix.starts_with('.')
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion core/sdk/src/api/observability/metrics_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn start_service_metrics_timer(extn_client: &ExtnClient, name: String) -> Op
}

pub async fn stop_and_send_service_metrics_timer(
mut client: ExtnClient,
client: ExtnClient,
timer: Option<Timer>,
status: String,
) {
Expand Down
10 changes: 5 additions & 5 deletions core/sdk/src/extn/client/extn_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ impl ExtnClient {
/// Critical method used by event processors to emit event back to the requestor
/// # Arguments
/// `msg` - [ExtnMessage] event object
pub fn event(&mut self, event: impl ExtnPayloadProvider) -> Result<(), RippleError> {
pub fn event(&self, event: impl ExtnPayloadProvider) -> Result<(), RippleError> {
let other_sender = self.get_extn_sender_with_contract(event.get_contract());
self.sender.send_event(event, other_sender)
}
Expand Down Expand Up @@ -549,7 +549,7 @@ impl ExtnClient {
/// # Arguments
/// `payload` - impl [ExtnPayloadProvider]
pub async fn standalone_request<T: ExtnPayloadProvider>(
&mut self,
&self,
payload: impl ExtnPayloadProvider,
timeout_in_msecs: u64,
) -> Result<T, RippleError> {
Expand Down Expand Up @@ -586,7 +586,7 @@ impl ExtnClient {
///
/// # Arguments
/// `payload` - impl [ExtnPayloadProvider]
pub fn request_transient(&mut self, payload: impl ExtnPayloadProvider) -> RippleResponse {
pub fn request_transient(&self, payload: impl ExtnPayloadProvider) -> RippleResponse {
let id = uuid::Uuid::new_v4().to_string();
let other_sender = self.get_extn_sender_with_contract(payload.get_contract());
self.sender.send_request(id, payload, other_sender, None)
Expand Down Expand Up @@ -1528,7 +1528,7 @@ pub mod tests {
Some(HashMap::new()),
);

let mut extn_client = ExtnClient::new(receiver.clone(), mock_sender.clone());
let extn_client = ExtnClient::new(receiver.clone(), mock_sender.clone());

// TODO - this is a dummy test, need to add a real test
if let Ok(ExtnResponse::Value(_v)) = extn_client
Expand All @@ -1550,7 +1550,7 @@ pub mod tests {
Some(HashMap::new()),
);

let mut extn_client = ExtnClient::new(receiver, mock_sender);
let extn_client = ExtnClient::new(receiver, mock_sender);
let (s, _receiver) = unbounded();
extn_client.clone().add_sender(
ExtnId::get_main_target("main".into()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl ThunderPoolStep {
}

pub async fn setup(
mut state: ThunderBootstrapStateWithConfig,
state: ThunderBootstrapStateWithConfig,
) -> Result<ThunderBootstrapStateWithClient, RippleError> {
let pool_size = state.pool_size;
let url = state.url.clone();
Expand Down
2 changes: 1 addition & 1 deletion examples/rpc_extn/src/rpc/legacy_jsonrpsee_extn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub trait Legacy {
#[async_trait]
impl LegacyServer for LegacyImpl {
async fn make(&self, ctx: CallContext) -> RpcResult<String> {
let mut client = self.client.clone();
let client = self.client.clone();
let mut new_ctx = ctx;
new_ctx.protocol = ApiProtocol::Extn;

Expand Down

0 comments on commit 1752167

Please sign in to comment.