Skip to content

Commit

Permalink
refactor: details endpoint will retrieve driver defaults instead of m…
Browse files Browse the repository at this point in the history
…etadata (#264)
  • Loading branch information
naqvis authored Nov 21, 2023
1 parent e603a0d commit 2437f7d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/api/drivers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ module PlaceOS::Core::Api
) : Nil
Log.context.set(driver: driver_file, repository: repository, commit: commit, branch: branch)
repo = Model::Repository.find!(repository)
metadata = store.metadata(driver_file, commit, branch, repo.uri)
if metadata.success
defaults = store.defaults(driver_file, commit, branch, repo.uri)
if defaults.success
response.headers["Content-Type"] = "application/json"
render text: metadata.output
render text: defaults.output
end
password = repo.decrypt_password if repo.password.presence
result = store.compile(driver_file, repo.uri, commit, branch, false, repo.username, password)
if result.success
metadata = store.metadata(driver_file, commit, branch, repo.uri)
if metadata.success
defaults = store.defaults(driver_file, commit, branch, repo.uri)
if defaults.success
response.headers["Content-Type"] = "application/json"
render text: metadata.output
render text: defaults.output
end
end
render :internal_server_error, text: result.output
Expand Down
23 changes: 22 additions & 1 deletion src/placeos-core/driver_manager.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ module PlaceOS::Core
return Result.new(success: true, output: resp.body.as(String)) if resp.success?
Result.new(output: "Metadata not found. Server returned #{resp.status_code}")
rescue ex
return Result.new(output: ex.message.not_nil!, name: file_name)
Result.new(output: ex.message.not_nil!, name: file_name)
end

def defaults(file_name : String, commit : String, branch : String, uri : String)
resp = BuildApi.defaults(file_name, commit, branch, uri)
return Result.new(success: true, output: resp.body.as(String)) if resp.success?
Result.new(output: "Driver defaults not found. Server returned #{resp.status_code}")
rescue ex
Result.new(output: ex.message.not_nil!, name: file_name)
end

def built?(file_name : String, commit : String, branch : String, uri : String) : String?
Expand Down Expand Up @@ -130,6 +138,19 @@ module PlaceOS::Core
end
end

def self.defaults(file_name : String, commit : String, branch : String, uri : String)
host = URI.parse(Core.build_host)
file_name = URI.encode_www_form(file_name)
ConnectProxy::HTTPClient.new(host) do |client|
path = "#{BUILD_API_BASE}/defaults/#{file_name}"
params = URI::Params.encode({"url" => uri, "branch" => branch, "commit" => commit})
uri = "#{path}?#{params}"
rep = client.get(uri)
Log.debug { {message: "Getting driver defaults. Server respose: #{rep.status_code}", file_name: file_name, commit: commit, branch: branch} }
rep
end
end

def self.compiled?(file_name : String, commit : String, branch : String, uri : String)
host = URI.parse(Core.build_host)
file_name = URI.encode_www_form(file_name)
Expand Down

0 comments on commit 2437f7d

Please sign in to comment.