Class: Couchbase::Management::UserManager

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/management/user_manager.rb

Defined Under Namespace

Classes: 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)


25
26
27
# File 'lib/couchbase/management/user_manager.rb', line 25

def initialize(backend)
  @backend = backend
end

Instance Method Details

#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:



156
157
158
# File 'lib/couchbase/management/user_manager.rb', line 156

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)


81
82
83
# File 'lib/couchbase/management/user_manager.rb', line 81

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:



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

def get_all_groups(options = GetAllGroupsOptions.new)
  resp = @backend.group_get_all(options.timeout)
  resp.map(&method(:extract_group))
end

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

Gets all users

Returns:



46
47
48
49
# File 'lib/couchbase/management/user_manager.rb', line 46

def get_all_users(options = GetAllUsersOptions.new)
  resp = @backend.user_get_all(options.domain, options.timeout)
  resp.map(&method(:extract_user))
end

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

Gets a group

Parameters:

  • group_name (String)

    name of the group to get

Returns:

Raises:



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

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:



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

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:



38
39
40
41
# File 'lib/couchbase/management/user_manager.rb', line 38

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:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/couchbase/management/user_manager.rb', line 134

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)


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

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