Skip to content

Commit

Permalink
fix: querying generic git repos with auth (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach authored Sep 21, 2022
1 parent 8223d87 commit 347006b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion OPENAPI_DOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
description: Provides repository commit details and downloads frontend repository
code
title: frontend-loader
version: 2.5.1
version: 2.5.2
paths:
/api/frontend-loader/v1/remotes/{repository_url}/releases:
get:
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: placeos-frontend-loader
version: 2.5.1
version: 2.5.2

authors:
- Caspian Baska <[email protected]>
Expand Down
7 changes: 3 additions & 4 deletions src/placeos-frontend-loader/api/remotes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ module PlaceOS::FrontendLoader::Api
@[AC::Route::Filter(:before_action)]
protected def get_repository_url(
@[AC::Param::Info(description: "the git url that represents the repository", example: "https://github.com/PlaceOS/PlaceOS.git")]
repository_url : String,
@repository_url : String,
@[AC::Param::Info(description: "a username for access if required", example: "steve")]
username : String? = nil,
@username : String? = nil,
@[AC::Param::Info(description: "the password or access token as required", example: "ab34cfe4567")]
password : String? = nil
@password : String? = nil
)
@repository_url = repository_url
end

getter! repository_url : String
Expand Down
38 changes: 25 additions & 13 deletions src/placeos-frontend-loader/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,47 @@ module PlaceOS::FrontendLoader
end

# Releases for a remote repository
def releases(repository_url : String)
def releases(repository_url : String, username : String? = nil, password : String? = nil)
encoded_url = URI.encode_www_form(repository_url)
path = "/remotes/#{encoded_url}/releases"
response = get(path)
params = URI::Params.build do |form|
form.add("username", username.to_s) if username.presence
form.add("password", password.to_s) if password.presence
end
response = get("/remotes/#{encoded_url}/releases?#{params}")
Array(String).from_json(response.body)
end

# Commits for a remote repository
def remote_commits(repository_url : String, branch : String)
def remote_commits(repository_url : String, branch : String, username : String? = nil, password : String? = nil)
encoded_url = URI.encode_www_form(repository_url)
params = HTTP::Params{"branch" => branch}
path = "/remotes/#{encoded_url}/commits?#{params}"
response = get(path)
params = URI::Params.build do |form|
form.add("branch", branch)
form.add("username", username.to_s) if username.presence
form.add("password", password.to_s) if password.presence
end
response = get("/remotes/#{encoded_url}/commits?#{params}")
Array(GitRepository::Commit).from_json(response.body)
end

# Branches for a remote repository
def remote_branches(repository_url : String)
def remote_branches(repository_url : String, username : String? = nil, password : String? = nil)
encoded_url = URI.encode_www_form(repository_url)
path = "/remotes/#{encoded_url}/branches"
response = get(path)
params = URI::Params.build do |form|
form.add("username", username.to_s) if username.presence
form.add("password", password.to_s) if password.presence
end
response = get("/remotes/#{encoded_url}/branches?#{params}")
Array(String).from_json(response.body)
end

# Tags for a remote repository
def tags(repository_url : String)
def tags(repository_url : String, username : String? = nil, password : String? = nil)
encoded_url = URI.encode_www_form(repository_url)
path = "/remotes/#{encoded_url}/tags"
response = get(path)
params = URI::Params.build do |form|
form.add("username", username.to_s) if username.presence
form.add("password", password.to_s) if password.presence
end
response = get("/remotes/#{encoded_url}/tags?#{params}")
Array(String).from_json(response.body)
end

Expand Down

0 comments on commit 347006b

Please sign in to comment.