Class: Bosh::Director::Api::DatabaseUserManager

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/api/user/database_user_manager.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(username, password) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bosh/director/api/user/database_user_manager.rb', line 10

def authenticate(username, password)
  # This is a dev-mode shortcut
  if Models::User.count == 0
    return username == "admin" && password == "admin"
  end

  user = find_by_name(username)
  BCrypt::Password.new(user.password) == password
rescue UserNotFound
  false
end

#create_user(new_user) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/bosh/director/api/user/database_user_manager.rb', line 26

def create_user(new_user)
  user = Models::User.new
  user.username = new_user.username
  if new_user.password
    user.password = BCrypt::Password.create(new_user.password).to_s
  end
  save_user(user)
  user
end

#delete_user(username) ⇒ Object



22
23
24
# File 'lib/bosh/director/api/user/database_user_manager.rb', line 22

def delete_user(username)
  find_by_name(username).destroy
end

#get_user_from_json(json_user) ⇒ Object



43
44
45
46
47
# File 'lib/bosh/director/api/user/database_user_manager.rb', line 43

def get_user_from_json(json_user)
  hash = JSON.parse(json_user)
  Models::User.new(:username => hash["username"],
    :password => hash["password"])
end

#supports_api_update?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/bosh/director/api/user/database_user_manager.rb', line 6

def supports_api_update?
  true
end

#update_user(updated_user) ⇒ Object



36
37
38
39
40
41
# File 'lib/bosh/director/api/user/database_user_manager.rb', line 36

def update_user(updated_user)
  user = find_by_name(updated_user.username)
  user.password = BCrypt::Password.create(updated_user.password).to_s
  save_user(user)
  user
end