Class: OneviewSDK::API200::User
- Defined in:
- lib/oneview-sdk/resource/api200/user.rb
Overview
User resource implementation
Direct Known Subclasses
OneviewSDK::API300::C7000::User, OneviewSDK::API300::Synergy::User
Constant Summary collapse
- BASE_URI =
'/rest/users'.freeze
- UNIQUE_IDENTIFIERS =
%w(userName uri).freeze
Constants inherited from Resource
Resource::DEFAULT_REQUEST_HEADER
Instance Attribute Summary
Attributes inherited from Resource
#api_version, #client, #data, #logger
Class Method Summary collapse
-
.validate_full_name(client, full_name) ⇒ Boolean
Checks for the existence of a user with the specified full name in the appliance.
-
.validate_user_name(client, user_name) ⇒ Boolean
Validates the existence of a user with the given user name in the appliance.
Instance Method Summary collapse
-
#create ⇒ Resource
Create the resource on OneView using the current data.
-
#initialize(client, params = {}, api_ver = nil) ⇒ User
constructor
Create a resource object, associate it with a client, and set its properties.
-
#set_roles(roles) ⇒ Resource
Set data and save to OneView.
-
#update(attributes = {}) ⇒ Resource
Set data and save to OneView.
Methods inherited from Resource
#==, #[], #[]=, build_query, #create!, #deep_merge!, #delete, #each, #eql?, #exists?, find_by, find_with_pagination, from_file, get_all, #like?, #refresh, #retrieve!, schema, #schema, #set, #set_all, #to_file
Constructor Details
#initialize(client, params = {}, api_ver = nil) ⇒ User
Create a resource object, associate it with a client, and set its properties.
25 26 27 28 29 30 31 |
# File 'lib/oneview-sdk/resource/api200/user.rb', line 25 def initialize(client, params = {}, api_ver = nil) super # Default values: @data['type'] ||= 'UserAndRoles' @data['enabled'] ||= true @data['roles'] ||= ['Read only'] end |
Class Method Details
.validate_full_name(client, full_name) ⇒ Boolean
Checks for the existence of a user with the specified full name in the appliance.
91 92 93 94 |
# File 'lib/oneview-sdk/resource/api200/user.rb', line 91 def self.validate_full_name(client, full_name) response = client.rest_post("#{BASE_URI}/validateUserName/#{full_name}") client.response_handler(response) end |
.validate_user_name(client, user_name) ⇒ Boolean
Validates the existence of a user with the given user name in the appliance.
82 83 84 85 |
# File 'lib/oneview-sdk/resource/api200/user.rb', line 82 def self.validate_user_name(client, user_name) response = client.rest_post("#{BASE_URI}/validateLoginName/#{user_name}") client.response_handler(response) end |
Instance Method Details
#create ⇒ Resource
Calls the refresh method to set additional data
Removes the password attribute after creation
Create the resource on OneView using the current data
39 40 41 42 43 44 45 46 |
# File 'lib/oneview-sdk/resource/api200/user.rb', line 39 def create ensure_client response = @client.rest_post(self.class::BASE_URI, { 'body' => @data }, @api_version) body = @client.response_handler(response) @data.delete('password') set_all(body) self end |
#set_roles(roles) ⇒ Resource
Set data and save to OneView
68 69 70 71 72 73 74 75 76 |
# File 'lib/oneview-sdk/resource/api200/user.rb', line 68 def set_roles(roles) ensure_client && ensure_uri data = roles.map { |r| { roleName: r, type: 'RoleNameDtoV2' } } response = @client.rest_put("#{@data['uri']}/roles?multiResource=true", { 'body' => data }, @api_version) r = @client.response_handler(response) new_roles = r.map { |i| i['roleName'] } set('roles', new_roles) self end |
#update(attributes = {}) ⇒ Resource
Set data and save to OneView
53 54 55 56 57 58 59 60 61 |
# File 'lib/oneview-sdk/resource/api200/user.rb', line 53 def update(attributes = {}) set_all(attributes) ensure_client && ensure_uri new_data = @data.select { |k, _v| k.to_s != 'roles' } # This cannot be updated here. It is updated below response = @client.rest_put(self.class::BASE_URI, { 'body' => new_data }, @api_version) d = @client.response_handler(response) set_roles(@data['roles']) if @data['roles'] && @data['roles'].sort != d['roles'].sort self end |