Skip to content

Commit 3e8fd81

Browse files
committed
Organized code in crates (part 1)
1 parent 838df29 commit 3e8fd81

File tree

16 files changed

+223
-190
lines changed

16 files changed

+223
-190
lines changed

Cargo.lock

Lines changed: 124 additions & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
1-
[package]
2-
name = "potsi"
3-
version = "0.1.0"
4-
authors = []
5-
edition = "2021"
6-
# Remove this line if you want to be able to publish this crate as open source on crates.io.
7-
# Otherwise, `publish = false` prevents an accidental `cargo publish` from revealing private source.
8-
publish = false
9-
license = "Apache-2.0"
10-
11-
[profile.release]
12-
debug = 1
13-
14-
[dependencies]
15-
fastly = "0.11.2"
16-
hmac = "0.12.1"
17-
sha2 = "0.10.6"
18-
hex = "0.4.3"
19-
serde = { version = "1.0", features = ["derive"] }
20-
serde_json = "1.0.91"
21-
cookie = "0.18.1"
22-
log = "0.4.20"
23-
log-fastly = "0.10.0"
24-
futures = "0.3"
25-
tokio = { version = "1.0", features = ["sync", "macros", "io-util", "rt", "time"] }
26-
url = "2.4.1"
27-
config = "0.15.11"
28-
handlebars = "6.3.2"
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"crates/common",
5+
"crates/fastly",
6+
]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ git clone [email protected]:IABTechLab/trusted-server.git
9191
:information_source: Note that you’ll have to edit the following files for your setup:
9292

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

9696
### Build
9797

crates/common/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "trusted-server-common"
3+
version = "0.1.0"
4+
authors = []
5+
edition = "2021"
6+
# Remove this line if you want to be able to publish this crate as open source on crates.io.
7+
# Otherwise, `publish = false` prevents an accidental `cargo publish` from revealing private source.
8+
publish = false
9+
license = "Apache-2.0"
10+
11+
[profile.release]
12+
debug = 1
13+
14+
[dependencies]
15+
config = "0.15.11"
16+
cookie = "0.18.1"
17+
fastly = "0.11.2"
18+
futures = "0.3"
19+
handlebars = "6.3.2"
20+
hex = "0.4.3"
21+
hmac = "0.12.1"
22+
log = "0.4.20"
23+
log-fastly = "0.10.0"
24+
serde = { version = "1.0", features = ["derive"] }
25+
serde_json = "1.0.91"
26+
sha2 = "0.10.6"
27+
tokio = { version = "1.0", features = ["sync", "macros", "io-util", "rt", "time"] }
28+
url = "2.4.1"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub const SYNTHETIC_HEADER_FRESH: &str = "X-Synthetic-Fresh";
2-
pub const SYNTHETIC_HEADER_POTSI: &str = "X-Synthetic-Potsi";
2+
pub const SYNTHETIC_HEADER_TRUSTED_SERVER: &str = "X-Synthetic-Trusted-Server";
33
pub const SYNTHETIC_HEADER_PUB_USER_ID: &str = "X-Pub-User-ID";

crates/common/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub mod constants;
2+
pub mod cookies;
3+
pub mod models;
4+
pub mod prebid;
5+
pub mod settings;
6+
pub mod synthetic;
7+
pub mod templates;

src/prebid.rs renamed to crates/common/src/prebid.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use fastly::http::{header, Method};
22
use fastly::{Error, Request, Response};
33
use serde_json::json;
44

5-
use crate::constants::{SYNTHETIC_HEADER_FRESH, SYNTHETIC_HEADER_POTSI};
5+
use crate::constants::{SYNTHETIC_HEADER_FRESH, SYNTHETIC_HEADER_TRUSTED_SERVER};
66
use crate::settings::Settings;
77
use crate::synthetic::generate_synthetic_id;
88

@@ -31,7 +31,7 @@ impl PrebidRequest {
3131
pub fn new(settings: &Settings, req: &Request) -> Result<Self, Error> {
3232
// Get the POTSI ID from header (which we just set in handle_prebid_test)
3333
let synthetic_id = req
34-
.get_header(SYNTHETIC_HEADER_POTSI)
34+
.get_header(SYNTHETIC_HEADER_TRUSTED_SERVER)
3535
.and_then(|h| h.to_str().ok())
3636
.map(|s| s.to_string())
3737
.unwrap_or_else(|| generate_synthetic_id(settings, req));
@@ -98,12 +98,12 @@ impl PrebidRequest {
9898

9999
// Get and store the POTSI ID value from the incoming request
100100
let potsi_id = incoming_req
101-
.get_header(SYNTHETIC_HEADER_POTSI)
101+
.get_header(SYNTHETIC_HEADER_TRUSTED_SERVER)
102102
.and_then(|h| h.to_str().ok())
103103
.map(|s| s.to_string())
104104
.unwrap_or_else(|| self.synthetic_id.clone());
105105

106-
println!("Found POTSI ID from incoming request: {}", potsi_id);
106+
println!("Found Truted Server ID from incoming request: {}", potsi_id);
107107

108108
// Construct the OpenRTB2 bid request
109109
let prebid_body = json!({
@@ -170,7 +170,7 @@ impl PrebidRequest {
170170
req.set_header("X-Forwarded-For", &self.client_ip);
171171
req.set_header(header::ORIGIN, &self.origin);
172172
req.set_header(SYNTHETIC_HEADER_FRESH, &self.synthetic_id);
173-
req.set_header(SYNTHETIC_HEADER_POTSI, &potsi_id);
173+
req.set_header(SYNTHETIC_HEADER_TRUSTED_SERVER, &potsi_id);
174174

175175
println!(
176176
"Sending prebid request with Fresh ID: {} and POTSI ID: {}",
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ pub struct Synthetic {
2626

2727
#[derive(Debug, Deserialize)]
2828
#[allow(unused)]
29-
pub(crate) struct Settings {
29+
pub struct Settings {
3030
pub ad_server: AdServer,
3131
pub prebid: Prebid,
3232
pub synthetic: Synthetic,
3333
}
3434

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

4040
let s = Config::builder()

0 commit comments

Comments
 (0)