orm¶
Functions
apps_for_user (session, user) |
Returns a tuple of tuples, each containing an application and the associated policy that the specified orm user is allowed to run. |
detached_session (db) |
Creates a session where at the end, the objects retrieved |
transaction (session) |
handles a transaction in a session. |
-
remoteappmanager.db.orm.
apps_for_user
(session, user)[source]¶ Returns a tuple of tuples, each containing an application and the associated policy that the specified orm user is allowed to run. If the user is None, the default is to return an empty list. The mapping_id is a unique string identifying the combination of application and policy. It is not unique per user. :param session: The current session :type session: Session :param user: the orm User, or None. :type user: User or None
Returns: Return type: A tuple of tuples (mapping_id, orm.Application, orm.ApplicationPolicy)
-
remoteappmanager.db.orm.
detached_session
(db)[source]¶ Creates a session where at the end, the objects retrieved are detached from the session itself
Classes
Accounting (**kwargs) |
Holds the information about who is allowed to run what. |
AppAccounting (url, **kwargs) |
Initialiser |
Application (**kwargs) |
Describes an application that should be available for startup |
ApplicationPolicy (**kwargs) |
A simple constructor that allows initialization from kwargs. |
Database (url, **kwargs) |
Initialises a database connection to a given database url. |
IdMixin |
Base class to provide an id |
User (**kwargs) |
Table for users. |
-
class
remoteappmanager.db.orm.
Accounting
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
Holds the information about who is allowed to run what.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
application
¶
-
application_id
¶
-
application_policy
¶
-
application_policy_id
¶
-
id
¶
-
user
¶
-
user_id
¶
-
-
class
remoteappmanager.db.orm.
AppAccounting
(url, **kwargs)[source]¶ Bases:
remoteappmanager.db.interfaces.ABCAccounting
Initialiser
Parameters: - url (str) – the url for connecting to a database
- **kwargs – optional keyword arguments for Database
See also
-
check_database_readable
()[source]¶ Raise IOError if the database url points to a sqlite database that is not readable
TODO: may extend for validating databases in other dialects?
-
create_application
(app_name)[source]¶ Creates a new application with the specified name. Raises if an application with the same name already exists
Parameters: app_name (str) – The name of the application Returns: id – The id of the created application Return type: int Raises: exceptions.Exists
– If the application already exists.
-
create_user
(user_name)[source]¶ Creates a user with the specified username, if the backend allows it.
Parameters: user_name (str) – The user name Returns: id – The unique id of the user Return type: int Raises: exceptions.Exists
– If the user with that name already exists.
-
get_apps_for_user
(user)[source]¶ Return an iterable of ApplicationConfig for a given user
Parameters: user (opaque-type) – Same type as the result of get_user Returns: each item of the tuple should be a tuple of (id, ABCApplication, ABCApplicationPolicy) where id is a string used for identifying (ABCApplication, ABCApplicationPolicy) Return type: tuple
-
get_user
(*, user_name=None, id=None)[source]¶ Return a User for a given user_name or id, or return None if the User is not found. Only one argument is allowed.
Parameters: Returns: user – an user object that the database understands
Return type: opaque-type
-
grant_access
(app_name, user_name, allow_home, allow_view, volume)[source]¶ Grant access for user to application.
Parameters: - app_name (str) – The name of the application
- user_name (str) – The name of the user
- allow_home (bool) – If the home workspace should be mounted.
- allow_view (bool) – If the session should be visible by others.
- volume (str) – A volume to mount in the format source_path:target_path:mode mode being “ro” or “rw”. (e.g. “/host/path:/container/path:ro”).
Raises: - exception.NotFound: – if the app or user are not found.
- ValueError: – if the volume string is invalid.
Returns: id – A 32 characters id (mapping_id)
Return type:
-
list_applications
()[source]¶ List all available applications
Returns: applications – A list of the available apps. Return type: list
-
list_users
()[source]¶ Returns a list of all available users.
Returns: users – A list of users. Return type: list
-
remove_application
(*, app_name=None, id=None)[source]¶ Remove an existing application by name or id, depending what is provided. Only one argument is allowed. If the application is not present, does nothing.
Parameters: Raises: exception.NotFound
– If the application is not found.
-
remove_user
(*, user_name=None, id=None)[source]¶ Removes a user by name or id, if the backend allows it. Only one argument is allowed. If the user is not present, does nothing.
Parameters: user_name (str) – The user name
-
revoke_access
(app_name, user_name, allow_home, allow_view, volume)[source]¶ Revoke access for user to application.
Parameters: - app_name (str) – The name of the application
- user_name (str) – The name of the user
- allow_home (bool) – If the home workspace should be mounted.
- allow_view (bool) – If the session should be visible by others.
- volume (str) – A volume to mount in the format source_path:target_path:mode mode being “ro” or “rw”. (e.g. “/host/path:/container/path:ro”).
Raises: - exception.NotFound: – if the app or user are not found.
- ValueError: – if the volume string is invalid.
-
class
remoteappmanager.db.orm.
Application
(**kwargs)[source]¶ Bases:
remoteappmanager.db.orm.IdMixin
,sqlalchemy.ext.declarative.api.Base
Describes an application that should be available for startup
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
id
¶
-
image
¶ The docker image name where the application can be found
-
-
class
remoteappmanager.db.orm.
ApplicationPolicy
(**kwargs)[source]¶ Bases:
remoteappmanager.db.orm.IdMixin
,sqlalchemy.ext.declarative.api.Base
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
allow_common
¶ If a common workarea should be mounted in the container
-
allow_home
¶ If the home directory should be mounted in the container
-
allow_view
¶ If the container should be accessible by other people
-
id
¶
-
volume_mode
¶
-
volume_source
¶
-
volume_target
¶
-
-
class
remoteappmanager.db.orm.
Database
(url, **kwargs)[source]¶ Bases:
remoteappmanager.logging.logging_mixin.LoggingMixin
Initialises a database connection to a given database url.
Parameters: - url (url) – A sqlalchemy url to connect to a specified database.
- kwargs (dict) – Additional keys will be passed at create_engine.
-
class
remoteappmanager.db.orm.
IdMixin
[source]¶ Bases:
object
Base class to provide an id
-
id
= Column(None, Integer(), table=None, primary_key=True, nullable=False)¶
-
-
class
remoteappmanager.db.orm.
User
(**kwargs)[source]¶ Bases:
remoteappmanager.db.orm.IdMixin
,sqlalchemy.ext.declarative.api.Base
Table for users.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
id
¶
-
name
¶ The name of the user as specified by jupyterhub. This entry must be unique and is, for all practical purposes, a primary key.
-