Class: VagrantPlugins::ScriptRock::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::ScriptRock::Config
- Defined in:
- lib/vagrant-scriptrock/config.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#connect_url ⇒ Object
Returns the value of attribute connect_url.
-
#first_hop ⇒ Object
Returns the value of attribute first_hop.
-
#scriptrock_yml_path ⇒ Object
Returns the value of attribute scriptrock_yml_path.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#ssh_pubkey ⇒ Object
Returns the value of attribute ssh_pubkey.
Instance Method Summary collapse
- #dump ⇒ Object
- #finalize! ⇒ Object
- #get_ssh_pubkey ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_vars_from_yml ⇒ Object
- #unset(v) ⇒ Object
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vagrant-scriptrock/config.rb', line 15 def initialize @debug = false puts "config initialize" if @debug @scriptrock_yml_path = "~/.scriptrock/scriptrock.yml" @first_hop = UNSET_VALUE @api_key = UNSET_VALUE @secret_key = UNSET_VALUE @connect_url = UNSET_VALUE @ssh_pubkey = UNSET_VALUE end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/vagrant-scriptrock/config.rb', line 10 def api_key @api_key end |
#connect_url ⇒ Object
Returns the value of attribute connect_url.
12 13 14 |
# File 'lib/vagrant-scriptrock/config.rb', line 12 def connect_url @connect_url end |
#first_hop ⇒ Object
Returns the value of attribute first_hop.
9 10 11 |
# File 'lib/vagrant-scriptrock/config.rb', line 9 def first_hop @first_hop end |
#scriptrock_yml_path ⇒ Object
Returns the value of attribute scriptrock_yml_path.
8 9 10 |
# File 'lib/vagrant-scriptrock/config.rb', line 8 def scriptrock_yml_path @scriptrock_yml_path end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
11 12 13 |
# File 'lib/vagrant-scriptrock/config.rb', line 11 def secret_key @secret_key end |
#ssh_pubkey ⇒ Object
Returns the value of attribute ssh_pubkey.
13 14 15 |
# File 'lib/vagrant-scriptrock/config.rb', line 13 def ssh_pubkey @ssh_pubkey end |
Instance Method Details
#dump ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/vagrant-scriptrock/config.rb', line 86 def dump puts "config dump" puts "yml_path #{@scriptrock_yml_path}" puts "api_key #{@api_key}" puts "connect_url #{@connect_url}" puts "ssh_pubkey #{@ssh_pubkey}" end |
#finalize! ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/vagrant-scriptrock/config.rb', line 74 def finalize! puts "finalize!" if @debug get_ssh_pubkey() if unset(@first_hop) @first_hop = "" end end |
#get_ssh_pubkey ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vagrant-scriptrock/config.rb', line 48 def get_ssh_pubkey if @ssh_pubkey != UNSET_VALUE return @ssh_pubkey end load_vars_from_yml() begin puts "ScriptRock API connect_url #{@connect_url}" if @debug response = HTTParty.get( "#{@connect_url}/api/v1/users/ssh_key.json", :headers => { "Authorization" => "Token token=\"#{@api_key}\"" }) if response.code == 200 h = JSON.parse(response.body) @ssh_pubkey = h["public_key"] else puts "ScriptRock get_ssh_pubkey error code = #{response.code}" puts "ScriptRock get_ssh_pubkey error body = #{response.body}" end rescue => e puts "ScriptRock get_ssh_pubkey error = #{e.class}: #{e.}" end return @ssh_pubkey end |
#load_vars_from_yml ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vagrant-scriptrock/config.rb', line 26 def load_vars_from_yml if unset(@api_key) || unset(@secret_key) || unset(@connect_url) if unset(@scriptrock_yml_path) puts "ScriptRock yml config path un-set, not loading values from yml" elsif !File.exist?(File.(@scriptrock_yml_path)) puts "ScriptRock yml file '#{@scriptrock_yml_path}' doesn't exist, not loading values from yml" else yml = YAML.load(File.read(File.(@scriptrock_yml_path))) puts yml if @debug if unset(@api_key) @api_key = yml["api_key"] end if unset(@secret_key) @secret_key = yml["secret_key"] end if unset(@connect_url) @connect_url = yml["connect_url"] end end end end |
#unset(v) ⇒ Object
82 83 84 |
# File 'lib/vagrant-scriptrock/config.rb', line 82 def unset(v) return v == UNSET_VALUE || v == nil || v == "" end |
#validate(machine) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/vagrant-scriptrock/config.rb', line 94 def validate(machine) puts "config validate" if @debug dump if @debug errors = _detected_errors if unset(@api_key) errors << "ScriptRock Guardrail api_key is not set" end if unset(@secret_key) errors << "ScriptRock Guardrail secret_key is not set" end if unset(@connect_url) errors << "ScriptRock Guardrail connect_url is not set" end if unset(@ssh_pubkey) errors << "ScriptRock Guardrail ssh public key is not set" end { "errors" => errors } end |