Class: LUSI::API::ServiceAccount
- Inherits:
-
Object
- Object
- LUSI::API::ServiceAccount
- Defined in:
- lib/lusi_api/service_account.rb
Overview
Represents a service account used to access the LUSI API
Constant Summary collapse
- PASSWORD_CHARS =
The characters used to generate a random service account password
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!-_=+,.'
Instance Attribute Summary collapse
-
#contact_email ⇒ String?
The email address of the service account owner.
-
#contact_name ⇒ String?
The full name of the service account owner.
-
#description ⇒ String?
The description of the service account.
-
#expiry_date ⇒ DateTime?
The expiry date of the service account password.
-
#institutions ⇒ Array<LUSI::API::Organisation::Unit>?
An array of institutions associated with this account.
-
#service_methods ⇒ Array<LUSI::API::ServiceMethod>?
An array of ServiceMethod instances callable from this account.
-
#username ⇒ String?
The service account username.
Class Method Summary collapse
-
.generate_service_account_password ⇒ String
Generates a 16-character random password for the service account.
-
.get_instance(api, lookup = nil) {|obj| ... } ⇒ Array<LUSI::API::ServiceAccount>
Return a ServiceAccount instance for the API’s service user.
-
.update_service_account_password(api, password = nil) ⇒ String
Sets a new password on the service account.
Instance Method Summary collapse
-
#initialize(xml = nil, lookup = nil, username: nil, description: nil, contact_name: nil, contact_email: nil, expiry_date: DateTime, institutions: nil, service_methods: nil) ⇒ void
constructor
Creates a new ServiceAccount instance Fields are extracted from the parsed XML response to the LUSI GetServiceAccountDetails API call.
-
#to_s ⇒ String
Returns a String representation of the ServiceAccount instance (the service username).
Constructor Details
#initialize(xml = nil, lookup = nil, username: nil, description: nil, contact_name: nil, contact_email: nil, expiry_date: DateTime, institutions: nil, service_methods: nil) ⇒ void
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.
73 74 75 76 77 78 79 80 81 82 |
# 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 |
Instance Attribute Details
#contact_email ⇒ String?
Returns the email address of the service account owner.
15 16 17 |
# File 'lib/lusi_api/service_account.rb', line 15 def contact_email @contact_email end |
#contact_name ⇒ String?
Returns the full name of the service account owner.
19 20 21 |
# File 'lib/lusi_api/service_account.rb', line 19 def contact_name @contact_name end |
#description ⇒ String?
Returns the description of the service account.
23 24 25 |
# File 'lib/lusi_api/service_account.rb', line 23 def description @description end |
#expiry_date ⇒ DateTime?
Returns the expiry date of the service account password.
27 28 29 |
# File 'lib/lusi_api/service_account.rb', line 27 def expiry_date @expiry_date end |
#institutions ⇒ Array<LUSI::API::Organisation::Unit>?
Returns an array of institutions associated with this account.
31 32 33 |
# File 'lib/lusi_api/service_account.rb', line 31 def institutions @institutions end |
#service_methods ⇒ Array<LUSI::API::ServiceMethod>?
Returns an array of ServiceMethod instances callable from this account.
35 36 37 |
# File 'lib/lusi_api/service_account.rb', line 35 def service_methods @service_methods end |
#username ⇒ String?
Returns the service account username.
39 40 41 |
# File 'lib/lusi_api/service_account.rb', line 39 def username @username end |
Class Method Details
.generate_service_account_password ⇒ String
Generates a 16-character random password for the service account
92 93 94 95 96 97 |
# 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 |
.get_instance(api, lookup = nil) {|obj| ... } ⇒ Array<LUSI::API::ServiceAccount>
Return a ServiceAccount instance for the API’s service user
51 52 53 54 55 56 57 58 |
# 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 |
.update_service_account_password(api, password = nil) ⇒ String
Sets a new password on the service account
104 105 106 107 108 109 110 111 112 113 114 115 |
# 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 |
Instance Method Details
#to_s ⇒ String
Returns a String representation of the ServiceAccount instance (the service username)
86 87 88 |
# File 'lib/lusi_api/service_account.rb', line 86 def to_s @username end |