Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

class squirro_client.user.UserApiMixin

Mixin class which encapsulates the functionality of the user API service.

All the methods of this class are made available in the SquirroClient class.

Table of Contents

get_user_data

get_user_data(user_id, api_version='v1')

Return data about a specific user, including any custom values.

Parameters:user_id – User identifier.
Returns:A dictionary which contains the user data.

Example:

>>> client.get_user_data('H5Qv-WhgSBGW0WL8xolSCQ')
{u'email': u'test@test.com',
 u'id': u'H5Qv-WhgSBGW0WL8xolSCQ',
 u'tenant': u'test'}

update_user_data

update_user_data(user_id, changes, api_version='v1')

Update data for the given user. Any value can be set and will be returned again when getting the user.

Parameters:
  • user_id – User identifier.
  • changes – A dictionary containing user data to be updated.
  • api_version – API version to use.
Returns:

A dictionary which contains the updated user data.

Example:

>>> client.update_user_data('H5Qv-WhgSBGW0WL8xolSCQ', {'name': 'Alexander Sennhauser'})
{u'email': u'test@test.com',
 u'id': u'H5Qv-WhgSBGW0WL8xolSCQ',
 u'name': u'Alexander Sennhauser',
 u'tenant': u'test'}

get_authentication

get_authentication(user_id, service)

Retrieves an authentication for a given service.

Parameters:
  • user_id – User identifier
  • service – Authentication service
Returns:

A dictionary containing the authentication data.

Example:

>>> client.get_authentication('H5Qv-WhgSBGW0WL8xolSCQ', 'facebook')
{u'access_secret': u'secret',
 u'access_secret_expires': u'2014-01-09T08:40:00',
 u'access_token': u'token',
 u'access_token_expires': u'2014-01-09T08:40:00',
 u'display_name': u'John Smith',
 u'service_user': u'1234567',
 u'state': u'ok'}

new_or_modify_authentication

new_or_modify_authentication(user_id, service, service_user, access_token, access_secret=None, display_name=None, access_token_expires=None, access_secret_expires=None)

Create a new authentication or modify an existing authentication for an external service.

Parameters:
  • user_id – User identifier.
  • service – Authentication service.
  • service_user – Service user identifier.
  • access_token – Service access token.
  • access_secret – Service access secret.
  • display_name – Service user display name.
  • access_token_expires – Expiry date for service access token.
  • access_secret_expires – Expiry date for service access secret.
Returns:

A dictionary containing the updated authentication data.

Example:

>>> client.new_or_modify_authentication('H5Qv-WhgSBGW0WL8xolSCQ', 'facebook', '1234567', 'token', 'secret', 'John Smith', datetime.datetime(2014, 1, 9, 8, 40), datetime.datetime(2014, 1, 9, 8, 40))
{u'access_secret': u'secret',
 u'access_secret_expires': u'2014-01-09T08:40:00',
 u'access_token': u'token',
 u'access_token_expires': u'2014-01-09T08:40:00',
 u'display_name': u'John Smith',
 u'service_user': u'1234567',
 u'state': u'ok'}

delete_authentication

delete_authentication(user_id, service)

Delete an authentication.

Parameters:
  • user_id – User identifier.
  • service – Service name.

Example:

>>> client.delete_authentication('H5Qv-WhgSBGW0WL8xolSCQ', 'facebook')

new_grant

new_grant(user_id, type, for_client_id=None, project_permissions=None)

Create a new grant.

Parameters:
  • user_id – User identifier.
  • type – Token type, either user or service.
  • for_client_id – Client id of the service the token is for. Only used when type is service.
  • project_permissions – List of permissions granted with this grant.
Returns:

A dictionary containing the refresh_token and the id of the grant.

Example:

>>> client.new_grant('H5Qv-WhgSBGW0WL8xolSCQ', 'service', 'abdc0183029498f20c38')
{u'id': u'yL0dnd17RNe9Jpn7uAa8Bw', u'refresh_token': u'b4c7440364afb80c2dd72fec18a506e57d7b0450fc0c8f10d3647b8b549587d9a838fe841950e625e7f2e3599a071a3c166936b159a314e2d538b0b773894ea2'}

delete_grant

delete_grant(user_id, grant_id)

Delete a grant.

Parameters:
  • user_id – User identifier.
  • grant_id – Grant identifier.

