Skip to content

Commit 9d64e9b

Browse files
committed
feat: [#220] make HTTP API bind address configurable in tracker template
- Add bind_address field to HttpApiConfig domain type - Update TrackerContext template wrapper with http_api_bind_address - Convert hardcoded bind_address in tracker.toml.tera to template variable - Update all JSON test configurations with bind_address field - Fix all doctests to include bind_address in HttpApiConfig examples - Set default bind_address to 0.0.0.0:1212 (matching previous hardcoded value) This change allows users to configure the HTTP API bind address through environment.json, following the same pattern as UDP and HTTP tracker bind addresses.
1 parent 893ac72 commit 9d64e9b

File tree

13 files changed

+38
-667
lines changed

13 files changed

+38
-667
lines changed

docs/e2e-testing.md

Lines changed: 0 additions & 666 deletions
This file was deleted.

src/application/command_handlers/create/config/environment_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use super::ssh_credentials_config::SshCredentialsConfig;
6262
/// }
6363
/// ],
6464
/// "http_api": {
65+
/// "bind_address": "0.0.0.0:1212",
6566
/// "admin_token": "MyAccessToken"
6667
/// }
6768
/// }
@@ -347,6 +348,7 @@ impl EnvironmentCreationConfig {
347348
bind_address: "0.0.0.0:7070".to_string(),
348349
}],
349350
http_api: HttpApiConfig {
351+
bind_address: "0.0.0.0:1212".to_string(),
350352
admin_token: "MyAccessToken".to_string(),
351353
},
352354
},
@@ -497,6 +499,7 @@ mod tests {
497499
}
498500
],
499501
"http_api": {
502+
"bind_address": "0.0.0.0:1212",
500503
"admin_token": "MyAccessToken"
501504
}
502505
}
@@ -557,6 +560,7 @@ mod tests {
557560
}
558561
],
559562
"http_api": {
563+
"bind_address": "0.0.0.0:1212",
560564
"admin_token": "MyAccessToken"
561565
}
562566
}

src/application/command_handlers/create/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
//! }
9090
//! ],
9191
//! "http_api": {
92+
//! "bind_address": "0.0.0.0:1212",
9293
//! "admin_token": "MyAccessToken"
9394
//! }
9495
//! }

src/domain/tracker/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use super::DatabaseConfig;
3434
/// HttpTrackerConfig { bind_address: "0.0.0.0:7070".to_string() },
3535
/// ],
3636
/// http_api: HttpApiConfig {
37+
/// bind_address: "0.0.0.0:1212".to_string(),
3738
/// admin_token: "MyAccessToken".to_string(),
3839
/// },
3940
/// };
@@ -80,6 +81,9 @@ pub struct HttpTrackerConfig {
8081
/// HTTP API configuration
8182
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
8283
pub struct HttpApiConfig {
84+
/// Bind address (e.g., "0.0.0.0:1212")
85+
pub bind_address: String,
86+
8387
/// Admin access token for HTTP API authentication
8488
pub admin_token: String,
8589
}
@@ -93,6 +97,7 @@ impl Default for TrackerConfig {
9397
/// - Mode: Public tracker (private = false)
9498
/// - UDP trackers: One instance on port 6969
9599
/// - HTTP trackers: One instance on port 7070
100+
/// - HTTP API: Bind address 0.0.0.0:1212
96101
/// - Admin token: `MyAccessToken`
97102
fn default() -> Self {
98103
Self {
@@ -109,6 +114,7 @@ impl Default for TrackerConfig {
109114
bind_address: "0.0.0.0:7070".to_string(),
110115
}],
111116
http_api: HttpApiConfig {
117+
bind_address: "0.0.0.0:1212".to_string(),
112118
admin_token: "MyAccessToken".to_string(),
113119
},
114120
}
@@ -135,6 +141,7 @@ mod tests {
135141
bind_address: "0.0.0.0:7070".to_string(),
136142
}],
137143
http_api: HttpApiConfig {
144+
bind_address: "0.0.0.0:1212".to_string(),
138145
admin_token: "test_token".to_string(),
139146
},
140147
};
@@ -157,6 +164,7 @@ mod tests {
157164
udp_trackers: vec![],
158165
http_trackers: vec![],
159166
http_api: HttpApiConfig {
167+
bind_address: "0.0.0.0:1212".to_string(),
160168
admin_token: "token123".to_string(),
161169
},
162170
};
@@ -186,6 +194,7 @@ mod tests {
186194
assert_eq!(config.http_trackers[0].bind_address, "0.0.0.0:7070");
187195

188196
// Verify HTTP API configuration
197+
assert_eq!(config.http_api.bind_address, "0.0.0.0:1212");
189198
assert_eq!(config.http_api.admin_token, "MyAccessToken");
190199
}
191200
}

src/domain/tracker/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
//! HttpTrackerConfig { bind_address: "0.0.0.0:7070".to_string() },
3737
//! ],
3838
//! http_api: HttpApiConfig {
39+
//! bind_address: "0.0.0.0:1212".to_string(),
3940
//! admin_token: "MyToken".to_string(),
4041
//! },
4142
//! };

