Module: ViprBase
- Included in:
- Vipr
- Defined in:
- lib/vipruby/viprbase.rb
Overview
Base methods used for all operations such as logging in and performing API calls
Instance Method Summary collapse
-
#generate_base_url(ip_or_fqdn) ⇒ strong
Generate the URL for standard ViPR instances using https: and port :443.
-
#get_auth_token(user_name, password, cert = nil, base = nil) ⇒ String
Get User’s Authentication Token.
-
#get_tenant_uid(base = nil, auth = nil, cert = nil) ⇒ Hash
Get the current users Tenant UID.
-
#login(user_name, password, cert = nil, base = nil) ⇒ HTML
Login to ViPR.
-
#rest_get(api_url, auth = nil, cert = nil) ⇒ Hash
Generic API get call.
-
#rest_post(payload, api_url, auth = nil, cert = nil) ⇒ Hash
Generic API post call.
-
#to_boolean(str) ⇒ bool
Ensure value is a boolean.
Instance Method Details
#generate_base_url(ip_or_fqdn) ⇒ strong
Generate the URL for standard ViPR instances using https: and port :443
63 64 65 |
# File 'lib/vipruby/viprbase.rb', line 63 def generate_base_url(ip_or_fqdn) return "https://#{ip_or_fqdn}:4443" end |
#get_auth_token(user_name, password, cert = nil, base = nil) ⇒ String
Get User’s Authentication Token
72 73 74 |
# File 'lib/vipruby/viprbase.rb', line 72 def get_auth_token(user_name,password, cert=nil, base=nil) login(user_name, password, cert.nil? ? @verify_cert : cert, base.nil? ? @base_url : base).headers[:x_sds_auth_token] end |
#get_tenant_uid(base = nil, auth = nil, cert = nil) ⇒ Hash
Get the current users Tenant UID
41 42 43 |
# File 'lib/vipruby/viprbase.rb', line 41 def get_tenant_uid(base=nil, auth=nil, cert=nil) rest_get(base.nil? ? @base_url + "/tenant" : base + "/tenant", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert) end |
#login(user_name, password, cert = nil, base = nil) ⇒ HTML
Login to ViPR
50 51 52 53 54 55 56 57 |
# File 'lib/vipruby/viprbase.rb', line 50 def login(user_name, password, cert=nil, base=nil) RestClient::Request.execute(method: :get, url: base.nil? ? @base_url : base + "/login", user: user_name, password: password, verify_ssl: cert.nil? ? @verify_cert : cert ) end |
#rest_get(api_url, auth = nil, cert = nil) ⇒ Hash
Generic API get call
28 29 30 31 32 33 34 35 36 |
# File 'lib/vipruby/viprbase.rb', line 28 def rest_get(api_url, auth=nil, cert=nil) JSON.parse(RestClient::Request.execute(method: :get, url: api_url, verify_ssl: cert.nil? ? @verify_cert : cert, headers: { :'X-SDS-AUTH-TOKEN' => auth.nil? ? @auth_token : auth, accept: :json })) end |
#rest_post(payload, api_url, auth = nil, cert = nil) ⇒ Hash
Generic API post call
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vipruby/viprbase.rb', line 12 def rest_post(payload, api_url, auth=nil, cert=nil) JSON.parse(RestClient::Request.execute(method: :post, url: api_url, verify_ssl: cert.nil? ? @verify_cert : cert, payload: payload, headers: { :'X-SDS-AUTH-TOKEN' => auth.nil? ? @auth_token : auth, content_type: 'application/json', accept: :json })) end |
#to_boolean(str) ⇒ bool
Ensure value is a boolean
80 81 82 |
# File 'lib/vipruby/viprbase.rb', line 80 def to_boolean(str) str.to_s.downcase == "true" end |