toxicbuild.integrations package

Submodules

toxicbuild.integrations.base module

class toxicbuild.integrations.base.BaseIntegrationApp(*args, **kwargs)[source]

Bases: toxicbuild.core.utils.LoggerMixin, mongomotor.document.Document

exception DoesNotExist

Bases: mongoengine.errors.DoesNotExist

exception MultipleObjectsReturned

Bases: mongoengine.errors.MultipleObjectsReturned

coroutine classmethod create_app()[source]
coroutine classmethod get_app()[source]

Returns the app instance. If it does not exist, create it.

id

A field wrapper around MongoDB’s ObjectIds.

objects = QuerySet
class toxicbuild.integrations.base.BaseIntegrationInstallation(*args, **kwargs)[source]

Bases: toxicbuild.core.utils.LoggerMixin, mongomotor.document.Document

A installation is created

exception DoesNotExist

Bases: mongoengine.errors.DoesNotExist

exception MultipleObjectsReturned

Bases: mongoengine.errors.MultipleObjectsReturned

coroutine classmethod create(user, **kwargs)[source]

Creates a new integration installation. Imports the repositories available to the installation.

Parameters:
  • user – The user that owns the installation.
  • kwargs – Named arguments passed to installation class init.
coroutine delete(requester, *args, **kwargs)[source]

Deletes the installation from the system

coroutine enable_notification(repo)[source]

Enables a notification to a repository.

Parameters:repo – A repository instance.
get_notif_config()[source]
coroutine import_repositories()[source]

Imports all repositories available to the installation.

coroutine import_repository(repo_info, clone=True)[source]

Imports a repository from an external service.

Parameters:repo_info – A dictionary with the repository information. it MUST have the following keys: - id - name - full_name - clone_url
coroutine list_repos()[source]
coroutine remove_repository(github_repo_id)[source]

Removes a repository from the system.

Parameters:github_repo_id – The id of the repository in github.
coroutine repo_request_build(external_repo_id, branch, named_tree)[source]

Requests a new build.

Parameters:
  • external_repo_id – The id of the repository in a external service.
  • branch – The name of the branch to build.
  • named_tree – The named tree to build.
coroutine update_repository(external_repo_id, repo_branches=None, external=None, wait_for_lock=False)[source]

Updates a repository’s code.

Parameters:
  • external_repo_id – The id of the repository on github.
  • repo_branches – Param to be passed to request_code_update().
  • external – Information about an third party repository i.e a commit from a pull request from another repository.
  • wait_for_lock – Indicates if we should wait for the release of the lock or simply return if we cannot get a lock.
id

A field wrapper around MongoDB’s ObjectIds.

notif_name = None
objects = QuerySet
repositories

The repositories imported from the user external service account.

user
user_id

The id of the user who owns the installation

user_name

The name of the user who owns the installation

class toxicbuild.integrations.base.ExternalInstallationRepository(*args, **kwargs)[source]

Bases: toxicbuild.core.utils.LoggerMixin, mongomotor.document.EmbeddedDocument

Information about a repository in an external service.

external_id

The id of the repository in the external service.

full_name

Full name of the repository in the external service.

repository_id

The id of the repository in ToxicBuild.

toxicbuild.integrations.exceptions module

exception toxicbuild.integrations.exceptions.AppDoesNotExist[source]

Bases: Exception

exception toxicbuild.integrations.exceptions.AppExists[source]

Bases: Exception

exception toxicbuild.integrations.exceptions.BadRepository[source]

Bases: Exception

exception toxicbuild.integrations.exceptions.BadRequestToExternalAPI[source]

Bases: Exception

exception toxicbuild.integrations.exceptions.BadSignature[source]

Bases: Exception

toxicbuild.integrations.github module

This module implements the integration with Github. It is a GithubApp that reacts to events sent by github webhooks and informs about build statuses using checks.

Usage:

# When a new installation is created on github we must create a
# installation here.

install = await GithubInstallation.create(github_install_id, user)

# When a push happens or a pull request is created or synchronized
# we update the code here.

await install.update_repository(github_repo_id)

# When a check is rerequested we request a build
await install.repo_request_build(github_repo_id, branch, named_tree)

For information on how to setup the integration, see Integration with Github

