Skip to content
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

fix: Fixes incorrect parsing of extra arguments. #156

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tokio = {version = "1.27.0", features = ["macros", "rt-multi-thread", "tracing",
tracing = {version = "0.1.37", features = ["log"]}
tracing-subscriber = {version = "0.3.16", features = ["json", "env-filter"]}
ulid = "1.0.0"
unleash-types = {version = "0.9.1", features = ["openapi", "hashes"]}
unleash-types = {version = "0.9.4", features = ["openapi", "hashes"]}
unleash-yggdrasil = "0.5.3"
utoipa = {version = "3", features = ["actix_extras", "chrono"]}
utoipa-swagger-ui = {version = "3", features = ["actix-web"]}
Expand Down
38 changes: 19 additions & 19 deletions server/src/frontend_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
error::{EdgeError, FrontendHydrationMissing},
metrics::client_metrics::MetricsCache,
tokens::{self, cache_key},
types::{EdgeJsonResult, EdgeResult, EdgeToken, ProjectFilter},
types::{EdgeJsonResult, EdgeResult, EdgeToken},
};

///
Expand Down Expand Up @@ -101,18 +101,18 @@ security(
#[post("/frontend/all")]
async fn post_frontend_all_features(
edge_token: EdgeToken,
engine_cache: web::Data<DashMap<String, EngineState>>,
token_cache: web::Data<DashMap<String, EdgeToken>>,
context: web::Json<Context>,
engine_cache: Data<DashMap<String, EngineState>>,
token_cache: Data<DashMap<String, EdgeToken>>,
context: Json<Context>,
) -> EdgeJsonResult<FrontendResult> {
post_all_features(edge_token, engine_cache, token_cache, context)
}

fn post_all_features(
edge_token: EdgeToken,
engine_cache: web::Data<DashMap<String, EngineState>>,
token_cache: web::Data<DashMap<String, EdgeToken>>,
context: web::Json<Context>,
engine_cache: Data<DashMap<String, EngineState>>,
token_cache: Data<DashMap<String, EdgeToken>>,
context: Json<Context>,
) -> EdgeJsonResult<FrontendResult> {
let context = context.into_inner();
let token = token_cache
Expand Down Expand Up @@ -211,7 +211,7 @@ async fn post_proxy_enabled_features(
edge_token: EdgeToken,
engine_cache: Data<DashMap<String, EngineState>>,
token_cache: Data<DashMap<String, EdgeToken>>,
context: Query<Context>,
context: Json<Context>,
) -> EdgeJsonResult<FrontendResult> {
post_enabled_features(edge_token, engine_cache, token_cache, context).await
}
Expand All @@ -233,7 +233,7 @@ async fn post_frontend_enabled_features(
edge_token: EdgeToken,
engine_cache: Data<DashMap<String, EngineState>>,
token_cache: Data<DashMap<String, EdgeToken>>,
context: Query<Context>,
context: Json<Context>,
) -> EdgeJsonResult<FrontendResult> {
post_enabled_features(edge_token, engine_cache, token_cache, context).await
}
Expand Down Expand Up @@ -333,7 +333,6 @@ pub fn evaluate_feature(
})
.map(|r| EvaluatedToggle {
name: feature_name.clone(),
project: r.project,
enabled: r.enabled,
variant: EvaluatedVariant {
name: r.variant.name,
Expand All @@ -349,7 +348,7 @@ async fn post_enabled_features(
edge_token: EdgeToken,
engine_cache: Data<DashMap<String, EngineState>>,
token_cache: Data<DashMap<String, EdgeToken>>,
context: Query<Context>,
context: Json<Context>,
) -> EdgeJsonResult<FrontendResult> {
let context = context.into_inner();
let token = token_cache
Expand Down Expand Up @@ -500,27 +499,30 @@ pub fn frontend_from_yggdrasil(
let toggles: Vec<EvaluatedToggle> = res
.iter()
.filter(|(_, resolved)| include_all || resolved.enabled)
.filter(|(_, resolved)| {
edge_token.projects.is_empty()
|| edge_token.projects.contains(&"*".to_string())
|| edge_token.projects.contains(&resolved.project)
})
.map(|(name, resolved)| EvaluatedToggle {
name: name.into(),
enabled: resolved.enabled,
project: resolved.project.clone(),
variant: EvaluatedVariant {
name: resolved.variant.name.clone(),
enabled: resolved.variant.enabled,
payload: resolved.variant.payload.clone(),
},
impression_data: resolved.impression_data,
})
.collect::<Vec<EvaluatedToggle>>()
.filter_by_projects(edge_token);
.collect::<Vec<EvaluatedToggle>>();
FrontendResult { toggles }
}

pub fn get_all_features(
edge_token: EdgeToken,
engine_cache: web::Data<DashMap<String, EngineState>>,
token_cache: web::Data<DashMap<String, EdgeToken>>,
context: web::Query<Context>,
engine_cache: Data<DashMap<String, EngineState>>,
token_cache: Data<DashMap<String, EdgeToken>>,
context: Query<Context>,
) -> EdgeJsonResult<FrontendResult> {
let context = context.into_inner();
let token = token_cache
Expand Down Expand Up @@ -727,7 +729,6 @@ mod tests {
payload: None,
},
impression_data: false,
project: "default".into(),
}],
};

Expand Down Expand Up @@ -865,7 +866,6 @@ mod tests {

let result: FrontendResult = test::call_and_read_body_json(&app, req).await;
assert_eq!(result.toggles.len(), 16);
assert!(result.toggles.iter().all(|toggle| toggle.project == "dx"));
}

#[tokio::test]
Expand Down
7 changes: 3 additions & 4 deletions server/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use shadow_rs::shadow;
use unleash_types::client_features::{ClientFeature, ClientFeatures};
use unleash_types::client_metrics::{ClientApplication, ClientMetricsEnv};
use unleash_types::frontend::EvaluatedToggle;
use unleash_yggdrasil::EngineState;
use unleash_yggdrasil::{EngineState, ResolvedToggle};
use utoipa::{IntoParams, ToSchema};

pub type EdgeJsonResult<T> = Result<Json<T>, EdgeError>;
Expand Down Expand Up @@ -197,8 +196,8 @@ impl ProjectFilter<ClientFeature> for Vec<ClientFeature> {
}
}

impl ProjectFilter<EvaluatedToggle> for Vec<EvaluatedToggle> {
fn filter_by_projects(&self, token: &EdgeToken) -> Vec<EvaluatedToggle> {
impl ProjectFilter<ResolvedToggle> for Vec<ResolvedToggle> {
fn filter_by_projects(&self, token: &EdgeToken) -> Vec<ResolvedToggle> {
self.iter()
.filter(|toggle| {
token.projects.is_empty()
Expand Down