Example:

>>> client.delete_grant('H5Qv-WhgSBGW0WL8xolSCQ', 'yL0dnd17RNe9Jpn7uAa8Bw')

get_user_grants

get_user_grants(user_id)

Get all grants for the provided user.

Parameters:user_id – User identifier.
Returns:A dictionary where the value of grants is a list of the grants.

Example:

>>> client.get_user_grants('H5Qv-WhgSBGW0WL8xolSCQ')
{u'grants': [{u'created_at': u'2012-12-21 16:00:01', u'valid_to': u'2022-12-21 16:00:01', u'id': u'yL0dnd17RNe9Jpn7uAa8Bw', u'type': u'user'}]}

delete_session

delete_session(user_id, session_id)

Delete a session.

Parameters:
  • user_id – User identifier.
  • session_id – Session identifier

Example:

>>> client.delete_session('H5Qv-WhgSBGW0WL8xolSCQ', 'yL0dnd17RNe9Jpn7uAa8Bw')

get_users

get_users()

Returns all users within the logged-in users tenant.

Example:

>>> client.get_users()
{u'users': [
    {
        u'email': u'user01@example.com',
        u'full_name': u'User 1',
        u'id': u'H5Qv-WhgSBGW0WL8xolSCQ',
        u'role': u'user',
        u'role_permissions': [u'user'],
        u'tenant': u'lW8-FnZlQYWBimxFknYitw',
        …
    }
]}

delete_user

delete_user(user_id)

Delete a user from the system.

Parameters:user_id – Identifier of the user to delete.

Example:

>>> client.delete_user('H5Qv-WhgSBGW0WL8xolSCQ')

get_project_members

get_project_members(project_id)

Returns all users and groups associated with the given project.

Parameters:project_id – Project identifier.

Example:

>>> client.get_project_members('2sic33jZTi-ifflvQAVcfw')
{u'members': [{
   u'email': u'user01@example.com',
   u'full_name': u'User 1',
   u'member_id': u'H5Qv-WhgSBGW0WL8xolSCQ',
   u'member_type': u'user',
   u'server_role': u'user',
   u'project_role': u'reader',
   u'project_id': '2sic33jZTi-ifflvQAVcfw'
   u'permissions': [u'fingerprints.read.*',
                    u'fingerprints.write.create.adhoc',
                    u'items.read.*',
                    u'objects.read.*',
                    u'previews.read.*',
                    u'projects.read.*',
                    u'savedsearches.read.*',
                    u'scores.read.*',
                    u'signals.read.*',
                    u'sources.read.*',
                    u'subscriptions.read.*']},
    …
]}

The permissions list reflects the permissions the given user or group has in this project. The permissions depend on the user’s project role and server role.

add_project_member

add_project_member(project_id, role, user_id=None, group_id=None)

Adds a user or group to a project as a member.

Parameters:
  • project_id – Project identifier of the project in which to add the member.
  • role – Role of the member. Allowed values: reader, member, admin.
  • user_id – Identifier of the user to be added (can’t be combined with group_id).
  • group_id – Identifier of the group to be added (can’t be combined with user_id).

Example:

>>> client.add_project_member('2sic33jZTi-ifflvQAVcfw', 'member',
                              user_id='H5Qv-WhgSBGW0WL8xolSCQ')
{
   u'email': u'user01@example.com',
   u'full_name': u'User 1',
   u'member_id': u'H5Qv-WhgSBGW0WL8xolSCQ',
   u'member_type': u'user',
   u'server_role': u'user',
   u'project_role': u'member',
   u'project_id': '2sic33jZTi-ifflvQAVcfw'
   u'permissions': [u'fingerprints.*',
                    u'items.*',
                    u'objects.*',
                    u'previews.*',
                    u'projects.read.*',
                    u'projects.write.*',
                    u'savedsearches.*',
                    u'scores.*',
                    u'signals.*',
                    u'sources.*',
                    u'subscriptions.*']
}

update_project_member

update_project_member(project_id, member_id, role)

Modifies a project membership.

Right now only the role can be changed, so that argument is required.

Parameters:
  • project_id – Project identifier of the project in which to modify the member.
  • member_id – Identifier of the user or group to be updated.
  • role – New role of the member. Allowed values: reader, member, admin.

