This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With this endpoint clients will be able to fetch: - Info from the version as stated in the VERSION file. - Info of the git repository if possible (tag, commit and branch). - Supported API versions by the server. Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module API | ||
class Version < Grape::API | ||
before do | ||
authorization!(force_admin: false) | ||
end | ||
|
||
desc "Fetch the version of Portus", | ||
tags: ["version"], | ||
detail: "Returns the version of Portus and the supported API versions" | ||
|
||
get "/version" do | ||
version = ::Version.from_file | ||
git = if ::Version.git? | ||
if ::Version::TAG.present? | ||
{ tag: ::Version::TAG } | ||
else | ||
{ branch: ::Version::BRANCH, commit: ::Version::COMMIT } | ||
end | ||
end | ||
|
||
{ | ||
"api-versions": ["v1"], | ||
git: git, | ||
version: version | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "rails_helper" | ||
|
||
describe API::Version do | ||
let!(:admin) { create(:admin) } | ||
let!(:token) { create(:application_token, user: admin) } | ||
|
||
before :each do | ||
@header = build_token_header(token) | ||
end | ||
|
||
context "GET /api/version" do | ||
it "returns the proper versioning" do | ||
expect(::Version).to receive(:git?).and_return(true) | ||
|
||
get "/api/version", nil, @header | ||
|
||
resp = JSON.parse(response.body) | ||
expect(resp["api-versions"]).to eq(["v1"]) | ||
expect(resp["version"]).to eq(::Version.from_file) | ||
expect(resp["git"]).to_not include("tag") | ||
end | ||
|
||
it "returns the tag when present" do | ||
expect(::Version).to receive(:git?).and_return(true) | ||
expect(::Version::TAG).to receive(:present?).and_return(true) | ||
|
||
get "/api/version", nil, @header | ||
|
||
resp = JSON.parse(response.body) | ||
expect(resp["git"]).to include("tag") | ||
end | ||
|
||
it "returns a null git on stable releases" do | ||
expect(::Version).to receive(:git?).and_return(false) | ||
|
||
get "/api/version", nil, @header | ||
|
||
resp = JSON.parse(response.body) | ||
expect(resp["api-versions"]).to eq(["v1"]) | ||
expect(resp["version"]).to eq(::Version.from_file) | ||
expect(resp["git"]).to be_nil | ||
end | ||
end | ||
end |