Skip to content

Commit 9448400

Browse files
committed
fix
1 parent ca2d94c commit 9448400

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

shell.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This file is intended to be used with `nix-shell`
44
# (https://nixos.org/nix/manual/#sec-nix-shell) to setup a fully-functional
55
# syncstorage-rs build environment by installing all required dependencies.
6-
with import <nixpkgs> {};
6+
with import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/dc402c1fc646b5aeb6e50bdd06e1509981ce2af0.tar.gz") {};
77
stdenv.mkDerivation {
88
name = "syncstorage-rs";
99
buildInputs = [
@@ -14,7 +14,9 @@ stdenv.mkDerivation {
1414
openssl
1515
cmake
1616
protobuf
17+
python313
1718
go
1819
];
1920
NIX_LDFLAGS = "-L${libmysqlclient}/lib/mysql";
21+
RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
2022
}

syncserver-settings/src/lib.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ static PREFIX: &str = "sync";
1818
pub struct Settings {
1919
pub port: u16,
2020
pub host: String,
21-
/// public facing URL of the server
21+
/// The private address of the server.
22+
pub server_address: ServerAddress,
2223
pub public_url: Option<String>,
24+
/// The public facing server address.
25+
pub public_address: Option<ServerAddress>,
2326
/// Keep-alive header value (seconds)
2427
pub actix_keep_alive: Option<u32>,
2528
/// The master secret, from which are derived
@@ -187,7 +190,13 @@ impl Default for Settings {
187190
Settings {
188191
port: 8000,
189192
host: "127.0.0.1".to_string(),
193+
server_address: ServerAddress::Parts {
194+
host: "127.0.0.1".to_string(),
195+
port: 8000,
196+
path: None,
197+
},
190198
public_url: None,
199+
public_address: None,
191200
actix_keep_alive: None,
192201
master_secret: Secrets::default(),
193202
statsd_host: Some("localhost".to_owned()),
@@ -229,6 +238,37 @@ impl Default for Settings {
229238
}
230239
}
231240

241+
/// Represents a server address.
242+
#[derive(Clone, Debug, Deserialize)]
243+
pub enum ServerAddress {
244+
/// The uri to the server.
245+
Url(String),
246+
/// The parts of the address.
247+
Parts {
248+
/// The host name of the server.
249+
host: String,
250+
/// The port of the server.
251+
port: u16,
252+
/// The path to the root of the service.
253+
path: Option<String>,
254+
},
255+
}
256+
257+
impl ServerAddress {
258+
pub fn get_path(&self) -> String {
259+
match self {
260+
ServerAddress::Parts {
261+
path: Some(ref path),
262+
..
263+
} => path.to_owned(),
264+
ServerAddress::Url(ref url) => {
265+
Url::parse(url).map(|url| url.path().to_owned()).unwrap()
266+
}
267+
_ => "".to_owned(),
268+
}
269+
}
270+
}
271+
232272
/// Secrets used during Hawk authentication.
233273
#[derive(Clone, Debug)]
234274
pub struct Secrets {

syncserver/src/server/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syncserver_common::{
1919
Taggable,
2020
};
2121
use syncserver_db_common::{GetPoolState, PoolState};
22-
use syncserver_settings::Settings;
22+
use syncserver_settings::{Settings, ServerAddress};
2323
use syncstorage_db::{DbError, DbPool, DbPoolImpl};
2424
use syncstorage_settings::{Deadman, ServerLimits};
2525
use tokio::{sync::RwLock, time};
@@ -108,7 +108,7 @@ pub struct Server;
108108

109109
#[macro_export]
110110
macro_rules! build_app {
111-
($reverse_proxy_state: expr, $syncstorage_state: expr, $tokenserver_state: expr, $secrets: expr, $limits: expr, $cors: expr, $metrics: expr) => {
111+
($server_address: expr, $public_address: expr, $syncstorage_state: expr, $tokenserver_state: expr, $secrets: expr, $limits: expr, $cors: expr, $metrics: expr) => {
112112
App::new()
113113
.configure(|cfg| {
114114
cfg.app_data(Data::new($syncstorage_state));
@@ -119,7 +119,7 @@ macro_rules! build_app {
119119
}
120120
})
121121
.app_data(Data::new($secrets))
122-
.app_data(Data::new($reverse_proxy_state))
122+
.app_data(Data::new($public_address))
123123
// Middleware is applied LIFO
124124
// These will wrap all outbound responses with matching status codes.
125125
.wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, ApiError::render_404))
@@ -184,7 +184,7 @@ macro_rules! build_app {
184184
)
185185
// Tokenserver
186186
.service(
187-
web::resource("/1.0/{application}/{version}")
187+
web::resource(format!("{}1.0/{}", $server_address.path(), "{application}/{version}"))
188188
.route(web::get().to(tokenserver::handlers::get_tokenserver_result)),
189189
)
190190
// Dockerflow
@@ -370,6 +370,7 @@ impl Server {
370370

371371
build_app!(
372372
ReverseProxyState::from_settings(&settings_copy),
373+
&settings_copy.public_address.clone(),
373374
syncstorage_state,
374375
tokenserver_state.clone(),
375376
Arc::clone(&secrets),

syncserver/src/server/test.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ macro_rules! init_app {
133133
let state = get_test_state(&$settings).await;
134134
let metrics = state.metrics.clone();
135135
test::init_service(build_app!(
136-
ReverseProxyState::from_settings(&$settings),
136+
&$settings.server_address,
137+
&$settings.public_address,
137138
state,
138139
None::<tokenserver::ServerState>,
139140
Arc::clone(&SECRETS),
@@ -275,7 +276,8 @@ where
275276
let state = get_test_state(&settings).await;
276277
let metrics = state.metrics.clone();
277278
let app = test::init_service(build_app!(
278-
ReverseProxyState::from_settings(&settings),
279+
&settings.server_address,
280+
&settings.public_address,
279281
state,
280282
None::<tokenserver::ServerState>,
281283
Arc::clone(&SECRETS),
@@ -320,7 +322,8 @@ async fn test_endpoint_with_body(
320322
let state = get_test_state(&settings).await;
321323
let metrics = state.metrics.clone();
322324
let app = test::init_service(build_app!(
323-
ReverseProxyState::from_settings(&settings),
325+
&settings.server_address,
326+
&settings.public_address,
324327
state,
325328
None::<tokenserver::ServerState>,
326329
Arc::clone(&SECRETS),

0 commit comments

Comments
 (0)