Commit 5e08ea59 authored by Douwe Maan's avatar Douwe Maan

Merge branch '2581-elastic-license-checks' into 'master'

Add explicit licensing for Elasticsearch

Closes #2581

See merge request !2108
parents a04a700a bbb67df4
......@@ -276,6 +276,16 @@ class ApplicationSetting < ActiveRecord::Base
end
end
def elasticsearch_indexing
License.feature_available?(:elastic_search) && super
end
alias_method :elasticsearch_indexing?, :elasticsearch_indexing
def elasticsearch_search
License.feature_available?(:elastic_search) && super
end
alias_method :elasticsearch_search?, :elasticsearch_search
def elasticsearch_url
read_attribute(:elasticsearch_url).split(',').map(&:strip)
end
......
......@@ -7,12 +7,14 @@ class License < ActiveRecord::Base
AUDITOR_USER_FEATURE = 'GitLab_Auditor_User'.freeze
SERVICE_DESK_FEATURE = 'GitLab_ServiceDesk'.freeze
OBJECT_STORAGE_FEATURE = 'GitLab_ObjectStorage'.freeze
ELASTIC_SEARCH_FEATURE = 'GitLab_ElasticSearch'.freeze
FEATURE_CODES = {
geo: GEO_FEATURE,
auditor_user: AUDITOR_USER_FEATURE,
service_desk: SERVICE_DESK_FEATURE,
object_storage: OBJECT_STORAGE_FEATURE,
elastic_search: ELASTIC_SEARCH_FEATURE,
# Features that make sense to Namespace:
deploy_board: DEPLOY_BOARD_FEATURE,
file_lock: FILE_LOCK_FEATURE
......@@ -24,7 +26,7 @@ class License < ActiveRecord::Base
EARLY_ADOPTER_PLAN = 'early_adopter'.freeze
EES_FEATURES = [
# ..
{ ELASTIC_SEARCH_FEATURE => 1 }
].freeze
EEP_FEATURES = [
......@@ -91,6 +93,8 @@ class License < ActiveRecord::Base
end
end
delegate :feature_available?, to: :current, allow_nil: true
def reset_current
RequestStore.delete(:current_license)
end
......@@ -183,7 +187,7 @@ class License < ActiveRecord::Base
end
def plan
restricted_attr(:plan)
restricted_attr(:plan, STARTER_PLAN)
end
def current_active_users_count
......
%fieldset
%legend Elasticsearch
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_indexing do
= f.check_box :elasticsearch_indexing
Elasticsearch indexing
- if License.feature_available?(:elastic_search)
%fieldset
%legend Elasticsearch
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_indexing do
= f.check_box :elasticsearch_indexing
Elasticsearch indexing
- missing = !Gitlab::Elastic::Indexer.experimental_indexer_present?
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_experimental_indexer do
= f.check_box :elasticsearch_experimental_indexer, disabled: missing
Use <a href="https://gitlab.com/gitlab-org/gitlab-elasticsearch-indexer">experimental repository indexer</a>
- if missing
(not installed)
- missing = !Gitlab::Elastic::Indexer.experimental_indexer_present?
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_experimental_indexer do
= f.check_box :elasticsearch_experimental_indexer, disabled: missing
Use <a href="https://gitlab.com/gitlab-org/gitlab-elasticsearch-indexer">experimental repository indexer</a>
- if missing
(not installed)
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_search do
= f.check_box :elasticsearch_search
Search with Elasticsearch enabled
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_search do
= f.check_box :elasticsearch_search
Search with Elasticsearch enabled
.form-group
= f.label :elasticsearch_url, 'URL', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_url, value: @application_setting.elasticsearch_url.join(', '), class: 'form-control', placeholder: 'http://localhost:9200'
.help-block
The url to use for connecting to Elasticsearch. Use a comma-separated list to support clustering (e.g., "http://localhost:9200, http://localhost:9201").
.form-group
= f.label :elasticsearch_url, 'URL', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_url, value: @application_setting.elasticsearch_url.join(', '), class: 'form-control', placeholder: 'http://localhost:9200'
.help-block
The url to use for connecting to Elasticsearch. Use a comma-separated list to support clustering (e.g., "http://localhost:9200, http://localhost:9201").
%fieldset
%legend Elasticsearch AWS IAM credentials
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_aws do
= f.check_box :elasticsearch_aws
Using AWS hosted Elasticsearch with IAM credentials
.form-group
= f.label :elasticsearch_aws_region, 'AWS region', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_aws_region, value: @application_setting.elasticsearch_aws_region, class: 'form-control'
.help-block
Region that elasticsearch is configured
%fieldset
%legend Elasticsearch AWS IAM credentials
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_aws do
= f.check_box :elasticsearch_aws
Using AWS hosted Elasticsearch with IAM credentials
.form-group
= f.label :elasticsearch_aws_region, 'AWS region', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_aws_region, value: @application_setting.elasticsearch_aws_region, class: 'form-control'
.help-block
Region that elasticsearch is configured
.form-group
= f.label :elasticsearch_aws_access_key, 'AWS Access Key', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_aws_access_key, value: @application_setting.elasticsearch_aws_access_key, class: 'form-control'
.help-block
AWS Access Key. Only required if not using role instance credentials
.form-group
= f.label :elasticsearch_aws_access_key, 'AWS Access Key', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_aws_access_key, value: @application_setting.elasticsearch_aws_access_key, class: 'form-control'
.help-block
AWS Access Key. Only required if not using role instance credentials
.form-group
= f.label :elasticsearch_aws_secret_access_key, 'AWS Secret Access Key', class: 'control-label col-sm-2'
.col-sm-10
= f.password_field :elasticsearch_aws_secret_access_key, value: @application_setting.elasticsearch_aws_secret_access_key, class: 'form-control'
.help-block
AWS Secret Access Key. Only required if not using role instance credentials
.form-group
= f.label :elasticsearch_aws_secret_access_key, 'AWS Secret Access Key', class: 'control-label col-sm-2'
.col-sm-10
= f.password_field :elasticsearch_aws_secret_access_key, value: @application_setting.elasticsearch_aws_secret_access_key, class: 'form-control'
.help-block
AWS Secret Access Key. Only required if not using role instance credentials
---
title: Add explicit licensing for Elasticsearch
merge_request: 2108
author:
......@@ -303,6 +303,35 @@ describe ApplicationSetting, models: true do
end
end
describe 'elasticsearch licensing' do
before do
setting.elasticsearch_search = true
setting.elasticsearch_indexing = true
end
def expect_is_es_licensed
expect(License).to receive(:feature_available?).with(:elastic_search).at_least(:once)
end
it 'disables elasticsearch when unlicensed' do
expect_is_es_licensed.and_return(false)
expect(setting.elasticsearch_indexing?).to be_falsy
expect(setting.elasticsearch_indexing).to be_falsy
expect(setting.elasticsearch_search?).to be_falsy
expect(setting.elasticsearch_search).to be_falsy
end
it 'enables elasticsearch when licensed' do
expect_is_es_licensed.and_return(true)
expect(setting.elasticsearch_indexing?).to be_truthy
expect(setting.elasticsearch_indexing).to be_truthy
expect(setting.elasticsearch_search?).to be_truthy
expect(setting.elasticsearch_search).to be_truthy
end
end
describe '#elasticsearch_url' do
it 'presents a single URL as a one-element array' do
setting.elasticsearch_url = 'http://example.com'
......
......@@ -344,6 +344,20 @@ describe License do
end
describe 'reading add-ons' do
describe '#plan' do
it 'interprets no plan as EES' do
license = build(:license, data: build(:gitlab_license, restrictions: { add_ons: {} }).export)
expect(license.plan).to eq(License::STARTER_PLAN)
end
it 'interprets an unknown plan as unknown' do
license = build_license_with_add_ons({}, plan: 'unknown')
expect(license.plan).to eq('unknown')
end
end
describe '#add_ons' do
context 'without add-ons' do
it 'returns an empty Hash' do
......
......@@ -17,7 +17,7 @@ describe API::License, api: true do
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']).not_to be_empty
expect(json_response['add_ons']).to eq({ 'GitLab_FileLocks' => 1, 'GitLab_Auditor_User' => 1 })
expect(json_response['add_ons']).to eq(license.add_ons)
end
it 'denies access if not admin' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment