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.
-
.code ⇒ Object
Returns the value of attribute code.
-
.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, password, code = nil, auth = true) ⇒ Cloud
constructor
A new instance of Cloud.
-
#inspect ⇒ Object
hide secret fields from being displayed in 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, password, code = nil, auth = true) ⇒ Cloud
Returns a new instance of Cloud.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lmc/Cloud.rb', line 22 def initialize(cloud_host, user, password, code = nil, auth = true) @auth_ok = false @cloud_host = cloud_host @user = user @password = password @code = code @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 login 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 |
.code ⇒ Object
Returns the value of attribute code.
10 11 12 |
# File 'lib/lmc/Cloud.rb', line 10 def code @code 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.
20 21 22 |
# File 'lib/lmc/Cloud.rb', line 20 def auth_ok @auth_ok end |
#cloud_host ⇒ Object (readonly)
Returns the value of attribute cloud_host.
20 21 22 |
# File 'lib/lmc/Cloud.rb', line 20 def cloud_host @cloud_host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
20 21 22 |
# File 'lib/lmc/Cloud.rb', line 20 def password @password end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
20 21 22 |
# File 'lib/lmc/Cloud.rb', line 20 def user @user end |
Class Method Details
.instance(opts = { authorize: true }) ⇒ Object
16 17 18 |
# File 'lib/lmc/Cloud.rb', line 16 def self.instance(opts = { authorize: true }) @@inst ||= new(@cloud_host, @user, @password, @code, opts[:authorize]) end |
Instance Method Details
#accept_tos(tos) ⇒ Object
142 143 144 |
# File 'lib/lmc/Cloud.rb', line 142 def accept_tos(tos) ([], tos) end |
#auth_for_account(account) ⇒ Object
138 139 140 |
# File 'lib/lmc/Cloud.rb', line 138 def auth_for_account(account) ([account]) end |
#auth_for_accounts(accounts) ⇒ Object
134 135 136 |
# File 'lib/lmc/Cloud.rb', line 134 def auth_for_accounts(accounts) (accounts) end |
#build_url(*path_components) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/lmc/Cloud.rb', line 126 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
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/lmc/Cloud.rb', line 108 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
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/lmc/Cloud.rb', line 73 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
45 46 47 |
# File 'lib/lmc/Cloud.rb', line 45 def get_accounts get 'cloud-service-auth/accounts' end |
#get_accounts_objects ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lmc/Cloud.rb', line 49 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
41 42 43 |
# File 'lib/lmc/Cloud.rb', line 41 def get_backstage_serviceinfos get 'cloud-service-backstage/serviceinfos' end |
#inspect ⇒ Object
hide secret fields from being displayed in dumps
37 38 39 |
# File 'lib/lmc/Cloud.rb', line 37 def inspect "#<Cloud:#{object_id}, #{build_url}>" end |
#invite_user_to_account(email, account_id, type, authorities = []) ⇒ Object
62 63 64 65 66 |
# File 'lib/lmc/Cloud.rb', line 62 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
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/lmc/Cloud.rb', line 96 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
69 70 71 |
# File 'lib/lmc/Cloud.rb', line 69 def preferences(section) LMC::Preferences.new cloud: self, section: section end |
#put(path, body_object, params = nil) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/lmc/Cloud.rb', line 84 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
122 123 124 |
# File 'lib/lmc/Cloud.rb', line 122 def session_token @auth_token['value'] end |