Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ test_details = ["test", "--target", "aarch64-apple-darwin"]
target = "wasm32-wasip1"

[target.'cfg(all(target_arch = "wasm32"))']
runner = "viceroy run -C fastly.toml -- "
runner = "viceroy run -C ../../fastly.toml -- "
117 changes: 87 additions & 30 deletions Cargo.lock

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

35 changes: 6 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
[package]
name = "potsi"
version = "0.1.0"
authors = []
edition = "2021"
# Remove this line if you want to be able to publish this crate as open source on crates.io.
# Otherwise, `publish = false` prevents an accidental `cargo publish` from revealing private source.
publish = false
license = "Apache-2.0"

[profile.release]
debug = 1

[dependencies]
fastly = "0.11.2"
hmac = "0.12.1"
sha2 = "0.10.6"
hex = "0.4.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.91"
cookie = "0.18.1"
log = "0.4.20"
log-fastly = "0.10.0"
futures = "0.3"
tokio = { version = "1.0", features = ["sync", "macros", "io-util", "rt", "time"] }
url = "2.4.1"
config = "0.15.11"
handlebars = "6.3.2"
chrono = "0.4"
[workspace]
resolver = "2"
members = [
"crates/common",
"crates/fastly",
]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ git clone [email protected]:IABTechLab/trusted-server.git
:information_source: Note that you’ll have to edit the following files for your setup:

- fastly.toml (service ID, author, description)
- potsi.toml (KV store ID names)
- trusted-server.toml (KV store ID names)

### Build

Expand Down
29 changes: 29 additions & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "trusted-server-common"
version = "0.1.0"
authors = []
edition = "2021"
# Remove this line if you want to be able to publish this crate as open source on crates.io.
# Otherwise, `publish = false` prevents an accidental `cargo publish` from revealing private source.
publish = false
license = "Apache-2.0"

[profile.release]
debug = 1

[dependencies]
chrono = "0.4"
config = "0.15.11"
cookie = "0.18.1"
fastly = "0.11.2"
futures = "0.3"
handlebars = "6.3.2"
hex = "0.4.3"
hmac = "0.12.1"
log = "0.4.20"
log-fastly = "0.10.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.91"
sha2 = "0.10.6"
tokio = { version = "1.0", features = ["sync", "macros", "io-util", "rt", "time"] }
url = "2.4.1"
2 changes: 1 addition & 1 deletion src/constants.rs → crates/common/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub const SYNTHETIC_HEADER_FRESH: &str = "X-Synthetic-Fresh";
pub const SYNTHETIC_HEADER_POTSI: &str = "X-Synthetic-Potsi";
pub const SYNTHETIC_HEADER_TRUSTED_SERVER: &str = "X-Synthetic-Trusted-Server";
pub const SYNTHETIC_HEADER_PUB_USER_ID: &str = "X-Pub-User-ID";
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub mod constants;
pub mod cookies;
pub mod gdpr;
pub mod models;
pub mod prebid;
pub mod privacy;
pub mod settings;
pub mod synthetic;
pub mod templates;
pub mod why;
File renamed without changes.
24 changes: 12 additions & 12 deletions src/prebid.rs → crates/common/src/prebid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use fastly::http::{header, Method};
use fastly::{Error, Request, Response};
use serde_json::json;

use crate::constants::{SYNTHETIC_HEADER_FRESH, SYNTHETIC_HEADER_POTSI};
use crate::constants::{SYNTHETIC_HEADER_FRESH, SYNTHETIC_HEADER_TRUSTED_SERVER};
use crate::settings::Settings;
use crate::synthetic::generate_synthetic_id;

Expand All @@ -29,9 +29,9 @@ impl PrebidRequest {
/// # Returns
/// * `Result<Self, Error>` - New PrebidRequest or error
pub fn new(settings: &Settings, req: &Request) -> Result<Self, Error> {
// Get the POTSI ID from header (which we just set in handle_prebid_test)
// Get the Trusted Server ID from header (which we just set in handle_prebid_test)
let synthetic_id = req
.get_header(SYNTHETIC_HEADER_POTSI)
.get_header(SYNTHETIC_HEADER_TRUSTED_SERVER)
.and_then(|h| h.to_str().ok())
.map(|s| s.to_string())
.unwrap_or_else(|| generate_synthetic_id(settings, req));
Expand Down Expand Up @@ -97,17 +97,17 @@ impl PrebidRequest {
let mut req = Request::new(Method::POST, settings.prebid.server_url.to_owned());

// Get and store the POTSI ID value from the incoming request
let potsi_id = incoming_req
.get_header(SYNTHETIC_HEADER_POTSI)
let id: String = incoming_req
.get_header(SYNTHETIC_HEADER_TRUSTED_SERVER)
.and_then(|h| h.to_str().ok())
.map(|s| s.to_string())
.unwrap_or_else(|| self.synthetic_id.clone());

println!("Found POTSI ID from incoming request: {}", potsi_id);
println!("Found Truted Server ID from incoming request: {}", id);

// Construct the OpenRTB2 bid request
let prebid_body = json!({
"id": potsi_id,
"id": id,
"imp": [{
"id": "imp1",
"banner": {
Expand Down Expand Up @@ -150,10 +150,10 @@ impl PrebidRequest {
{
"source": &self.domain,
"uids": [{
"id": &potsi_id,
"id": &id,
"atype": 1,
"ext": {
"type": "potsi"
"type": "potsi" // TODO: remove reference to potsi
}
}]
}
Expand All @@ -170,11 +170,11 @@ impl PrebidRequest {
req.set_header("X-Forwarded-For", &self.client_ip);
req.set_header(header::ORIGIN, &self.origin);
req.set_header(SYNTHETIC_HEADER_FRESH, &self.synthetic_id);
req.set_header(SYNTHETIC_HEADER_POTSI, &potsi_id);
req.set_header(SYNTHETIC_HEADER_TRUSTED_SERVER, &id);

println!(
"Sending prebid request with Fresh ID: {} and POTSI ID: {}",
self.synthetic_id, potsi_id
"Sending prebid request with Fresh ID: {} and Trusted Server ID: {}",
self.synthetic_id, id
);

req.set_body_json(&prebid_body)?;
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/settings.rs → crates/common/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ pub struct Synthetic {

#[derive(Debug, Deserialize)]
#[allow(unused)]
pub(crate) struct Settings {
pub struct Settings {
pub ad_server: AdServer,
pub prebid: Prebid,
pub synthetic: Synthetic,
}

impl Settings {
pub(crate) fn new() -> Result<Self, ConfigError> {
let toml_bytes = include_bytes!("../potsi.toml");
pub fn new() -> Result<Self, ConfigError> {
let toml_bytes = include_bytes!("../../../trusted-server.toml");
let toml_str = str::from_utf8(toml_bytes).unwrap();

let s = Config::builder()
Expand Down
Loading