class LUSI::API::ServiceAccount
Constants
- PASSWORD_CHARS
The characters used to generate a random service account password
Attributes
@!attribute [rw] contact_email
@return [String, nil] the email address of the service account owner
@!attribute [rw] contact_name
@return [String, nil] the full name of the service account owner
@!attribute [rw] description
@return [String, nil] the description of the service account
@!attribute [rw] expiry_date
@return [DateTime, nil] the expiry date of the service account password
@!attribute [rw] institutions
@return [Array<LUSI::API::Organisation::Unit>, nil] an array of institutions associated with this account
@!attribute [rw] service_methods
@return [Array<LUSI::API::ServiceMethod>, nil] an array of ServiceMethod instances callable from this account
@!attribute [rw] username
@return [String, nil] the service account username
Public Class Methods
Generates a 16-character random password for the service account @return [String] the generated password
# File lib/lusi_api/service_account.rb, line 92 def self.generate_service_account_password password = [] random = Random::new (0..16).each { |i| password.push(PASSWORD_CHARS[random.rand(PASSWORD_CHARS.length)]) } password.join('') end
Return a ServiceAccount
instance for the API's service user @param api [LUSI::API::Core::API] the LUSI
API
instance @param lookup [LUSI::API::Core::Lookup::LookupService, nil] the lookup service for object resolution @return [Array<LUSI::API::ServiceAccount>] a list containing the ServiceAccount
for the API's service user @yield [obj] Passes the ServiceAccount
instance to the block @yieldparam obj [LUSI::API::ServiceAccount] the ServiceAccount
instance @raise [LUSI::API::Core::APIError] if the API
call fails
# File lib/lusi_api/service_account.rb, line 51 def self.get_instance(api, lookup = nil) xml = api.call('LUSIReference', 'General.asmx', 'GetServiceAccountDetails') LUSI::API::Core::XML::xml(xml, 'xmlns:ServiceAccount') do |s| obj = LUSI::API::ServiceAccount.new(s, lookup) yield(obj) if block_given? obj end end
Creates a new ServiceAccount
instance Fields are extracted from the parsed XML response to the LUSI
GetServiceAccountDetails API
call. Default values for fields missing from the XML can be specified as keyword arguments. @param xml [Nokogiri::XML::Node, nil] the XML response from the LUSI
GetServiceAccountDetails API
call, or nil @param lookup [LUSI::API::Core::Lookup::LookupService, nil] the lookup service for object resolution @param username [String, nil] the default username @param description [String, nil] the default description @param contact_name
[String, nil] the default contact name @param contact_email
[Stirng, nil] the default contact email @param expiry_date
[DateTime, nil] the default expiry date @param institutions [Array<LUSI::API::Institution>] the default institution list @param service_methods
[Array<LUSI::API::ServiceMethod>] the default service method list @return [void]
# File lib/lusi_api/service_account.rb, line 73 def initialize(xml = nil, lookup = nil, username: nil, description: nil, contact_name: nil, contact_email: nil, expiry_date: DateTime, institutions: nil, service_methods: nil) @contact_email = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:ContactEmail', contact_email) @contact_name = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:ContactName', contact_name) @description = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Description', description) @expiry_date = LUSI::API::Core::XML.xml_datetime_at(xml, 'xmlns:ExpiryDate', expiry_date) @institutions = LUSI::API::Core::XML.xml(xml, 'xmlns:Institutions', institutions).map { |i| LUSI::API::Core::XML.lookup(i, lookup, :institution, 'xmlns:Institution') } @service_methods = LUSI::API::Core::XML.xml(xml, 'xmlns:ServiceMethods/xmlns:ServiceMethod', service_methods).map { |m| LUSI::API::ServiceMethod.new(m, lookup) } @username = LUSI::API::Core::XML.xml_content_at('xmlns:Username') end
Sets a new password on the service account @param api [LUSI::API::Core::API] the LUSI
API
configured with the service account to be updated @param password [String, nil] the new password (if nil, a 16-digit random password will be generated) @return [String] the new password @raise [LUSI::API::Core::APIError] if the LUSI
API
call fails
# File lib/lusi_api/service_account.rb, line 104 def self.update_service_account_password(api, password = nil) # Generate a password if required password ||= generate_service_account_password # Update the password xml = api.call('LUSIReference', 'General.asmx', 'UpdateServiceAccountPassword', NewPassword: password) # Return the new password password end
Public Instance Methods
Returns a String representation of the ServiceAccount
instance (the service username) @return [String] the string representation of the ServiceAccount
instance
# File lib/lusi_api/service_account.rb, line 86 def to_s @username end