Class: Couchbase::Management::UserManager

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/management/user_manager.rb,
/code/couchbase-ruby-client/lib/couchbase/management/user_manager.rb

Defined Under Namespace

Classes: ChangePasswordOptions, DropGroupOptions, DropUserOptions, GetAllGroupsOptions, GetAllUsersOptions, GetGroupOptions, GetRolesOptions, GetUserOptions, UpsertGroupOptions, UpsertUserOptions

Instance Method Summary collapse

Constructor Details

#initialize(backend) ⇒ UserManager

Returns a new instance of UserManager.

Parameters:

  • backend (Couchbase::Backend)


27
28
29
# File 'lib/couchbase/management/user_manager.rb', line 27

def initialize(backend)
  @backend = backend
end

Instance Method Details

#change_password(new_password, options = ChangePasswordOptions.new) ⇒ Object

Changes the password of the currently authenticated user

Parameters:

Raises:

  • (ArgumentError)


111
112
113
# File 'lib/couchbase/management/user_manager.rb', line 111

def change_password(new_password, options = ChangePasswordOptions.new)
  @backend.change_password(new_password, options.timeout)
end

#drop_group(group_name, options = DropGroupOptions.new) ⇒ Object

Removes a group

Parameters:

  • group_name (String)

    name of the group

  • options (DropGroupOptions) (defaults to: DropGroupOptions.new)

Raises:



167
168
169
# File 'lib/couchbase/management/user_manager.rb', line 167

def drop_group(group_name, options = DropGroupOptions.new)
  @backend.group_drop(group_name, options.timeout)
end

#drop_user(username, options = DropUserOptions.new) ⇒ Object

Removes a user

Parameters:

  • username (String)

    ID of the user

  • options (DropUserOptions) (defaults to: DropUserOptions.new)


83
84
85
# File 'lib/couchbase/management/user_manager.rb', line 83

def drop_user(username, options = DropUserOptions.new)
  @backend.user_drop(options.domain, username, options.timeout)
end

#get_all_groups(options = GetAllGroupsOptions.new) ⇒ Array<Group>

Gets all groups

Parameters:

Returns:



133
134
135
136
# File 'lib/couchbase/management/user_manager.rb', line 133

def get_all_groups(options = GetAllGroupsOptions.new)
  resp = @backend.group_get_all(options.timeout)
  resp.map { |entry| extract_group(entry) }
end

#get_all_users(options = GetAllUsersOptions.new) ⇒ Array<UserAndMetadata>

Gets all users

Returns:



48
49
50
51
# File 'lib/couchbase/management/user_manager.rb', line 48

def get_all_users(options = GetAllUsersOptions.new)
  resp = @backend.user_get_all(options.domain, options.timeout)
  resp.map { |entry| extract_user(entry) }
end

#get_group(group_name, options = GetGroupOptions.new) ⇒ Group

Gets a group

Parameters:

  • group_name (String)

    name of the group to get

Returns:

Raises:



123
124
125
126
# File 'lib/couchbase/management/user_manager.rb', line 123

def get_group(group_name, options = GetGroupOptions.new)
  resp = @backend.group_get(group_name, options.timeout)
  extract_group(resp)
end

#get_roles(options = GetRolesOptions.new) ⇒ Array<RoleAndDescription>

Gets all roles supported by the server

Parameters:

Returns:



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/couchbase/management/user_manager.rb', line 92

def get_roles(options = GetRolesOptions.new)
  resp = @backend.role_get_all(options.timeout)
  resp.map do |r|
    RoleAndDescription.new do |role|
      role.name = r[:name]
      role.display_name = r[:display_name]
      role.description = r[:description]
      role.bucket = r[:bucket]
      role.scope = r[:scope]
      role.collection = r[:collection]
    end
  end
end

#get_user(username, options = GetUserOptions.new) ⇒ UserAndMetadata

Get a user

Parameters:

  • username (String)

    ID of the user

  • options (GetUserOptions) (defaults to: GetUserOptions.new)

Returns:

Raises:



40
41
42
43
# File 'lib/couchbase/management/user_manager.rb', line 40

def get_user(username, options = GetUserOptions.new)
  resp = @backend.user_get(options.domain, username, options.timeout)
  extract_user(resp)
end

#upsert_group(group, options = UpsertGroupOptions.new) ⇒ Object

Creates or updates a group

Parameters:

  • group (Group)

    the new version of the group

  • options (UpsertGroupOptions) (defaults to: UpsertGroupOptions.new)

Raises:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/couchbase/management/user_manager.rb', line 145

def upsert_group(group, options = UpsertGroupOptions.new)
  @backend.group_upsert({
    name: group.name,
    description: group.description,
    ldap_group_reference: group.ldap_group_reference,
    roles: group.roles.map do |role|
             {
               name: role.name,
               bucket: role.bucket,
               scope: role.scope,
               collection: role.collection,
             }
           end,
  }, options.timeout)
end

#upsert_user(user, options = UpsertUserOptions.new) ⇒ Object

Creates or updates a user

Parameters:

  • user (User)

    the new version of the user

  • options (UpsertUserOptions) (defaults to: UpsertUserOptions.new)

Raises:

  • (ArgumentError)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/couchbase/management/user_manager.rb', line 59

def upsert_user(user, options = UpsertUserOptions.new)
  @backend.user_upsert(
    options.domain,
    {
      username: user.username,
      display_name: user.display_name,
      groups: user.groups,
      password: user.password,
      roles: user.roles.map do |role|
               {
                 name: role.name,
                 bucket: role.bucket,
                 scope: role.scope,
                 collection: role.collection,
               }
             end,
    }, options.timeout
  )
end