group - group handling

The group module includes all code relevant to group management. Just like the restauth_user module, the module contains factory methods (get(), get_all() or create()) and the Group class that offers an interface for managing a group.

Just like with users, it is recommended to instantiate a Group object directly if performance is critical. Please see the restauth_user module for an analogous example.

API documentation

Module handling code relevant to group handling.

class RestAuthClient.group.Group(conn, name)[source]

An instance of this class represents a group in RestAuth.

Note: The constructor does not verify that the group actually exists. This has the advantage of saving one request to the RestAuth service. If you want to be sure that a user exists, use get() or get_all().

Parameters:
  • conn (RestAuthConnection) – The connection to the RestAuthServer.
  • name (str) – The name of this user.
add_group(group)[source]

Add a group to this group.

Parameters:

group (Group or str) – The group or the name of the group to add.

Raises:
  • BadRequest – If the server was unable to parse the request body.
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – If the group or user does not exist.
  • UnsupportedMediaType – The server does not support the content type used by this connection (see also: set_content_handler()).
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
add_user(user)[source]

Add a user to this group.

Parameters:

user (User or str) – The user or the name of the user to add.

Raises:
  • BadRequest – If the server was unable to parse the request body.
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – If the group or user does not exist.
  • UnsupportedMediaType – The server does not support the content type used by this connection (see also: set_content_handler()).
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
get_groups()[source]

Get a list of sub-groups of this group.

Raises:
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – If the sub- or meta-group not exist.
  • NotAcceptable – When the server cannot generate a response in the content type used by this connection (see also: set_content_handler()).
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
get_members()[source]

Get all members of this group.

Returns:

A list of users.

Return type:

list

Raises:
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – If the group does not exist.
  • NotAcceptable – When the server cannot generate a response in the content type used by this connection (see also: set_content_handler()).
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
is_member(user)[source]

Check if the named user is a member.

Parameters:

user (User or str) – The user or the name of a user in question.

Returns:

True if the user is a member, False if not.

Return type:

bool

Raises:
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – If the group or user does not exist.
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
remove()[source]

Delete this group.

Raises:
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – If the group does not exist.
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
remove_group(group)[source]

Remove a sub-group from this group.

Parameters:

group (Group or str) – The group or the name of the group to remmove.

Raises:
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – If the sub- or meta-group not exist.
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
remove_user(user)[source]

Remove the given user from the group.

Raises:
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – If the group or user does not exist.
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
RestAuthClient.group.create(conn, name)[source]

Factory method that creates a new group in RestAuth.

Parameters:
  • conn (RestAuthConnection) – A connection to a RestAuth service.
  • name (str) – The name of the group to create
Returns:

The group object representing the group just created.

Return type:

Group

Raises:
  • BadRequest – If the server was unable to parse the request body.
  • Unauthorized – When the connection uses wrong credentials.
  • GroupExists – When the user already exists.
  • UnsupportedMediaType – The server does not support the content type used by this connection (see also: set_content_handler()).
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
RestAuthClient.group.create_test(conn, name)[source]

Do a test-run on creating a new group (i.e. to test user input against the RestAuth server configuration). This method throws the exact same Exceptions as create() but always returns None instead of a Group instance if the group could be created that way.

Note

Invoking this method cannot guarantee that actually creating this group will work in the future, i.e. it may have been created by another client in the meantime.

RestAuthClient.group.get(conn, name)[source]

Factory method that gets an existing user from RestAuth. This method verifies that the user exists in the RestAuth and throws ResourceNotFound if not.

Parameters:
  • conn (RestAuthConnection) – A connection to a RestAuth service.
  • name (str) – The name of the group to get
Returns:

The group object representing the group in RestAuth.

Return type:

Group

Raises:
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – If the group does not exist.
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.
RestAuthClient.group.get_all(conn, user=None)[source]

Factory method that gets all groups for this service known to RestAuth.

Parameters:
  • conn (RestAuthConnection) – A connection to a RestAuth service.
  • user (str) – Only return groups where the named user is a member
Returns:

A list of Group objects

Return type:

List of groups

Raises:
  • Unauthorized – When the connection uses wrong credentials.
  • ResourceNotFound – When the given user does not exist.
  • NotAcceptable – When the server cannot generate a response in the content type used by this connection (see also: set_content_handler()).
  • InternalServerError – When the RestAuth service returns HTTP status code 500
  • UnknownStatus – If the response status is unknown.

Table Of Contents

Previous topic

restauth_user - user handling

Next topic

errors - RestAuth related errors

This Page