Validators

To run actions, the app must receive some sort of a trigger request, e.g. a push notification from GitHub. The app checks all incoming requests, and only the ones that pass the check trigger actions. The requests usually contain data that should be passed to the actions, i.e. branch name, so the app must extact the data after the check.

In Sloth CI, a trigger request source is called provider; e.g., GitHub, Bitbucket, and GitLab are providers. Each provider uses its own request format and thus requires its own validation and data extraction routine.

Validator implements request checking and data extraction for a particular provider. To add support of a new provider to Sloth CI, we just create a corresponsing validator.

Here is the list of currently available validators. If you want to create your own validator, refer to the developer guide.

Bitbucket

Sloth CI validator for Bitbucket push events.

Installation

$ pip install sloth-ci.validators.bitbucket

Usage

provider:
    bitbucket:
        # Repository owner. Mandatory parameter.
        owner: moigagoo

        # Repository title as it appears in the URL, i.e. slug.
        # Mandatory parameter.
        repo: sloth-ci

        # Only pushes to these branches will initiate a build.
        # Skip this parameter to allow all branches to fire builds.
        branches:
            - master
            - staging
sloth_ci.validators.bitbucket.validate(request, validation_data)[source]

Check payload from Bitbucket: the origin IP must be genuine; the repo owner and title must be valid.

Parameters:
  • requestCherryPy request instance representing incoming request
  • validation_data – dict with the keys owner, repo, and branches, parsed from the config
Returns:

namedtuple(status, message, list of extracted params as dicts), e.g. Response(status=200, message='Payload validated. Branches: default', [{'branch': 'default'}])

GitHub

Sloth CI validator for GitHub push events.

Installation

$ pip install sloth-ci.validators.github

Usage

provider:
    github:
        # Repository owner. Mandatory parameter.
        owner: moigagoo

        # Repository title as it appears in the URL, i.e. slug.
        # Mandatory parameter.
        repo: sloth-ci

        # Only pushes to these branches will initiate a build.
        # Skip this parameter to allow all branches to fire builds.
        branches:
            - master
            - staging
sloth_ci.validators.github.validate(request, validation_data)[source]

Check payload from GitHub: the origin IP must be genuine; the repo owner and title must be valid.

Parameters:
  • request

    CherryPy request instance representing incoming request

  • validation_data – dict with the keys owner, repo, and branches, parsed from the config
Returns:

namedtuple(status, message, list of extracted params as dicts), e.g. Response(status=200, message='Payload validated. Branches: default', [{'branch': 'default'}])

GitLab

Sloth CI validator for GitLab push events.

Installation

$ pip install sloth-ci.validators.gitlab

Usage

provider:
    gitlab:
        # Whitelisted GitLab server IPs.
        # Mandatory parameter.
        trusted_ips:
            - 123.45.67.89
            - 111.22.33.44

        # Repository title as it appears in the URL, i.e. slug.
        # Mandatory parameter.
        repo: sloth-ci

        # Only pushes to these branches will initiate a build.
        # Skip this parameter to allow all branches to fire builds.
        branches:
            - master
            - staging
sloth_ci.validators.gitlab.validate(request, validation_data)[source]

Check payload from GitLab: the origin IP must be genuine and the repo title must be valid.

Parameters:
  • request

    CherryPy request instance representing incoming request

  • validation_data – dict with the keys trusted_ips, repo, and branches, parsed from the config
Returns:

namedtuple(status, message, list of extracted params as dicts), e.g. Response(status=200, message='Payload validated. Branches: default', [{'branch': 'default'}])