Skip to content

Commit 76a6068

Browse files
Remove different tokent type option
1 parent da94519 commit 76a6068

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/server/auth.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ lazy_static! {
1414
Regex::new(r"^crater(-agent)?/(?P<sha>[a-f0-9]{7,40})( \(.*\))?$").unwrap();
1515
}
1616

17-
#[derive(Copy, Clone)]
18-
pub enum TokenType {
19-
Agent,
20-
}
21-
2217
pub struct AuthDetails {
2318
pub name: String,
2419
pub git_revision: Option<String>,
@@ -45,7 +40,7 @@ fn git_revision(user_agent: &str) -> Option<String> {
4540
.map(|cap| cap["sha"].to_string())
4641
}
4742

48-
fn check_auth(data: &Data, headers: &HeaderMap, token_type: TokenType) -> Option<AuthDetails> {
43+
fn check_auth(data: &Data, headers: &HeaderMap) -> Option<AuthDetails> {
4944
// Try to extract the git revision from the User-Agent header
5045
let git_revision = if let Some(ua_value) = headers.get(USER_AGENT) {
5146
if let Ok(ua) = ua_value.to_str() {
@@ -60,11 +55,7 @@ fn check_auth(data: &Data, headers: &HeaderMap, token_type: TokenType) -> Option
6055
if let Some(authorization_value) = headers.get(AUTHORIZATION) {
6156
if let Ok(authorization) = authorization_value.to_str() {
6257
if let Some(token) = parse_token(authorization) {
63-
let tokens = match token_type {
64-
TokenType::Agent => &data.tokens.agents,
65-
};
66-
67-
if let Some(name) = tokens.get(token) {
58+
if let Some(name) = data.tokens.agents.get(token) {
6859
return Some(AuthDetails {
6960
name: name.clone(),
7061
git_revision,
@@ -79,12 +70,11 @@ fn check_auth(data: &Data, headers: &HeaderMap, token_type: TokenType) -> Option
7970

8071
pub fn auth_filter(
8172
data: Arc<Data>,
82-
token_type: TokenType,
8373
) -> impl Filter<Extract = (AuthDetails,), Error = Rejection> + Clone {
8474
warp::header::headers_cloned().and_then(move |headers| {
8575
let data = data.clone();
8676
async move {
87-
match check_auth(&data, &headers, token_type) {
77+
match check_auth(&data, &headers) {
8878
Some(details) => Ok(details),
8979
None => Err(warp::reject::custom(HttpError::Forbidden)),
9080
}

src/server/routes/agent.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::experiments::{Assignee, Experiment};
33
use crate::prelude::*;
44
use crate::results::{DatabaseDB, EncodingType, ProgressData};
55
use crate::server::api_types::{AgentConfig, ApiResponse};
6-
use crate::server::auth::{auth_filter, AuthDetails, TokenType};
6+
use crate::server::auth::{auth_filter, AuthDetails};
77
use crate::server::messages::Message;
88
use crate::server::{Data, GithubData, HttpError};
99
use crossbeam_channel::Sender;
@@ -37,46 +37,46 @@ pub fn routes(
3737
.and(warp::path::end())
3838
.and(warp::body::json())
3939
.and(data_filter.clone())
40-
.and(auth_filter(data.clone(), TokenType::Agent))
40+
.and(auth_filter(data.clone()))
4141
.map(endpoint_config);
4242

4343
let next_experiment = warp::post()
4444
.and(warp::path("next-experiment"))
4545
.and(warp::path::end())
4646
.and(mutex_filter.clone())
4747
.and(github_data_filter)
48-
.and(auth_filter(data.clone(), TokenType::Agent))
48+
.and(auth_filter(data.clone()))
4949
.map(endpoint_next_experiment);
5050

5151
let next_crate = warp::post()
5252
.and(warp::path("next-crate"))
5353
.and(warp::path::end())
5454
.and(warp::body::json())
5555
.and(data_filter.clone())
56-
.and(auth_filter(data.clone(), TokenType::Agent))
56+
.and(auth_filter(data.clone()))
5757
.map(endpoint_next_crate);
5858

5959
let record_progress = warp::post()
6060
.and(warp::path("record-progress"))
6161
.and(warp::path::end())
6262
.and(warp::body::json())
6363
.and(data_filter.clone())
64-
.and(auth_filter(data.clone(), TokenType::Agent))
64+
.and(auth_filter(data.clone()))
6565
.map(endpoint_record_progress);
6666

6767
let heartbeat = warp::post()
6868
.and(warp::path("heartbeat"))
6969
.and(warp::path::end())
7070
.and(data_filter)
71-
.and(auth_filter(data.clone(), TokenType::Agent))
71+
.and(auth_filter(data.clone()))
7272
.map(endpoint_heartbeat);
7373

7474
let error = warp::post()
7575
.and(warp::path("error"))
7676
.and(warp::path::end())
7777
.and(warp::body::json())
7878
.and(mutex_filter)
79-
.and(auth_filter(data, TokenType::Agent))
79+
.and(auth_filter(data))
8080
.map(endpoint_error);
8181

8282
warp::any()

0 commit comments

Comments
 (0)