Class: Ogre::SetPrivateKey

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/ogre/set-private-key.rb

Overview

Set Private Key is used to set a chef validation key via a vco workflow

Instance Method Summary collapse

Instance Method Details

#set_private_keyObject

rubocop:disable CyclomaticComplexity, PerceivedComplexity Execute vcoworkflows gem to call set private key



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ogre/set-private-key.rb', line 20

def set_private_key
  # get workflow
  # rubocop:disable AlignParameters
  workflow = VcoWorkflows::Workflow.new(options[:vco_wf_name]    || Config.options[:vco_wf_name],
                            url:        options[:vco_url]        || Config.options[:vco_url],
                            verify_ssl: options[:vco_verify_ssl] || Config.options[:vco_verify_ssl],
                            username:   options[:vco_user]       || Config.options[:vco_user],
                            password:   options[:vco_password]   || Config.options[:vco_password])
  # rubocop:enable AlignParameters

  # set parameters
  workflow.parameter('chefHostname', chef_hostname)
  workflow.parameter('userid', chef_validator_name)
  workflow.parameter('pem', File.read(key_path))

  # run workflow
  execution_id = workflow.execute

  # check status
  finished = false
  until finished
    # Fetch a new workflow token to check the status of the workflow execution
    wf_token = workflow.token
    # If the execution is no longer alive, exit the loop
    unless wf_token.alive?
      finished = true
      execution_id
    end
    sleep 5
  end

  # output result
  log = workflow.token(execution_id).to_s
  puts log.slice(0..log.index('Input Parameters:') - 2)
end