#!/usr/bin/env ruby # (c) Copyright 2014 Hewlett-Packard Development Company, L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. module Setup def setup create_dir create_credentials_file file = get_credentials_file template = YAML.load_file(file) # access key begin access_key = template['default']['access_key'] rescue puts 'which access key to use' access_key = $stdin.gets.chomp save_to_credentials_file('access_key', access_key) end # secret key begin secret_key = template['default']['secret_key'] rescue puts 'which secret_key key to use' secret_key = $stdin.gets.chomp save_to_credentials_file('secret_key', secret_key) end # auth uri begin auth_uri = template['default']['auth_uri'] rescue puts 'which auth url to use' auth_uri = $stdin.gets.chomp save_to_credentials_file('auth_uri', auth_uri) end # tenant id begin tenant_id = template['default']['tenant_id'] rescue puts 'which tenant id to use' tenant_id = $stdin.gets.chomp save_to_credentials_file('tenant_id', tenant_id) end # availability zone begin availability_zone = template['default']['availability_zone'] rescue puts 'which availability zone to use' availability_zone = $stdin.gets.chomp save_to_credentials_file('availability_zone', availability_zone) end end end def create_credentials_file home = File.expand_path('~') file = home + '/.hpcloud/.hpcloud' unless File.file?(file) File.open(file, 'w') do |f| f.write('default:' + "\n") end end end def create_dir home = File.expand_path('~') path = home + '/.hpcloud' unless File.directory?(path) do Dir.mkdir(path) end end end def get_credentials_file home = File.expand_path('~') file = home + '/.hpcloud/.hpcloud' end def save_to_credentials_file(key, value) home = File.expand_path('~') file = home + '/.hpcloud/.hpcloud' File.open(file, 'a') do |f| f.write(' ' + key + ': ' + value + "\n") end end