Class: Soca::Plugins::Credentials

Inherits:
Soca::Plugin show all
Defined in:
lib/soca/plugins/credentials.rb

Instance Attribute Summary

Attributes inherited from Soca::Plugin

#options, #pusher

Instance Method Summary collapse

Methods inherited from Soca::Plugin

#app_dir, #config, #initialize, #logger, name, plugins

Constructor Details

This class inherits a constructor from Soca::Plugin

Instance Method Details

#after_load_couchapprcObject

Credentials plugin This plugin is run after the couchapprc is loaded, it checks the db field in every environment, searches for strings ending with ‘_CREDENTIALS’ in the URI userinfo field, passes the URI host to a method handling the requested credentials, and replaces the userinfo with the username and password from the credentials method.

When adding a new credentials method, please make sure the platform specific requirements are met (e.g. external tools or gems) and configure its platform availability in the credentials_supported? method



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/soca/plugins/credentials.rb', line 18

def after_load_couchapprc
  config['couchapprc']['env'].each do |env, cfg|
    next unless cfg['db'] =~ /^(https?:\/\/)([^@]+_CREDENTIALS)@(.*)$/i
    scheme = $1
    userinfo = $2
    host = $3

    unless credentials_supported?(userinfo)
      Soca.logger.error "#{userinfo} are not supported on the #{RUBY_PLATFORM} platform"
      puts 'skip'
      next
    end

    (username, password) = send(userinfo.downcase, host)
    unless username and password
      Soca.logger.warn "#{userinfo} returned empty credentials for #{host}"
    else
      credentials = "#{username}:#{password}@"
      config['couchapprc']['env'][env]['db'] = "#{scheme}#{credentials}#{host}"
      Soca.logger.debug "Replacing #{userinfo} with #{credentials} in #{cfg['db']}"
    end
  end
end