Skip to content

Commit ab36d7a

Browse files
committed
feat: feature gate jexl
1 parent 06a5d15 commit ab36d7a

File tree

4 files changed

+54
-21
lines changed

4 files changed

+54
-21
lines changed

components/remote_settings/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ description = "A Remote Settings client intended for application layer platforms
88
license = "MPL-2.0"
99
exclude = ["/android", "/ios"]
1010

11+
[features]
12+
default = []
13+
jexl = ["dep:jexl-eval"]
14+
1115
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1216

1317
[dependencies]
@@ -22,7 +26,7 @@ viaduct = { path = "../viaduct" }
2226
url = "2.1" # mozilla-central can't yet take 2.2 (see bug 1734538)
2327
camino = "1.0"
2428
rusqlite = { workspace = true, features = ["bundled"] }
25-
jexl-eval = "0.3.0"
29+
jexl-eval = { version = "0.3.0", optional = true }
2630
regex = "1.9"
2731
anyhow = "1.0"
2832
firefox-versioning = { path = "../support/firefox-versioning" }

components/remote_settings/src/client.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
use crate::config::RemoteSettingsConfig;
66
use crate::error::{Error, Result};
7+
#[cfg(feature = "jexl")]
78
use crate::jexl_filter::JexlFilter;
89
use crate::storage::Storage;
9-
use crate::{RemoteSettingsContext, RemoteSettingsServer, UniffiCustomTypeConverter};
10+
#[cfg(feature = "jexl")]
11+
use crate::RemoteSettingsContext;
12+
use crate::{RemoteSettingsServer, UniffiCustomTypeConverter};
1013
use parking_lot::Mutex;
1114
use serde::{Deserialize, Serialize};
1215
use std::{
@@ -27,6 +30,7 @@ const HEADER_RETRY_AFTER: &str = "Retry-After";
2730
pub struct RemoteSettingsClient<C = ViaductApiClient> {
2831
// This is immutable, so it can be outside the mutex
2932
collection_name: String,
33+
#[cfg(feature = "jexl")]
3034
jexl_filter: JexlFilter,
3135
inner: Mutex<RemoteSettingsClientInner<C>>,
3236
}
@@ -40,11 +44,12 @@ impl<C: ApiClient> RemoteSettingsClient<C> {
4044
pub fn new_from_parts(
4145
collection_name: String,
4246
storage: Storage,
43-
jexl_filter: JexlFilter,
47+
#[cfg(feature = "jexl")] jexl_filter: JexlFilter,
4448
api_client: C,
4549
) -> Self {
4650
Self {
4751
collection_name,
52+
#[cfg(feature = "jexl")]
4853
jexl_filter,
4954
inner: Mutex::new(RemoteSettingsClientInner {
5055
storage,
@@ -57,6 +62,7 @@ impl<C: ApiClient> RemoteSettingsClient<C> {
5762
}
5863

5964
/// Filters records based on the presence and evaluation of `filter_expression`.
65+
#[cfg(feature = "jexl")]
6066
fn filter_records(&self, records: Vec<RemoteSettingsRecord>) -> Vec<RemoteSettingsRecord> {
6167
records
6268
.into_iter()
@@ -69,6 +75,11 @@ impl<C: ApiClient> RemoteSettingsClient<C> {
6975
.collect()
7076
}
7177

78+
#[cfg(not(feature = "jexl"))]
79+
fn filter_records(&self, records: Vec<RemoteSettingsRecord>) -> Vec<RemoteSettingsRecord> {
80+
records
81+
}
82+
7283
/// Get the current set of records.
7384
///
7485
/// If records are not present in storage this will normally return None. Use `sync_if_empty =
@@ -125,15 +136,17 @@ impl RemoteSettingsClient<ViaductApiClient> {
125136
server_url: Url,
126137
bucket_name: String,
127138
collection_name: String,
128-
context: Option<RemoteSettingsContext>,
139+
#[cfg(feature = "jexl")] context: Option<RemoteSettingsContext>,
129140
storage: Storage,
130141
) -> Result<Self> {
131142
let api_client = ViaductApiClient::new(server_url, &bucket_name, &collection_name)?;
143+
#[cfg(feature = "jexl")]
132144
let jexl_filter = JexlFilter::new(context);
133145

134146
Ok(Self::new_from_parts(
135147
collection_name,
136148
storage,
149+
#[cfg(feature = "jexl")]
137150
jexl_filter,
138151
api_client,
139152
))
@@ -1510,6 +1523,7 @@ mod test {
15101523
mod test_new_client {
15111524
use super::*;
15121525

1526+
#[cfg(not(feature = "jexl"))]
15131527
use serde_json::json;
15141528

15151529
#[test]
@@ -1536,6 +1550,7 @@ mod test_new_client {
15361550
}
15371551

15381552
#[test]
1553+
#[cfg(not(feature = "jexl"))]
15391554
fn test_get_records_none_cached() {
15401555
let mut api_client = MockApiClient::new();
15411556
api_client.expect_collection_url().returning(|| {
@@ -1544,19 +1559,16 @@ mod test_new_client {
15441559
// Note, don't make any api_client.expect_*() calls, the RemoteSettingsClient should not
15451560
// attempt to make any requests for this scenario
15461561
let storage = Storage::new(":memory:".into()).expect("Error creating storage");
1547-
let rs_client = RemoteSettingsClient::new_from_parts(
1548-
"test-collection".into(),
1549-
storage,
1550-
JexlFilter::new(None),
1551-
api_client,
1552-
);
1562+
let rs_client =
1563+
RemoteSettingsClient::new_from_parts("test-collection".into(), storage, api_client);
15531564
assert_eq!(
15541565
rs_client.get_records(false).expect("Error getting records"),
15551566
None
15561567
);
15571568
}
15581569

15591570
#[test]
1571+
#[cfg(not(feature = "jexl"))]
15601572
fn test_get_records_none_cached_sync_with_empty() {
15611573
let mut api_client = MockApiClient::new();
15621574
let records = vec![RemoteSettingsRecord {
@@ -1577,23 +1589,19 @@ mod test_new_client {
15771589
}
15781590
});
15791591
let storage = Storage::new(":memory:".into()).expect("Error creating storage");
1580-
let rs_client = RemoteSettingsClient::new_from_parts(
1581-
"test-collection".into(),
1582-
storage,
1583-
JexlFilter::new(None),
1584-
api_client,
1585-
);
1592+
let rs_client =
1593+
RemoteSettingsClient::new_from_parts("test-collection".into(), storage, api_client);
15861594
assert_eq!(
15871595
rs_client.get_records(true).expect("Error getting records"),
15881596
Some(records)
15891597
);
15901598
}
15911599
}
15921600

1601+
#[cfg(feature = "jexl")]
15931602
#[cfg(test)]
1594-
mod test_filtering_records {
1603+
mod jexl_tests {
15951604
use super::*;
1596-
use serde_json::json;
15971605

15981606
#[test]
15991607
fn test_get_records_filtered_app_version_pass() {
@@ -1603,7 +1611,7 @@ mod test_filtering_records {
16031611
last_modified: 100,
16041612
deleted: false,
16051613
attachment: None,
1606-
fields: json!({
1614+
fields: serde_json::json!({
16071615
"filter_expression": "env.version|versionCompare(\"128.0a1\") > 0"
16081616
})
16091617
.as_object()
@@ -1652,7 +1660,7 @@ mod test_filtering_records {
16521660
last_modified: 100,
16531661
deleted: false,
16541662
attachment: None,
1655-
fields: json!({
1663+
fields: serde_json::json!({
16561664
"filter_expression": "env.version|versionCompare(\"128.0a1\") > 0"
16571665
})
16581666
.as_object()

components/remote_settings/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub mod error;
1616
pub mod service;
1717
pub mod storage;
1818

19+
#[cfg(feature = "jexl")]
1920
pub(crate) mod jexl_filter;
2021

2122
pub use client::{Attachment, RemoteSettingsRecord, RemoteSettingsResponse, RsJsonObject};
@@ -209,14 +210,15 @@ impl RemoteSettingsClient {
209210
base_url: Url,
210211
bucket_name: String,
211212
collection_name: String,
212-
context: Option<RemoteSettingsContext>,
213+
#[cfg(feature = "jexl")] context: Option<RemoteSettingsContext>,
213214
storage: Storage,
214215
) -> Result<Self> {
215216
Ok(Self {
216217
internal: client::RemoteSettingsClient::new(
217218
base_url,
218219
bucket_name,
219220
collection_name,
221+
#[cfg(feature = "jexl")]
220222
context,
221223
storage,
222224
)?,

components/remote_settings/src/service.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl RemoteSettingsService {
5656
}
5757

5858
/// Create a new Remote Settings client
59+
#[cfg(feature = "jexl")]
5960
pub fn make_client(
6061
&self,
6162
collection_name: String,
@@ -74,6 +75,24 @@ impl RemoteSettingsService {
7475
Ok(client)
7576
}
7677

78+
#[cfg(not(feature = "jexl"))]
79+
pub fn make_client(
80+
&self,
81+
collection_name: String,
82+
#[allow(unused_variables)] context: Option<RemoteSettingsContext>,
83+
) -> Result<Arc<RemoteSettingsClient>> {
84+
let mut inner = self.inner.lock();
85+
let storage = Storage::new(inner.storage_dir.join(format!("{collection_name}.sql")))?;
86+
let client = Arc::new(RemoteSettingsClient::new(
87+
inner.base_url.clone(),
88+
inner.bucket_name.clone(),
89+
collection_name.clone(),
90+
storage,
91+
)?);
92+
inner.clients.push(Arc::downgrade(&client));
93+
Ok(client)
94+
}
95+
7796
/// Sync collections for all active clients
7897
pub fn sync(&self) -> Result<Vec<String>> {
7998
// Make sure we only sync each collection once, even if there are multiple clients

0 commit comments

Comments
 (0)