class Origen::Users::User

Attributes

email[W]
name[W]
role[R]

Public Class Methods

current() click to toggle source
# File lib/origen/users/user.rb, line 17
def self.current
  Origen.current_user
end
current_user_id() click to toggle source
# File lib/origen/users/user.rb, line 13
def self.current_user_id
  `whoami`.strip
end
new(*args) click to toggle source
# File lib/origen/users/user.rb, line 21
def initialize(*args)
  if args.last.is_a?(Symbol)
    @role = args.pop
  else
    @role = :user
  end
  if args.size == 2
    @name = args.first
  end
  id = args.pop
  if id.to_s =~ /(.*)@/
    @email = id
    @id = Regexp.last_match(1)
  else
    @id = id
  end
end

Public Instance Methods

==(user) click to toggle source
Calls superclass method
# File lib/origen/users/user.rb, line 131
def ==(user)
  if user.is_a?(Origen::Users::User)
    user.id == id
  elsif user.is_a?(String)
    user.downcase == id
  else
    super
  end
end
admin?() click to toggle source

Returns true if the user is an admin for the current application

# File lib/origen/users/user.rb, line 59
def admin?
  role == :admin
end
auth_session() click to toggle source

Returns a private global Origen session store (stored in the user’s home directory and only readable by them). See - origen-sdk.org/origen/guides/misc/session/#Global_Sessions

# File lib/origen/users/user.rb, line 173
def auth_session
  @session ||= begin
    @session = Origen.session.user
    @session.private = true
    @session
  end
end
core_id(options = {})
Alias for: id
current?() click to toggle source

Returns true if the user is the current user

# File lib/origen/users/user.rb, line 64
def current?
  id.to_s.downcase == self.class.current_user_id
end
decrypt(text) click to toggle source
# File lib/origen/users/user.rb, line 208
def decrypt(text)
  text
end
display()
Alias for: raw
email(options = {}) click to toggle source
# File lib/origen/users/user.rb, line 82
def email(options = {})
  if current?
    @email ||= ENV['ORIGEN_EMAIL'] || ENV['ORIGEN_USER_EMAIL'] || email_from_rc || begin
      if Origen.site_config.email_domain
        "#{id}@#{Origen.site_config.email_domain}"
      end
    end
  else
    @email ||= if Origen.site_config.email_domain
                 "#{id}@#{Origen.site_config.email_domain}"
               end

  end
end
email_from_rc() click to toggle source
# File lib/origen/users/user.rb, line 97
def email_from_rc
  RevisionControl::Git.user_email
end
encrypt(text) click to toggle source
# File lib/origen/users/user.rb, line 212
def encrypt(text)
  text
end
id(options = {}) click to toggle source
# File lib/origen/users/user.rb, line 50
def id(options = {})
  # Way to force Origen to use the new user ID in case of WSL where the core ID might not match the WSL login name
  # User needs to setup the environment variable in their .bashrc or .tcshrc file
  ENV['ORIGEN_USER_ID'] || @id.to_s.downcase
end
Also aliased as: core_id, username
initials() click to toggle source

Returns the user’s initials in lower case

# File lib/origen/users/user.rb, line 69
def initials
  initials = name.split(/\s+/).map { |n| n[0].chr }.join('')
  initials.downcase
end
lookup(default = 'Unknown') { |data| ... } click to toggle source

Fetch user data from the FSL application directory

@example

User.new("r49409").lookup.motunixdomain   # => ["cde-tx32.sps.mot.com"]
# File lib/origen/users/user.rb, line 106
def lookup(default = 'Unknown')
  data = Origen.ldap.lookup(self)
  if block_given?
    if data
      yield data
    else
      default
    end
  else
    data
  end
end
method_missing(method, *args, &block) click to toggle source

Provides methods to access attributes available from LDAP

Calls superclass method
# File lib/origen/users/user.rb, line 142
def method_missing(method, *args, &block)
  l = Origen.ldap.lookup(self)
  if l
    if l.attribute_names.include?(method)
      l[method]
    else
      super
    end
  else
    super
  end
end
name() click to toggle source
# File lib/origen/users/user.rb, line 74
def name
  @name ||= ENV['ORIGEN_NAME'] || ENV['ORIGEN_USER_NAME'] || name_from_rc || @id
end
name_and_email() click to toggle source

Returns a string like “Stephen McGinty <stephen.mcginty@nxp.com>”

# File lib/origen/users/user.rb, line 166
def name_and_email
  "#{name} <#{email}>"
end
name_from_rc() click to toggle source
# File lib/origen/users/user.rb, line 78
def name_from_rc
  RevisionControl::Git.user_name
end
password(options = {}) click to toggle source

Returns the password for the current user. If the user hasn’t supplied it yet they will be prompted to enter it, it will then be stored

First, try in the global session, if its not defined, ask for it.

# File lib/origen/users/user.rb, line 185
def password(options = {})
  unless current?
    fail "You can only reference the password for the current user (#{self.class.current_user_id})!"
  end

  if options[:refresh]
    auth_session[:password] = nil
  end

  if auth_session[:password]
    password = decrypt(auth_session[:password])
  else
    puts 'Please enter your password:'
    password = (STDIN.noecho(&:gets) || '').chomp

    # TODO: Need some kind of callback here to optionally verify password correctness via LDAP or similar

    auth_session[:password] = encrypt(password)
  end

  password
end
raw() click to toggle source

Prints all raw data available on the given user from the FSL application directory.

Most of the useful data is already exposed through the available user methods, but if you want to get any of these parameters they can be fetched via the lookup method.

# File lib/origen/users/user.rb, line 125
def raw
  Origen.ldap.display(self)
  nil
end
Also aliased as: display
respond_to?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/origen/users/user.rb, line 155
def respond_to?(method, include_private = false)
  super || begin
    if Origen.ldap.available?
      Origen.ldap.lookup(self) && Origen.ldap.lookup(self).attribute_names.include?(method.to_sym)
    else
      false
    end
  end
end
send(options) click to toggle source

Send the user an email

@example

User.current.send subject: "Complete", message: "Your job is done!"
User.new("r49409").send subject: "Complete", message: "Your job is done!"
# File lib/origen/users/user.rb, line 44
def send(options)
  options[:body] ||= options[:message]
  options[:to] = self
  Origen.mailer.send_email(options)
end
username(options = {})
Alias for: id