Module: Match::Encryption

Defined in:
match/lib/match/encryption.rb,
match/lib/match/encryption/openssl.rb,
match/lib/match/encryption/interface.rb

Defined Under Namespace

Classes: Interface, OpenSSL

Class Method Summary collapse

Class Method Details

.backendsObject


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'match/lib/match/encryption.rb', line 7

def backends
  @backends ||= {
    "git" => lambda { |params|
      # OpenSSL is storage agnostic so this maps git_url
      # to keychain_name for the name of the keychain entry
      params[:keychain_name] = params[:git_url]
      return Encryption::OpenSSL.configure(params)
    },
    "google_cloud" => lambda { |params|
      return nil
    },
    "s3" => lambda { |params|
      params[:keychain_name] = params[:s3_bucket]
      return Encryption::OpenSSL.configure(params)
    }
  }
end

.for_storage_mode(storage_mode, params) ⇒ Object

Returns the class to be used for a given `storage_mode`


41
42
43
44
45
46
# File 'match/lib/match/encryption.rb', line 41

def for_storage_mode(storage_mode, params)
  configurator = backends[storage_mode.to_s]
  return configurator.call(params) if configurator

  UI.user_error!("No encryption backend for storage mode '#{storage_mode}'")
end

.register_backend(type: nil, encryption_class: nil, &configurator) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'match/lib/match/encryption.rb', line 25

def register_backend(type: nil, encryption_class: nil, &configurator)
  UI.user_error!("No type specified for encryption backend") if type.nil?

  normalized_name = type.to_s
  UI.message("Replacing Match::Encryption backend for type '#{normalized_name}'") if backends.include?(normalized_name)

  if configurator
    @backends[normalized_name] = configurator
  elsif encryption_class
    @backends[normalized_name] = ->(params) { return encryption_class.configure(params) }
  else
    UI.user_error!("Specify either a `encryption_class` or a configuration block when registering a encryption backend")
  end
end