class toxicbuild.integrations.github.GithubApp(*args, **kwargs)[source]

Bases: toxicbuild.integrations.base.BaseIntegrationApp

A GitHub App. Only one app per ToxicBuild installation.

exception DoesNotExist

Bases: toxicbuild.integrations.base.DoesNotExist

exception MultipleObjectsReturned

Bases: toxicbuild.integrations.base.MultipleObjectsReturned

coroutine classmethod create_app()[source]
coroutine classmethod create_installation_token(installation)[source]

Creates a auth token for a given github installation

Parameters:installation – An instance of GitHubInstallation
coroutine create_token()[source]

Creates a new token for the github api.

get_api_url()[source]

Returns the url for the github app api.

coroutine get_jwt_token()[source]

Returns the jwt token for authentication on the github api.

coroutine is_expired()[source]

Informs if the jwt token is expired.

coroutine set_expire_time(exp_time)[source]

Sets the expire time for the jwt token

coroutine set_jwt_token(jwt_token)[source]

Sets the jwt auth token.

validate_token(signature, data)[source]

Validates the incomming data in the webhook, sent by github.

app_id

The id of the app in github.

jwt_expires

When auth token for the github api. expires. It must be in UTC

jwt_token

The auth token for the github api.

private_key

The private key you generated in github.

webhook_token

The token used to sign the incomming request in the webhook. This must be set in the github app creation page.

class toxicbuild.integrations.github.GithubInstallation(*args, **kwargs)[source]

Bases: toxicbuild.integrations.base.BaseIntegrationInstallation

An installation of the GitHub App. Installations have access to repositories and events.

exception DoesNotExist

Bases: toxicbuild.integrations.base.DoesNotExist

exception MultipleObjectsReturned

Bases: toxicbuild.integrations.base.MultipleObjectsReturned

app

alias of GithubApp

coroutine get_header(accept='application/vnd.github.machine-man-preview+json')[source]
coroutine get_repo(repo_full_name)[source]

Get the repository (if available to the installation) from the github api.

Parameters:github_repo_id – The full name of the repository on github.
coroutine list_repos()[source]

Lists all respositories available to an installation. Returns a list of dictionaries with repositories’ information

auth_token

A unicode string field.

auth_token_url

URL used to retrieve an access token for this installation.

expires

Datetime field.

Uses the python-dateutil library if available alternatively use time.strptime to parse the dates. Note: python-dateutil’s parser is fully featured and when installed you can utilise it to convert varying types of date formats into valid python datetime objects.

Note: To default the field to the current datetime, use: DateTimeField(default=datetime.utcnow)

Note: Microseconds are rounded to the nearest millisecond.
Pre UTC microsecond support is effectively broken. Use ComplexDateTimeField if you need accurate microsecond support.
github_id

32-bit integer field.

notif_name = 'github-check-run'
token_is_expired

Informs if the installation auth token is expired.

toxicbuild.integrations.gitlab module

This module implements integration with gitlab. Imports repositories from GitLab and reacts to messages sent by gitlab to toxicbuild’s integrations webhook. See: GitLab integration docs.

class toxicbuild.integrations.gitlab.GitLabInstallation(*args, **kwargs)[source]

Bases: toxicbuild.integrations.base.BaseIntegrationInstallation

exception DoesNotExist

Bases: toxicbuild.integrations.base.DoesNotExist

exception MultipleObjectsReturned

Bases: toxicbuild.integrations.base.MultipleObjectsReturned

coroutine create_access_token()[source]

Creates an access token to the gitlab api.

coroutine create_webhook(repo_external_id)[source]

Creates a webhook at gitlab for a given repository.

Parameters:repo_external_id – The repository’s id on gitlab.
coroutine get_header()[source]
coroutine get_user_id()[source]

Gets the user id from the gitlab api.

coroutine import_repository(repo_info, clone=True)[source]

Imports a repository from an external service.

Parameters:repo_info – A dictionary with the repository information. it MUST have the following keys: - id - name - full_name - clone_url
coroutine list_repos()[source]

Lists the repositories using GitLab API.

REDIRECT_URI = 'gitlab/setup'
access_token

Access token for the gitlab api

code

The code first sent by the gitlab api. Used to generate the access token

gitlab_user_id

