Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo: Allow /s in repo names #33

Merged
merged 2 commits into from
Dec 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ impl Config {
pub fn get_repoconfig(&self, name: &str) -> Result<&RepoConfig, ApiError> {
self.repos.get(name).ok_or_else (|| ApiError::BadRequest("No such repo".to_string()))
}

pub fn get_repoconfig_from_path(&self, path: &Path) -> Result<&RepoConfig, ApiError> {
for (repo, config) in self.repos.iter() {
if path.starts_with(repo) {
return Ok(config)
}
}
Err(ApiError::BadRequest("No such repo".to_string()))
dbnicholson marked this conversation as resolved.
Show resolved Hide resolved
}
dbnicholson marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down Expand Up @@ -423,18 +432,18 @@ fn verify_repo_token(req: &HttpRequest, commit: ostree::OstreeCommit, repoconfig
fn handle_repo(config: Data<Config>,
req: HttpRequest) -> Result<HttpResponse, actix_web::Error> {
let tail = req.match_info().query("tail");
let repo = req.match_info().query("repo");
let repoconfig = config.get_repoconfig(&repo)?;
let tailpath = canonicalize_path(tail.trim_start_matches('/'))?;
let repoconfig = config.get_repoconfig_from_path(&tailpath)?;

let relpath = canonicalize_path(tail.trim_start_matches('/'))?;
let namepath = Path::new(&repoconfig.name);
let relpath = tailpath.strip_prefix(&namepath)
.map_err(|e| ApiError::InternalServerError(e.to_string()))?;
let path = Path::new(&repoconfig.path).join(&relpath);
if path.is_dir() {
return Err(ErrorNotFound("Ignoring directory"));
}

if let Some(commit) = get_commit_for_file (&path) {
let repo = req.match_info().query("repo");
let repoconfig = config.get_repoconfig(&repo)?;
verify_repo_token(&req, commit, repoconfig, &path)?;
}

Expand Down Expand Up @@ -513,7 +522,7 @@ pub fn create_app (
resp
})
})
.service(web::resource("/{repo}/{tail:.*}").name("repo")
.service(web::resource("/{tail:.*}").name("repo")
alexlarsson marked this conversation as resolved.
Show resolved Hide resolved
.route(web::get().to(handle_repo))
.route(web::head().to(handle_repo))
.to(HttpResponse::MethodNotAllowed)
Expand Down