Module: Qtc::Cli::Common
- Included in:
- Eds::Base, Mar::Base, Platform::Clouds, Platform::SshKeys, Platform::User
- Defined in:
- lib/qtc/cli/common.rb
Instance Method Summary collapse
- #base_url ⇒ Object
- #client ⇒ Qtc::Client
- #extract_app_in_dir(remote = nil) ⇒ String
- #ini_filename ⇒ Object
- #inifile ⇒ Object
- #instance_info(instance_id) ⇒ Object
- #platform_base_url ⇒ Object
- #platform_client(token = nil) ⇒ Object
Instance Method Details
#base_url ⇒ Object
84 85 86 |
# File 'lib/qtc/cli/common.rb', line 84 def base_url ENV['QTC_MAR_URL'] || 'https://mar-eu-1.qtc.io/v1' end |
#client ⇒ Qtc::Client
76 77 78 79 80 81 82 |
# File 'lib/qtc/cli/common.rb', line 76 def client if @client.nil? @client = Qtc::Client.new(base_url) end @client end |
#extract_app_in_dir(remote = nil) ⇒ String
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/qtc/cli/common.rb', line 56 def extract_app_in_dir(remote = nil) if File.exists?(File.('./.git/config')) remotes = [] git_remotes = `git remote -v` git_remotes.lines.each do |line| if match = line.match(/#{remote}\s+git@git-mar-(.*)\:(.*) \(push\)/) remotes << match[2] end end apps = remotes.uniq if apps.size == 1 return apps[0] elsif apps.size > 1 raise ArgumentError.new("Multiple app git remotes\nSpecify app with --remote REMOTE or --app APP") end end end |
#ini_filename ⇒ Object
33 34 35 |
# File 'lib/qtc/cli/common.rb', line 33 def ini_filename File.join(Dir.home, '/.qtc_client') end |
#inifile ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/qtc/cli/common.rb', line 37 def inifile if @inifile.nil? if File.exists?(ini_filename) @inifile = IniFile.load(ini_filename) else @inifile = IniFile.new end end unless @inifile['platform'] @inifile['platform'] = {} end @inifile end |
#instance_info(instance_id) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/qtc/cli/common.rb', line 6 def instance_info(instance_id) instance_data = platform_client.get("/instances/#{instance_id}") if instance_data response = platform_client.get("/instances/#{instance_id}/authorizations") if response['results'] instance_data['authorizations'] = response['results'] end else abort("Error: instance not found") end instance_data end |
#platform_base_url ⇒ Object
88 89 90 |
# File 'lib/qtc/cli/common.rb', line 88 def platform_base_url ENV['QTC_PLATFORM_URL'] || 'https://api.qtc.io/v1' end |
#platform_client(token = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/qtc/cli/common.rb', line 20 def platform_client(token = nil) inifile['platform']['token'] = token unless token.nil? unless inifile['platform']['token'] raise ArgumentError.new("Please login first using: qtc-cli login") end if @platform_client.nil? @platform_client = Qtc::Client.new(platform_base_url, {'Authorization' => "Bearer #{inifile['platform']['token']}"}) end @platform_client end |