The user’s id at gitlab.

notif_name = 'gitlab-commit-status'

toxicbuild.integrations.webhook_receivers module

class toxicbuild.integrations.webhook_receivers.BaseWebhookReceiver(*args, **kwargs)[source]

Bases: toxicbuild.core.utils.LoggerMixin, pyrocumulus.web.handlers.BasePyroHandler

operation_mapper

alias of pyrocumulus.web.operationmappers.HandlerOperationMapper

check_event_type()[source]
create_installation(user)[source]
coroutine get_install()[source]
get_pull_request_source()[source]
get_pull_request_target()[source]
get_repo_external_id()[source]
coroutine handle_pull_request()[source]
coroutine handle_push()[source]
hello()[source]
prepare()[source]

Called at the beginning of a request before get/post/etc.

Override this method to perform common initialization regardless of the request method.

Asynchronous support: Decorate this method with .gen.coroutine or .return_future to make it asynchronous (the asynchronous decorator cannot be used on prepare). If this method returns a .Future execution will not proceed until the .Future is done.

New in version 3.1: Asynchronous support.

coroutine receive_webhook()[source]
setup()[source]
coroutine validate_webhook()[source]
class toxicbuild.integrations.webhook_receivers.GithubWebhookReceiver(*args, **kwargs)[source]

Bases: toxicbuild.integrations.webhook_receivers.BaseWebhookReceiver

operation_mapper

alias of pyrocumulus.web.operationmappers.HandlerOperationMapper

check_event_type()[source]
create_installation(user)[source]
coroutine get_install()[source]
get_pull_request_source()[source]
get_pull_request_target()[source]
get_repo_external_id()[source]
coroutine validate_webhook()[source]
class toxicbuild.integrations.webhook_receivers.GitlabWebhookReceiver(*args, **kwargs)[source]

Bases: toxicbuild.integrations.webhook_receivers.BaseWebhookReceiver

operation_mapper

alias of pyrocumulus.web.operationmappers.HandlerOperationMapper

check_event_type()[source]
create_installation(user)[source]
coroutine get_install()[source]
get_pull_request_source()[source]
get_pull_request_target()[source]
get_repo_external_id()[source]
state_is_valid()[source]

Checks if the state hash sent by gitlab is valid.

coroutine validate_webhook()[source]

Module contents

toxicbuild.integrations.create(root_dir, access_token='', output_token='', root_user_id='', cookie_secret='')[source]

Creates a new toxicbuild integrations environment.

Parameters:
  • --root_dir – Root directory for toxicbuild integrations.
  • --access-token – Access token to master’s hole.
  • --output-token – The auth token on the output web api
  • --root-user-id – The id for the root user of the system.
  • --cookie-secret – The secret used for secure cookies. This MUST be the same secret used in toxicui.
toxicbuild.integrations.create_settings()[source]
toxicbuild.integrations.ensure_indexes()[source]
toxicbuild.integrations.restart(workdir, pidfile='toxicintegrations.pid', loglevel='info')[source]

Restarts toxicmaster integrations

The instance of toxicintegrations in workdir will be restarted. :param workdir: Workdir for instance to be killed. :param –pidfile: Name of the file to use as pidfile. :param –loglevel: Level for logging messages.

toxicbuild.integrations.start(workdir, daemonize=False, stdout='./toxicintegrations.log', stderr='./toxicintegrations.log', conffile=None, loglevel='info', pidfile='toxicintegrations.pid')[source]

Starts toxicmaster integrations.

Parameters:
  • workdir – Work directory for server.
  • --daemonize – Run as daemon. Defaults to False
  • --stdout – stdout path. Defaults to /dev/null
  • --stderr – stderr path. Defaults to /dev/null
  • --conffile (-c,) – path to config file. Defaults to None. If not conffile, will look for a file called toxicintegrations.conf inside workdir
  • --loglevel – Level for logging messages. Defaults to info.
  • --pidfile – Name of the file to use as pidfile. Defaults to toxicintegrations.pid
toxicbuild.integrations.stop(workdir, pidfile='toxicintegrations.pid')[source]

Stops toxicmaster integrations.

Parameters:
  • workdir – Work directory for the ui to be killed.
  • --pidfile – pid file for the process.