Class: ObjectStorage::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/object_storage/config.rb

Constant Summary collapse

AWS_PROVIDER =
'AWS'
AZURE_PROVIDER =
'AzureRM'
GOOGLE_PROVIDER =
'Google'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Config

Returns a new instance of Config.


11
12
13
# File 'lib/object_storage/config.rb', line 11

def initialize(options)
  @options = options.to_hash.deep_symbolize_keys
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


9
10
11
# File 'lib/object_storage/config.rb', line 9

def options
  @options
end

Instance Method Details

#aws?Boolean

AWS-specific options

Returns:

  • (Boolean)

46
47
48
# File 'lib/object_storage/config.rb', line 46

def aws?
  provider == AWS_PROVIDER
end

#azure?Boolean

Returns:

  • (Boolean)

81
82
83
# File 'lib/object_storage/config.rb', line 81

def azure?
  provider == AZURE_PROVIDER
end

#azure_storage_domainObject

Begin Azure-specific options


72
73
74
# File 'lib/object_storage/config.rb', line 72

def azure_storage_domain
  credentials[:azure_storage_domain]
end

#bucketObject


37
38
39
# File 'lib/object_storage/config.rb', line 37

def bucket
  options[:remote_directory]
end

#consolidated_settings?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/object_storage/config.rb', line 41

def consolidated_settings?
  options.fetch(:consolidated_settings, false)
end

#credentialsObject


25
26
27
# File 'lib/object_storage/config.rb', line 25

def credentials
  @credentials ||= options[:connection] || {}
end

#enabled?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'lib/object_storage/config.rb', line 33

def enabled?
  options[:enabled]
end

#fog_attributesObject


85
86
87
88
89
90
91
92
# File 'lib/object_storage/config.rb', line 85

def fog_attributes
  @fog_attributes ||= begin
    return {} unless enabled? && aws?
    return {} unless server_side_encryption.present?

    aws_server_side_encryption_headers.compact
  end
end

#google?Boolean

End Azure-specific options

Returns:

  • (Boolean)

77
78
79
# File 'lib/object_storage/config.rb', line 77

def google?
  provider == GOOGLE_PROVIDER
end

#load_providerObject


15
16
17
18
19
20
21
22
23
# File 'lib/object_storage/config.rb', line 15

def load_provider
  if aws?
    require 'fog/aws'
  elsif google?
    require 'fog/google'
  elsif azure?
    require 'fog/azurerm'
  end
end

#providerObject


66
67
68
# File 'lib/object_storage/config.rb', line 66

def provider
  credentials[:provider].to_s
end

#server_side_encryptionObject


58
59
60
# File 'lib/object_storage/config.rb', line 58

def server_side_encryption
  storage_options[:server_side_encryption]
end

#server_side_encryption_kms_key_idObject


62
63
64
# File 'lib/object_storage/config.rb', line 62

def server_side_encryption_kms_key_id
  storage_options[:server_side_encryption_kms_key_id]
end

#storage_optionsObject


29
30
31
# File 'lib/object_storage/config.rb', line 29

def storage_options
  @storage_options ||= options[:storage_options] || {}
end

#use_iam_profile?Boolean

Returns:

  • (Boolean)

50
51
52
# File 'lib/object_storage/config.rb', line 50

def use_iam_profile?
  Gitlab::Utils.to_boolean(credentials[:use_iam_profile], default: false)
end

#use_path_style?Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/object_storage/config.rb', line 54

def use_path_style?
  Gitlab::Utils.to_boolean(credentials[:path_style], default: false)
end