Module: Amp::Servers::RepoUserManagement::Memory

Defined in:
lib/amp/server/repo_user_management.rb

Instance Method Summary collapse

Instance Method Details

#add_user(user_info = {}) ⇒ Object Also known as: <<

Adds a user to the system. This is not repository specific.

Parameters:

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

    The user data, in hash form. Passed to User.from_hash

Options Hash (user_info):

  • :username (String)

    The username for the user

  • :password (String)

    The cleartext (unencrypted) password.



25
26
27
28
# File 'lib/amp/server/repo_user_management.rb', line 25

def add_user(={})
  new_user = User.from_hash 
  users[new_user.username] = new_user # universal list of users
end

#reposObject

All the repositories stored in a hash.

:private => Boolean}

Examples:

repos = {:users => {String => {:user => Amp::Servers::User,

:read => Boolean, :write => Boolean}},


15
# File 'lib/amp/server/repo_user_management.rb', line 15

def repos; @repos ||= {}; @repos.default = {}; @repos; end

#set_private(repository, _private = true) ⇒ Object

Sets the given repository’s privacy levels. Repositories default to being public, and must be set to be private using this method. This method can also be used to later make a private repository public without stopping the server.

Parameters:

  • repository (Repository)

    The repository for which to set privacy settings

  • _private (Boolean) (defaults to: true)

    (true) whether the repository should be private or not



67
68
69
# File 'lib/amp/server/repo_user_management.rb', line 67

def set_private(repository, _private=true)
  repos[repository][:private] = !!_private
end

#set_reader(repository, user) ⇒ Object

Adds a given username/password combination to the system, for a given repository, with read-only privileges. This will override any other settings previously set. For example, a call to #set_writer and then #set_reader would be as though #set_writer never happened.

Parameters:

  • repository (Repository)

    The repository to which are associating the user

  • user (Amp::Servers::User)

    The user to give write priveleges to



53
54
55
56
57
58
# File 'lib/amp/server/repo_user_management.rb', line 53

def set_reader(repository, user)
  repos[repository] ||= {:users => {}, :private => false}
  repos[repository][:users][user.username] ||= {:user => user, :read => true, :write => false}
  repos[repository][:users][user.username][:read]  = true
  repos[repository][:users][user.username][:write] = false
end

#set_writer(repository, user) ⇒ Object

Adds a given username/password combination to the system, for a given repository, with write privileges.

Parameters:

  • repository (Repository)

    The repository to which are associating the user

  • user (Amp::Servers::User)

    The user to give write priveleges to



38
39
40
41
42
43
# File 'lib/amp/server/repo_user_management.rb', line 38

def set_writer(repository, user)
  repos[repository] ||= {:users => {}, :private => false}
  repos[repository][:users][user.username] ||= {:user => user, :read => true, :write => true}
  repos[repository][:users][user.username][:read]  = true # these are unnecessary if we are adding a user
  repos[repository][:users][user.username][:write] = true
end

#usersObject



17
# File 'lib/amp/server/repo_user_management.rb', line 17

def users; @users ||= {}; end