Skip to content

Commit

Permalink
Add internal token config
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Oct 1, 2024
1 parent fa2be8e commit 7536349
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
15 changes: 13 additions & 2 deletions judger/src/agent/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ pub struct HttpClient {
}

impl HttpClient {
pub fn new(base_url: String) -> Self {
let client = reqwest::Client::new();
pub fn new(base_url: String, internal_token: String) -> Self {
let client = reqwest::Client::builder()
.default_headers({
let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
reqwest::header::AUTHORIZATION,
reqwest::header::HeaderValue::from_str(&format!("Bearer {}", internal_token))
.unwrap(),
);
headers
})
.build()
.unwrap();
Self { client, base_url }
}

Expand Down
4 changes: 2 additions & 2 deletions judger/src/agent/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pub struct PlatformClient {
}

impl PlatformClient {
pub fn new(base_url: String) -> Self {
pub fn new(base_url: String, internal_token: String) -> Self {
Self {
client: HttpClient::new(base_url),
client: HttpClient::new(base_url, internal_token),
}
}

Expand Down
5 changes: 4 additions & 1 deletion judger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async fn main() -> std::io::Result<()> {
match opt.cmd {
option::JudgerCommad::Serve {
platform_uri,
internal_token,
fetch_task_interval,
port,
} => {
Expand All @@ -44,6 +45,7 @@ async fn main() -> std::io::Result<()> {
opt.problem_package_bucket,
opt.problem_package_dir,
platform_uri.clone(),
internal_token,
fetch_task_interval,
port,
)
Expand Down Expand Up @@ -72,10 +74,11 @@ async fn serve(
problem_package_bucket: String,
problem_package_dir: PathBuf,
platform_uri: String,
internal_token: String,
fetch_task_interval: u64,
port: u16,
) -> std::io::Result<()> {
let platform_client = platform::PlatformClient::new(platform_uri.clone());
let platform_client = platform::PlatformClient::new(platform_uri.clone(), internal_token);

let worker = match JudgeWorker::new(
Some(platform_client),
Expand Down
2 changes: 2 additions & 0 deletions judger/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum JudgerCommad {
Serve {
#[structopt(env = "PLATFORM_URI", default_value = "http://localhost:8080/")]
platform_uri: String,
#[structopt(env = "INTERNAL_TOKEN", default_value = "internal_token")]
internal_token: String,
/// Interval to fetch task in seconds
#[structopt(env = "FETCH_TASK_INTERVAL", default_value = "10")]
fetch_task_interval: u64,
Expand Down

0 comments on commit 7536349

Please sign in to comment.