summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2015-11-24 11:50:08 -0500
committerPatricio Cano <suprnova32@gmail.com>2015-11-30 13:03:29 -0500
commitedc6d00bf8fa89c9295fd014adb34ae65452befb (patch)
treed1df36d4dca2297c3be218c84a352f4d57234c39
parent437679ec45c042190e5bfd925067cf14eefcd2f6 (diff)
downloadgitlab-ce-edc6d00bf8fa89c9295fd014adb34ae65452befb.tar.gz
License information can now be retrieved via the API
-rw-r--r--CHANGELOG-EE3
-rw-r--r--doc/api/README.md1
-rw-r--r--doc/api/license.md24
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/entities.rb12
-rw-r--r--lib/api/license_info.rb18
-rw-r--r--spec/factories.rb1
-rw-r--r--spec/requests/api/license_spec.rb27
8 files changed, 86 insertions, 1 deletions
diff --git a/CHANGELOG-EE b/CHANGELOG-EE
index 281714e2512..f42b480e133 100644
--- a/CHANGELOG-EE
+++ b/CHANGELOG-EE
@@ -1,4 +1,5 @@
v 8.3.0 (unreleased)
+ - License information can now be retrieved via the API
v 8.2.0
- Invalidate stored jira password if the endpoint URL is changed
@@ -26,7 +27,7 @@ v 8.1.0
- Add documentation for "Share project with group" API call
- Added an issues template (Hannes Rosenögger)
- Add documentation for "Share project with group" API call
- - Abiliy to disable 'Share with Group' feature (via UI and API)
+ - Ability to disable 'Share with Group' feature (via UI and API)
v 8.0.6
- No EE-specific changes
diff --git a/doc/api/README.md b/doc/api/README.md
index 25a31b235cc..69f86ddda27 100644
--- a/doc/api/README.md
+++ b/doc/api/README.md
@@ -23,6 +23,7 @@
- [Namespaces](namespaces.md)
- [Settings](settings.md)
- [Keys](keys.md)
+- [License](license.md)
## Clients
diff --git a/doc/api/license.md b/doc/api/license.md
new file mode 100644
index 00000000000..dc95f9fcebf
--- /dev/null
+++ b/doc/api/license.md
@@ -0,0 +1,24 @@
+# License
+
+## Retrieve information about the current license
+
+In order to retrieve the license information, you need to authenticate yourself
+as an admin.
+
+```
+GET /license
+```
+
+```json
+{
+ "starts_at": "2015-10-24",
+ "expires_at": "2016-10-24",
+ "licensee": {
+ "Name": "John Doe",
+ "Company": "Doe, Inc.",
+ "Email": "john@doe.com"
+ },
+ "user_limit": 100,
+ "active_users": 60
+}
+``` \ No newline at end of file
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 4f66dad6aa8..a483864a449 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -56,5 +56,6 @@ module API
mount Settings
mount Keys
mount Tags
+ mount LicenseInfo
end
end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 7d2eb69c0f5..954b22eb4f3 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -373,5 +373,17 @@ module API
end
end
end
+
+ class License < Grape::Entity
+ expose :starts_at, :expires_at, :licensee
+
+ expose :user_limit do |license, options|
+ license.restricted?(:active_user_count) ? license.restrictions[:active_user_count] : 0
+ end
+
+ expose :active_users do |license, options|
+ ::User.active.count
+ end
+ end
end
end
diff --git a/lib/api/license_info.rb b/lib/api/license_info.rb
new file mode 100644
index 00000000000..c2c173af429
--- /dev/null
+++ b/lib/api/license_info.rb
@@ -0,0 +1,18 @@
+module API
+ class LicenseInfo < Grape::API
+ before { authenticated_as_admin! }
+
+ resource :license do
+
+ # Get information on the currently active license
+ #
+ # Example request:
+ # GET /license
+ get do
+ @license = License.current
+
+ present @license, with: Entities::License
+ end
+ end
+ end
+end
diff --git a/spec/factories.rb b/spec/factories.rb
index b65582e80bf..8e76a332f77 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -225,6 +225,7 @@ FactoryGirl.define do
factory :gitlab_license, class: "Gitlab::License" do
starts_at { Date.today - 1.month }
+ expires_at { Date.today + 11.months }
licensee do
{ "Name" => FFaker::Name.name }
end
diff --git a/spec/requests/api/license_spec.rb b/spec/requests/api/license_spec.rb
new file mode 100644
index 00000000000..6ff56cd708f
--- /dev/null
+++ b/spec/requests/api/license_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe API::API, api: true do
+ include ApiHelpers
+
+ let(:gl_license) { build(:gitlab_license) }
+ let(:license) { build(:license, data: gl_license.export) }
+ let(:admin) { create(:admin) }
+ let(:user) { create(:user) }
+
+ describe 'GET /license' do
+ it 'should retrieve the license information if admin is logged in' do
+ get api('/license', admin)
+ expect(response.status).to eq 200
+ expect(json_response['user_limit']).to eq 0
+ expect(Date.parse(json_response['starts_at'])).to eq Date.today - 1.month
+ expect(Date.parse(json_response['expires_at'])).to eq Date.today + 11.months
+ expect(json_response['active_users']).to eq 1
+ expect(json_response['licensee']).to_not be_empty
+ end
+
+ it 'should deny access if not admin' do
+ get api('/license', user)
+ expect(response.status).to eq 403
+ end
+ end
+end