Example:

>>> client.update_project_member('2sic33jZTi-ifflvQAVcfw', 'H5Qv-WhgSBGW0WL8xolSCQ', 'admin')
{
   u'email': u'user01@example.com',
   u'full_name': u'User 1',
   u'member_id': u'H5Qv-WhgSBGW0WL8xolSCQ',
   u'member_type': u'admin',
   …
}

delete_project_member

delete_project_member(project_id, member_id)

Removes a user or group from a project as a member.

Parameters:
  • project_id – Project identifier of the project to remove the member from.
  • member_id – Identifier of the user or group to be removed.

Example:

>>> client.delete_project_member('2sic33jZTi-ifflvQAVcfw',
                                 'H5Qv-WhgSBGW0WL8xolSCQ')

get_groups

get_groups()

Returns all groups within the logged-in users tenant.

Example:

>>> client.get_groups()
[{u'id': u'1jo-WmmyRvC8UYtPMIQaoQ',
  u'name': 'Team East',
  u'members': [
      {
          u'email': u'user01@example.com',
          u'full_name': u'User 1',
          u'id': u'H5Qv-WhgSBGW0WL8xolSCQ',
          u'role': u'user',
          u'role_permissions': [u'user'],
          u'tenant': 'lW8-FnZlQYWBimxFknYitw'
      }
  ]
 }
]

create_group

create_group(name)

Create a new group.

Parameters:name – Group name

Example:

>>> client.create_group('Team East')
{
    u'id': u'1jo-WmmyRvC8UYtPMIQaoQ',
    u'name': 'Team East',
    u'members': []
}

get_group

get_group(group_id)

Returns details, including the members, of a group.

Parameters:group_id – Identifier of the group for which the details are returned.

Example:

>>> client.get_group('1jo-WmmyRvC8UYtPMIQaoQ')
{
    u'id': u'1jo-WmmyRvC8UYtPMIQaoQ',
    u'name': 'Team East',
    u'members': [
        {
            u'email': u'user01@example.com',
            u'full_name': u'User 1',
            u'id': u'H5Qv-WhgSBGW0WL8xolSCQ',
            u'role': u'user',
            u'role_permissions': [u'user'],
            u'tenant': 'lW8-FnZlQYWBimxFknYitw'
        }
    ]
}

update_group

update_group(group_id, name)

Modify a group’s attributes.

Parameters:
  • group_id – Identifier of the group to modify.
  • name – New name of the group.

Example:

>>> client.update_group('1jo-WmmyRvC8UYtPMIQaoQ', 'Team West')
{
    u'id': u'1jo-WmmyRvC8UYtPMIQaoQ',
    u'name': 'Team West',
    u'members': [
        {
            u'email': u'user01@example.com',
            u'full_name': u'User 1',
            u'id': u'H5Qv-WhgSBGW0WL8xolSCQ',
            u'role': u'user',
            u'role_permissions': [u'user'],
            u'tenant': 'lW8-FnZlQYWBimxFknYitw'
        }
    ]
}

delete_group

delete_group(group_id)

Delete a group.

Parameters:group_id – Identifier of the group to delete.

Example:

>>> client.delete_group('1jo-WmmyRvC8UYtPMIQaoQ')

add_group_member

add_group_member(group_id, user_id)

Adds a user to the group.

Parameters:
  • group_id – Identifier of the group to add the user to.
  • user_id – Identifier of the user to add to the group.

Example:

>>> client.add_group_member('1jo-WmmyRvC8UYtPMIQaoQ',
                            'H5Qv-WhgSBGW0WL8xolSCQ')
{
    u'email': u'user01@example.com',
    u'full_name': u'User 1',
    u'id': u'H5Qv-WhgSBGW0WL8xolSCQ',
    u'role': u'user',
    u'role_permissions': [u'user'],
    u'tenant': 'lW8-FnZlQYWBimxFknYitw'
}

delete_group_member

delete_group_member(group_id, user_id)

Removes a user from the group.

Parameters:
  • group_id – Identifier of the group from which to remove the user.
  • user_id – Identifier of the user to remove from the group.

Example:

>>> client.delete_group_member('1jo-WmmyRvC8UYtPMIQaoQ',
                               'H5Qv-WhgSBGW0WL8xolSCQ')
  • No labels