Class: Amp::Servers::User

Inherits:
Struct
  • Object
show all
Defined in:
lib/amp/server/amp_user.rb

Overview

User

A single user within an Amp’s server system. Just a simple struct - though they do offer a convenient constructor, taking a hash.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password

Returns:

  • (Object)

    the current value of password



8
9
10
# File 'lib/amp/server/amp_user.rb', line 8

def password
  @password
end

#usernameObject

Returns the value of attribute username

Returns:

  • (Object)

    the current value of username



8
9
10
# File 'lib/amp/server/amp_user.rb', line 8

def username
  @username
end

Class Method Details

.from_hash(input = {}) ⇒ Object

Extra constructor - takes a hash to create a new User, instead of the Struct class’s ordered parameters for its constructor.

Parameters:

  • input (Hash) (defaults to: {})

    the hash representing the values for the struct

Options Hash (input):

  • :username (String)

    The username for the user

  • :password (String)

    The cleartext (unencrypted) password.

  • :can_read (String)

    Can the user read the repository?

  • :can_write (String)

    Can the user write to the repository?

Raises:

  • (RuntimeError)

    raised if the user doesn’t supply :password or :password_hashed



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/amp/server/amp_user.rb', line 28

def self.from_hash(input={})
  # input checking
  unless input[:password]
    raise "User must have a password attribute"
  end
  
  # public is reserved as the username of the public user
  if input[:username].to_s == 'public'
    raise "User cannot have username 'public' -- reserved by Amp system"
  end
  
  new input[:username], input[:password]
end

.public_userUser

Generates a public user - i.e., somebody who has been granted no explicit rights.

Returns:

  • (User)

    a public user with no explicit rights



13
14
15
# File 'lib/amp/server/amp_user.rb', line 13

def self.public_user
  @@public_user ||= new('public', "")
end