Class: VagrantPlugins::Registration::Action::Register

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-registration/action/register.rb

Overview

This registers the guest if the guest plugin supports it

Constant Summary collapse

MAX_REGISTRATION_ATTEMPTS =
3

Instance Method Summary collapse

Constructor Details

#initialize(app, _) ⇒ Register

Returns a new instance of Register.



10
11
12
13
# File 'lib/vagrant-registration/action/register.rb', line 10

def initialize(app, _)
  @app    = app
  @logger = Log4r::Logger.new('vagrant_registration::action::register')
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant-registration/action/register.rb', line 15

def call(env)
  ui = env[:ui]
  # Configuration from Vagrantfile
  config = env[:machine].config.registration
  machine = env[:machine]
  guest = env[:machine].guest

  if should_register?(machine, ui)
    ui.info I18n.t('registration.action.register.registration_info')
    check_configuration_options(machine, ui)

    if credentials_provided? machine
      guest.capability(:registration_register, ui)
    else
      @logger.debug I18n.t('registration.action.register.no_credentials')

      # Offer to register ATM or skip
      register_now = ui.ask I18n.t('registration.action.register.prompt')
      process_registration(guest, machine, ui, config) if register_now == 'y' || register_now.empty?
    end
  end

  @logger.debug(I18n.t('registration.action.register.skip_due_config')) if config.skip

  # Call next middleware in chain
  @app.call(env)
end