Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:

- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install Viceroy
run: cargo install viceroy
run: cargo install viceroy --locked

- name: Install WASI SDK
uses: konsumer/install-wasi-sdk@v1
Expand Down
8 changes: 8 additions & 0 deletions examples/config_store.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! @example config_store.cpp
#include "fastly/sdk.h"

int main() {
fastly::log::init_simple("logs");
auto store = fastly::ConfigStore::open("example-store");
fastly::Response::from_body(store->get("hello")->value()).send_to_client();
}
6 changes: 6 additions & 0 deletions examples/fastly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ service_id = ""
fastly.url = "https://www.fastly.com"
wikipedia.url = "https://en.wikipedia.org"
esi-cpp-demo.url = "https://esi-cpp-demo.edgecompute.app"

[local_server.config_stores.example-store]
format = "inline-toml"

[local_server.config_stores.example-store.contents]
hello = "world"
4 changes: 4 additions & 0 deletions src/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ impl ConfigStore {
self.0.contains(try_fe!(err, key.to_str()))
}
}

pub fn f_config_store_config_store_force_symbols(x: Box<ConfigStore>) -> Box<ConfigStore> {
x
}
7 changes: 7 additions & 0 deletions src/geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,10 @@ impl UtcOffset {
self.0.is_negative()
}
}

pub fn f_geo_utc_offset_force_symbols(x: Box<UtcOffset>) -> Box<UtcOffset> {
x
}
pub fn f_geo_geo_force_symbols(x: Box<Geo>) -> Box<Geo> {
x
}
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ mod ffi {
mut err: Pin<&mut *mut FastlyError>,
) -> bool;
fn contains(&self, key: &CxxString, mut err: Pin<&mut *mut FastlyError>) -> bool;
fn f_config_store_config_store_force_symbols(x: Box<ConfigStore>) -> Box<ConfigStore>;
}

#[namespace = "fastly::sys::secret_store"]
Expand All @@ -723,6 +724,7 @@ mod ffi {
out: Pin<&mut *mut Secret>,
err: Pin<&mut *mut FastlyError>,
);
fn f_secret_store_secret_force_symbols(x: Box<Secret>) -> Box<Secret>;
}

#[namespace = "fastly::sys::secret_store"]
Expand All @@ -740,6 +742,7 @@ mod ffi {
mut err: Pin<&mut *mut FastlyError>,
);
fn contains(&self, key: &CxxString, mut err: Pin<&mut *mut FastlyError>) -> bool;
fn f_secret_store_secret_store_force_symbols(x: Box<SecretStore>) -> Box<SecretStore>;
}

#[namespace = "fastly::sys::geo"]
Expand All @@ -753,6 +756,7 @@ mod ffi {
fn is_utc(&self) -> bool;
fn is_positive(&self) -> bool;
fn is_negative(&self) -> bool;
fn f_geo_utc_offset_force_symbols(x: Box<UtcOffset>) -> Box<UtcOffset>;
}

#[namespace = "fastly::sys::geo"]
Expand Down Expand Up @@ -781,6 +785,7 @@ mod ffi {
fn proxy_type(&self) -> ProxyType;
fn region(&self, out: Pin<&mut CxxString>) -> bool;
fn utc_offset(&self) -> *mut UtcOffset;
fn f_geo_geo_force_symbols(x: Box<Geo>) -> Box<Geo>;
}

#[namespace = "fastly::sys::log"]
Expand Down
7 changes: 7 additions & 0 deletions src/secret_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ impl SecretStore {
try_fe!(err, self.0.contains(try_fe!(err, key.to_str())))
}
}

pub fn f_secret_store_secret_force_symbols(x: Box<Secret>) -> Box<Secret> {
x
}
pub fn f_secret_store_secret_store_force_symbols(x: Box<SecretStore>) -> Box<SecretStore> {
x
}
36 changes: 36 additions & 0 deletions test/config_store.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <catch2/catch_test_macros.hpp>
#include <fastly/config_store.h>
#include <fastly/http/body.h>

using namespace fastly::http;
using namespace fastly::config_store;

TEST_CASE("ConfigStore::open returns error for unknown store",
"[config_store]") {
auto result = ConfigStore::open("nonexistent_store");
REQUIRE(result.error().error_code() ==
fastly::FastlyErrorCode::ConfigStoreOpenError);
}

TEST_CASE("Opening and reading from ConfigStore", "[config_store]") {
auto store = ConfigStore::open("test-store");
REQUIRE(store.has_value());

SECTION("ConfigStore::contains") {
REQUIRE(store->contains("hello").value());
REQUIRE(!store->contains("does_not_exist").value());
}

SECTION("ConfigStore::get") {
auto get_result = store->get("hello").value();
REQUIRE(get_result.has_value());
REQUIRE(get_result.value() == "world");

auto no_result = store->get("does_not_exist").value();
REQUIRE(!no_result.has_value());
}
}

// Required due to https://github.com/WebAssembly/wasi-libc/issues/485
#include <catch2/catch_session.hpp>
int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); }
3 changes: 3 additions & 0 deletions test/config_store.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "world"
}
3 changes: 3 additions & 0 deletions test/fastly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ backends.esi-cpp-demo.url = "https://esi-cpp-demo.edgecompute.app"

[local_server.kv_stores]
test-store = { file = 'kv_store.json', format = 'json' }

[local_server.config_stores]
test-store = { file = 'config_store.json', format = 'json' }