class OneviewSDK::API200::User
User
resource implementation
Constants
- BASE_URI
- UNIQUE_IDENTIFIERS
Public Class Methods
Create a resource object, associate it with a client, and set its properties. @param [OneviewSDK::Client] client The client object for the OneView appliance @param [Hash] params The options for this resource (key-value pairs) @param [Integer] api_ver The api version to use when interracting with this resource.
OneviewSDK::Resource::new
# 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
Checks for the existence of a user with the specified full name in the appliance. @param [OneviewSDK::Client] client The client object for the OneView appliance @param [String] full_name The full name to validate @return [Boolean] return true if the user already exists
# File lib/oneview-sdk/resource/api200/user.rb, line 92 def self.validate_full_name(client, full_name) response = client.rest_post("#{BASE_URI}/validateUserName/#{full_name}") client.response_handler(response) end
Validates the existence of a user with the given user name in the appliance. @param [OneviewSDK::Client] client The client object for the OneView appliance @param [String] user_name The user name to validate @return [Boolean] return true if the user already exists
# File lib/oneview-sdk/resource/api200/user.rb, line 83 def self.validate_user_name(client, user_name) response = client.rest_post("#{BASE_URI}/validateLoginName/#{user_name}") client.response_handler(response) end
Public Instance Methods
Create the resource on OneView using the current data @note Calls the refresh method to set additional data @note Removes the password attribute after creation @param [Hash] header The header options for the request (key-value pairs) @raise [OneviewSDK::IncompleteResource] if the client is not set @raise [StandardError] if the resource creation fails @return [Resource] self
# File lib/oneview-sdk/resource/api200/user.rb, line 40 def create(header = {}) ensure_client response = @client.rest_post(BASE_URI, DEFAULT_REQUEST_HEADER.merge(header).merge('body' => @data), @api_version) body = @client.response_handler(response) @data.delete('password') set_all(body) self end
Set data and save to OneView @param [Array] roles The names of the roles to set for this user @raise [OneviewSDK::IncompleteResource] if the client or uri is not set @raise [StandardError] if setting the role fails @return [Resource] self
# File lib/oneview-sdk/resource/api200/user.rb, line 69 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
Set data and save to OneView @param [Hash] attributes The attributes to add/change for this resource (key-value pairs) @raise [OneviewSDK::IncompleteResource] if the client or uri is not set @raise [StandardError] if the resource save fails @return [Resource] self
# File lib/oneview-sdk/resource/api200/user.rb, line 54 def update(attributes = {}) set_all(attributes) ensure_client && ensure_uri new_data = @data.reject { |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