src/infrastructure/templating/ansible/template/wrappers/variables/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ mod tests {
197197
bind_address: "0.0.0.0:7070".to_string(),
198198
}],
199199
http_api: HttpApiConfig {
200+
bind_address: "0.0.0.0:1212".to_string(),
200201
admin_token: "MyAccessToken".to_string(),
201202
},
202203
};
@@ -222,6 +223,7 @@ mod tests {
222223
udp_trackers: vec![],
223224
http_trackers: vec![],
224225
http_api: HttpApiConfig {
226+
bind_address: "0.0.0.0:1212".to_string(),
225227
admin_token: "Token123".to_string(),
226228
},
227229
};
@@ -258,6 +260,7 @@ mod tests {
258260
bind_address: "no_port_here".to_string(), // Invalid format
259261
}],
260262
http_api: HttpApiConfig {
263+
bind_address: "0.0.0.0:1212".to_string(),
261264
admin_token: "Token".to_string(),
262265
},
263266
};

src/infrastructure/templating/tracker/template/wrapper/tracker_config/context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use serde::Serialize;
3939
/// HttpTrackerConfig { bind_address: "0.0.0.0:7070".to_string() },
4040
/// ],
4141
/// http_api: HttpApiConfig {
42+
/// bind_address: "0.0.0.0:1212".to_string(),
4243
/// admin_token: "MyToken".to_string(),
4344
/// },
4445
/// };
@@ -57,6 +58,9 @@ pub struct TrackerContext {
5758

5859
/// HTTP tracker bind addresses
5960
pub http_trackers: Vec<HttpTrackerEntry>,
61+
62+
/// HTTP API bind address
63+
pub http_api_bind_address: String,
6064
}
6165

6266
/// UDP tracker entry for template rendering
@@ -96,6 +100,7 @@ impl TrackerContext {
96100
bind_address: t.bind_address.clone(),
97101
})
98102
.collect(),
103+
http_api_bind_address: config.http_api.bind_address.clone(),
99104
}
100105
}
101106

@@ -119,6 +124,7 @@ impl TrackerContext {
119124
http_trackers: vec![HttpTrackerEntry {
120125
bind_address: "0.0.0.0:7070".to_string(),
121126
}],
127+
http_api_bind_address: "0.0.0.0:1212".to_string(),
122128
}
123129
}
124130
}
@@ -157,6 +163,7 @@ mod tests {
157163
bind_address: "0.0.0.0:7070".to_string(),
158164
}],
159165
http_api: HttpApiConfig {
166+
bind_address: "0.0.0.0:1212".to_string(),
160167
admin_token: "test_admin_token".to_string(),
161168
},
162169
}

src/presentation/controllers/create/subcommands/environment/config_loader.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ mod tests {
148148
}}
149149
],
150150
"http_api": {{
151+
"bind_address": "0.0.0.0:1212",
151152
"admin_token": "MyAccessToken"
152153
}}
153154
}}
@@ -259,6 +260,7 @@ mod tests {
259260
}}
260261
],
261262
"http_api": {{
263+
"bind_address": "0.0.0.0:1212",
262264
"admin_token": "MyAccessToken"
263265
}}
264266
}}
@@ -315,6 +317,7 @@ mod tests {
315317
}
316318
],
317319
"http_api": {
320+
"bind_address": "0.0.0.0:1212",
318321
"admin_token": "MyAccessToken"
319322
}
320323
}
@@ -376,6 +379,7 @@ mod tests {
376379
}}
377380
],
378381
"http_api": {{
382+
"bind_address": "0.0.0.0:1212",
379383
"admin_token": "MyAccessToken"
380384
}}
381385
}}

src/presentation/controllers/create/subcommands/environment/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async fn it_should_create_environment_from_valid_config() {
6262
}}
6363
],
6464
"http_api": {{
65+
"bind_address": "0.0.0.0:1212",
6566
"admin_token": "MyAccessToken"
6667
}}
6768
}}
@@ -182,6 +183,7 @@ async fn it_should_return_error_for_duplicate_environment() {
182183
}}
183184
],
184185
"http_api": {{
186+
"bind_address": "0.0.0.0:1212",
185187
"admin_token": "MyAccessToken"
186188
}}
187189
}}
@@ -262,6 +264,7 @@ async fn it_should_create_environment_in_custom_working_dir() {
262264
}}
263265
],
264266
"http_api": {{
267+
"bind_address": "0.0.0.0:1212",
265268
"admin_token": "MyAccessToken"
266269
}}
267270
}}

src/presentation/controllers/tests/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ pub fn create_valid_config(path: &Path, env_name: &str) -> PathBuf {
183183
}}
184184
],
185185
"http_api": {{
186+
"bind_address": "0.0.0.0:1212",
186187
"admin_token": "MyAccessToken"
187188
}}
188189
}}
@@ -298,6 +299,7 @@ pub fn create_config_with_invalid_name(path: &Path) -> PathBuf {
298299
}}
299300
],
300301
"http_api": {{
302+
"bind_address": "0.0.0.0:1212",
301303
"admin_token": "MyAccessToken"
302304
}}
303305
}}
@@ -370,6 +372,7 @@ pub fn create_config_with_missing_keys(path: &Path) -> PathBuf {
370372
}
371373
],
372374
"http_api": {
375+
"bind_address": "0.0.0.0:1212",
373376
"admin_token": "MyAccessToken"
374377
}
375378
}

0 commit comments

Comments
 (0)