Commit b27f9848 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Add license checks for object storage feature

parent 2a5cafe0
...@@ -6,11 +6,13 @@ class License < ActiveRecord::Base ...@@ -6,11 +6,13 @@ class License < ActiveRecord::Base
GEO_FEATURE = 'GitLab_Geo'.freeze GEO_FEATURE = 'GitLab_Geo'.freeze
AUDITOR_USER_FEATURE = 'GitLab_Auditor_User'.freeze AUDITOR_USER_FEATURE = 'GitLab_Auditor_User'.freeze
SERVICE_DESK_FEATURE = 'GitLab_ServiceDesk'.freeze SERVICE_DESK_FEATURE = 'GitLab_ServiceDesk'.freeze
OBJECT_STORAGE_FEATURE = 'GitLab_ObjectStorage'.freeze
FEATURE_CODES = { FEATURE_CODES = {
geo: GEO_FEATURE, geo: GEO_FEATURE,
auditor_user: AUDITOR_USER_FEATURE, auditor_user: AUDITOR_USER_FEATURE,
service_desk: SERVICE_DESK_FEATURE, service_desk: SERVICE_DESK_FEATURE,
object_storage: OBJECT_STORAGE_FEATURE,
# Features that make sense to Namespace: # Features that make sense to Namespace:
deploy_board: DEPLOY_BOARD_FEATURE, deploy_board: DEPLOY_BOARD_FEATURE,
file_lock: FILE_LOCK_FEATURE file_lock: FILE_LOCK_FEATURE
...@@ -31,7 +33,8 @@ class License < ActiveRecord::Base ...@@ -31,7 +33,8 @@ class License < ActiveRecord::Base
{ FILE_LOCK_FEATURE => 1 }, { FILE_LOCK_FEATURE => 1 },
{ GEO_FEATURE => 1 }, { GEO_FEATURE => 1 },
{ AUDITOR_USER_FEATURE => 1 }, { AUDITOR_USER_FEATURE => 1 },
{ SERVICE_DESK_FEATURE => 1 } { SERVICE_DESK_FEATURE => 1 },
{ OBJECT_STORAGE_FEATURE => 1 }
].freeze ].freeze
EEU_FEATURES = [ EEU_FEATURES = [
...@@ -52,7 +55,8 @@ class License < ActiveRecord::Base ...@@ -52,7 +55,8 @@ class License < ActiveRecord::Base
{ FILE_LOCK_FEATURE => 1 }, { FILE_LOCK_FEATURE => 1 },
{ GEO_FEATURE => 1 }, { GEO_FEATURE => 1 },
{ AUDITOR_USER_FEATURE => 1 }, { AUDITOR_USER_FEATURE => 1 },
{ SERVICE_DESK_FEATURE => 1 } { SERVICE_DESK_FEATURE => 1 },
{ OBJECT_STORAGE_FEATURE => 1 }
].freeze ].freeze
FEATURES_BY_PLAN = { FEATURES_BY_PLAN = {
......
...@@ -3,6 +3,7 @@ require 'carrierwave/storage/fog' ...@@ -3,6 +3,7 @@ require 'carrierwave/storage/fog'
class ObjectStoreUploader < GitlabUploader class ObjectStoreUploader < GitlabUploader
before :store, :set_default_local_store before :store, :set_default_local_store
before :store, :verify_license!
LOCAL_STORE = 1 LOCAL_STORE = 1
REMOTE_STORE = 2 REMOTE_STORE = 2
...@@ -104,6 +105,13 @@ class ObjectStoreUploader < GitlabUploader ...@@ -104,6 +105,13 @@ class ObjectStoreUploader < GitlabUploader
file.try(:storage) == cache_storage file.try(:storage) == cache_storage
end end
# We block storing artifacts on Object Storage, not receiving
def verify_license!(new_file)
return if file_storage?
raise 'Object Storage feature is missing' unless subject.project.feature_available?(:object_storage)
end
private private
def set_default_local_store(new_file) def set_default_local_store(new_file)
......
...@@ -12,6 +12,8 @@ module StubConfiguration ...@@ -12,6 +12,8 @@ module StubConfiguration
} }
) )
allow_any_instance_of(ArtifactUploader).to receive(:verify_license!) { true }
::Fog::Storage.new(Gitlab.config.artifacts.object_store.connection).tap do |connection| ::Fog::Storage.new(Gitlab.config.artifacts.object_store.connection).tap do |connection|
begin begin
connection.directories.create(key: 'artifacts') connection.directories.create(key: 'artifacts')
......
...@@ -186,4 +186,49 @@ describe ObjectStoreUploader do ...@@ -186,4 +186,49 @@ describe ObjectStoreUploader do
it { is_expected.to eq(false) } it { is_expected.to eq(false) }
end end
describe '#verify_license!' do
subject { uploader.verify_license!(nil) }
context 'when using local storage' do
before do
expect(object).to receive(:artifacts_file_store) { described_class::LOCAL_STORE }
end
it "does not raise an error" do
expect { subject }.not_to raise_error
end
end
context 'when using remote storage' do
let(:project) { double }
before do
uploader_class.storage_options double(
object_store: double(enabled: true))
expect(object).to receive(:artifacts_file_store) { described_class::REMOTE_STORE }
expect(object).to receive(:project) { project }
end
context 'feature is not available' do
before do
expect(project).to receive(:feature_available?).with(:object_storage) { false }
end
it "does raise an error" do
expect { subject }.to raise_error(/Object Storage feature is missing/)
end
end
context 'feature is available' do
before do
expect(project).to receive(:feature_available?).with(:object_storage) { true }
end
it "does not raise an error" do
expect { subject }.not_to raise_error
end
end
end
end
end end
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