Class: LMC::Cloud
- Inherits:
-
Object
- Object
- LMC::Cloud
- Defined in:
- lib/lmc/Cloud.rb
Class Attribute Summary collapse
-
.cloud_host ⇒ Object
Returns the value of attribute cloud_host.
-
.debug ⇒ Object
Returns the value of attribute debug.
-
.password ⇒ Object
Returns the value of attribute password.
-
.use_tls ⇒ Object
Returns the value of attribute use_tls.
-
.user ⇒ Object
Returns the value of attribute user.
-
.verbose ⇒ Object
Returns the value of attribute verbose.
-
.verify_tls ⇒ Object
Returns the value of attribute verify_tls.
Instance Attribute Summary collapse
-
#auth_ok ⇒ Object
readonly
Returns the value of attribute auth_ok.
-
#cloud_host ⇒ Object
readonly
Returns the value of attribute cloud_host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #accept_tos(tos) ⇒ Object
- #auth_for_account(account) ⇒ Object
- #auth_for_accounts(accounts) ⇒ Object
- #build_url(*path_components) ⇒ Object
- #delete(path, params = nil) ⇒ Object
- #get(path, params = nil) ⇒ Object
- #get_accounts ⇒ Object
- #get_accounts_objects ⇒ Object
- #get_backstage_serviceinfos ⇒ Object
-
#initialize(cloud_host, user, pass, auth = true) ⇒ Cloud
constructor
A new instance of Cloud.
-
#inspect ⇒ Object
hide password from dumps.
- #invite_user_to_account(email, account_id, type, authorities = []) ⇒ Object
- #post(path, body_object, params = nil) ⇒ Object
- #preferences(section) ⇒ Object
- #put(path, body_object, params = nil) ⇒ Object
-
#session_token ⇒ Object
public accessors.
Constructor Details
#initialize(cloud_host, user, pass, auth = true) ⇒ Cloud
Returns a new instance of Cloud.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lmc/Cloud.rb', line 21 def initialize(cloud_host, user, pass, auth = true) @auth_ok = false @cloud_host = cloud_host @user = user @password = pass @verify_tls = Cloud.verify_tls @last_authorized_account_ids = nil @logger ||= ::LMC::Logger.new(STDOUT) if Cloud.debug @logger.cloud = self if Cloud.debug RestClient.log = @logger if Cloud.debug if auth end |
Class Attribute Details
.cloud_host ⇒ Object
Returns the value of attribute cloud_host.
10 11 12 |
# File 'lib/lmc/Cloud.rb', line 10 def cloud_host @cloud_host end |
.debug ⇒ Object
Returns the value of attribute debug.
10 11 12 |
# File 'lib/lmc/Cloud.rb', line 10 def debug @debug end |
.password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/lmc/Cloud.rb', line 10 def password @password end |
.use_tls ⇒ Object
Returns the value of attribute use_tls.
10 11 12 |
# File 'lib/lmc/Cloud.rb', line 10 def use_tls @use_tls end |
.user ⇒ Object
Returns the value of attribute user.
10 11 12 |
# File 'lib/lmc/Cloud.rb', line 10 def user @user end |
.verbose ⇒ Object
Returns the value of attribute verbose.
10 11 12 |
# File 'lib/lmc/Cloud.rb', line 10 def verbose @verbose end |
.verify_tls ⇒ Object
Returns the value of attribute verify_tls.
10 11 12 |
# File 'lib/lmc/Cloud.rb', line 10 def verify_tls @verify_tls end |
Instance Attribute Details
#auth_ok ⇒ Object (readonly)
Returns the value of attribute auth_ok.
19 20 21 |
# File 'lib/lmc/Cloud.rb', line 19 def auth_ok @auth_ok end |
#cloud_host ⇒ Object (readonly)
Returns the value of attribute cloud_host.
19 20 21 |
# File 'lib/lmc/Cloud.rb', line 19 def cloud_host @cloud_host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
19 20 21 |
# File 'lib/lmc/Cloud.rb', line 19 def password @password end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
19 20 21 |
# File 'lib/lmc/Cloud.rb', line 19 def user @user end |
Class Method Details
.instance(opts = { authorize: true }) ⇒ Object
15 16 17 |
# File 'lib/lmc/Cloud.rb', line 15 def self.instance(opts = { authorize: true }) @@inst ||= new(@cloud_host, @user, @password, opts[:authorize]) end |
Instance Method Details
#accept_tos(tos) ⇒ Object
140 141 142 |
# File 'lib/lmc/Cloud.rb', line 140 def accept_tos(tos) ([], tos) end |
#auth_for_account(account) ⇒ Object
136 137 138 |
# File 'lib/lmc/Cloud.rb', line 136 def auth_for_account(account) ([account]) end |
#auth_for_accounts(accounts) ⇒ Object
132 133 134 |
# File 'lib/lmc/Cloud.rb', line 132 def auth_for_accounts(accounts) (accounts) end |
#build_url(*path_components) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/lmc/Cloud.rb', line 124 def build_url(*path_components) protocol = 'https' if !Cloud.use_tls protocol = 'http' end ["#{protocol}://#{@cloud_host}", path_components].flatten.compact.join('/') end |
#delete(path, params = nil) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/lmc/Cloud.rb', line 106 def delete(path, params = nil) prepared_headers = headers prepared_headers[:params] = params args = { :method => :delete, :url => build_url(path), :headers => prepared_headers } execute_request args end |
#get(path, params = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/lmc/Cloud.rb', line 71 def get(path, params = nil) prepared_headers = headers prepared_headers[:params] = params args = { :method => :get, :url => build_url(path), :headers => prepared_headers } execute_request args end |
#get_accounts ⇒ Object
43 44 45 |
# File 'lib/lmc/Cloud.rb', line 43 def get_accounts get 'cloud-service-auth/accounts' end |
#get_accounts_objects ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lmc/Cloud.rb', line 47 def get_accounts_objects result = get ['cloud-service-auth', 'accounts'] if result.code == 200 accounts = result.map do |aj| Account.new(self, aj) end else raise "Unable to fetch accounts: #{result.body.}" end accounts end |
#get_backstage_serviceinfos ⇒ Object
39 40 41 |
# File 'lib/lmc/Cloud.rb', line 39 def get_backstage_serviceinfos get 'cloud-service-backstage/serviceinfos' end |
#inspect ⇒ Object
hide password from dumps
35 36 37 |
# File 'lib/lmc/Cloud.rb', line 35 def inspect "#<Cloud:#{object_id}, #{build_url}>" end |
#invite_user_to_account(email, account_id, type, authorities = []) ⇒ Object
60 61 62 63 64 |
# File 'lib/lmc/Cloud.rb', line 60 def invite_user_to_account(email, account_id, type, = []) body = { name: email, state: 'ACTIVE', type: type } body['authorities'] = post ['cloud-service-auth', 'accounts', account_id, 'members'], body end |
#post(path, body_object, params = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/lmc/Cloud.rb', line 94 def post(path, body_object, params=nil ) prepared_headers = headers prepared_headers[:params] = params args = { :method => :post, :url => build_url(path), :payload => body_object.to_json, :headers => prepared_headers } execute_request args end |
#preferences(section) ⇒ Object
67 68 69 |
# File 'lib/lmc/Cloud.rb', line 67 def preferences(section) LMC::Preferences.new cloud: self, section: section end |
#put(path, body_object, params = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/lmc/Cloud.rb', line 82 def put(path, body_object, params = nil) prepared_headers = headers prepared_headers[:params] = params args = { :method => :put, :url => build_url(path), :payload => body_object.to_json, :headers => prepared_headers } execute_request args end |
#session_token ⇒ Object
public accessors
120 121 122 |
# File 'lib/lmc/Cloud.rb', line 120 def session_token @auth_token['value'] end |