Example #1
0
def main():
    args = docopt.docopt(__doc__, version="version " + __version__, help=True)

    logging.error(pprint.pformat(args))

    if args.get('server'):
        options = {
            'workspace':
            os.path.realpath(os.path.expanduser(args.get('--workspace'))),
            'title':
            _get_title(args),
            'host':
            args.get('--host'),
            'port':
            args.get('--port')
        }

        username = _get_username(args)
        password = _get_password(args)
        cookie_secret = _get_cookie_secret(args)
        ghauth = args.get('--github-auth')

        options[
            'cookie_secret'] = cookie_secret if cookie_secret else random_secret(
            )

        if ghauth:
            teams = []
            for allowed_team in ghauth.split(','):
                if not '/' in allowed_team:
                    raise PipelinesError(
                        'github-auth requires organization and team in format of "(org)/(team)"'
                    )
                org, team = allowed_team.split('/', 1)
                teams.append((org, team))
            options['auth'] = ('gh', teams)
        elif username and password:
            if len(password) < MIN_PASSWORD_LEN:
                raise PipelinesError('Too short password')
            options['auth'] = ('static', username, password)

        options['debug'] = args.get('--debug')
        options['history_limit'] = int(args.get('--history-limit') or 30)
        options['web_path'] = args.get('--web-path') or '/'
        try:
            server.main(options)
        except KeyboardInterrupt:
            print('Exiting')
    else:
        print(__doc__.strip('\n'))
        sys.exit(0)
Example #2
0
def make_app(cookie_secret=None, workspace='fixtures/workspace', title='Pipelines', auth=None):
    if cookie_secret is None:
        raise PipelineError('Cookie secret can not be empty')

    if not os.path.isdir(workspace):
        raise PipelinesError('Workspace is not a valid directory: %s' % workspace)

    auth_dict = _get_auth_dict(auth)

    slug_regexp = '[0-9a-zA-Z_\-]+'
    endpoints = [
        url(r"/api/pipelines/", GetPipelinesHandler),
        url(r"/api/pipelines/({slug})/".format(slug=slug_regexp), GetPipelineHandler),
        url(r"/api/pipelines/({slug})/run".format(slug=slug_regexp), RunPipelineHandler),
        url(r"/api/pipelines/({slug})/({slug})/status".format(slug=slug_regexp), GetStatusHandler),
        url(r"/api/pipelines/({slug})/({slug})/log".format(slug=slug_regexp), GetLogsHandler),
        url(r"/api/pipelines/({slug})/triggers".format(slug=slug_regexp), GetTriggersHandler),
        url(r"/api/webhook/({slug})".format(slug=slug_regexp), WebhookHandler),
        url(r"/api/slackbot/({slug})".format(slug=slug_regexp), SlackbotHandler),
        (r"/login", LoginHandler),
        (r'/(.*)', AuthStaticFileHandler, {'path': _get_static_path('app'), "default_filename": "index.html"}),
    ]

    if auth_dict and auth_dict.get('type') == 'gh':
        endpoints.insert(len(endpoints) - 1, (r"/ghauth", GithubOAuth2LoginHandler)),

    return Application(endpoints,
                       title=title,
                       workspace_path=workspace,
                       auth=auth_dict,
                       login_url="/login",
                       debug="True",
                       cookie_secret=cookie_secret
                       )
Example #3
0
def make_app(workspace='fixtures/workspace', auth=None):
    if not os.path.isdir(workspace):
        raise PipelinesError('Workspace is not a valid directory: %s' %
                             workspace)

    auth_dict = None
    if auth:
        auth_dict = {
            'type': 'static',
            'username': auth[0],
            'password': auth[1]
        }

    return Application(
        [
            url(r"/api/pipelines/", GetPipelinesHandler),
            url(r"/api/pipelines/([0-9a-zA-Z_\-]+)/run", RunPipelineHandler),
            url(r"/api/pipelines/([0-9a-zA-Z_\-]+)/([0-9a-zA-Z_\-]+)/status",
                GetStatusHandler),
            url(r"/api/pipelines/([0-9a-zA-Z_\-]+)/([0-9a-zA-Z_\-]+)/log",
                GetLogsHandler),
            (r"/login", LoginHandler),
            (r'/(.*)', AuthStaticFileHandler, {
                'path': _get_static_path('app'),
                "default_filename": "index.html"
            }),
        ],
        workspace_path=workspace,
        auth=auth_dict,
        login_url="/login",
        debug="True",
        cookie_secret=
        "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo="  # TODO: make configurable
    )
Example #4
0
 def run(self, context):
     log.debug('Running with context: {}'.format(context))
     self._write_user_context(context)
     if self.pipe:
         return self.pipe.run()
     else:
         raise PipelinesError('AsyncRunner error. No pipeline.')
Example #5
0
def make_app(workspace='fixtures/workspace', auth=None):
    if not os.path.isdir(workspace):
        raise PipelinesError('Workspace is not a valid directory: %s' %
                             workspace)

    auth_dict = _get_auth_dict(auth)

    slug_regexp = '[0-9a-zA-Z_\-]+'
    endpoints = [
        url(r"/api/pipelines/", GetPipelinesHandler),
        url(r"/api/pipelines/({slug})/".format(slug=slug_regexp),
            GetPipelineHandler),
        url(r"/api/pipelines/({slug})/run".format(slug=slug_regexp),
            RunPipelineHandler),
        url(
            r"/api/pipelines/({slug})/({slug})/status".format(
                slug=slug_regexp), GetStatusHandler),
        url(r"/api/pipelines/({slug})/({slug})/log".format(slug=slug_regexp),
            GetLogsHandler),
        url(r"/api/pipelines/({slug})/triggers".format(slug=slug_regexp),
            GetTriggersHandler),
        url(r"/api/webhook/({slug})".format(slug=slug_regexp), WebhookHandler),
        (r"/login", LoginHandler),
        (r'/(.*)', AuthStaticFileHandler, {
            'path': _get_static_path('app'),
            "default_filename": "index.html"
        }),
    ]

    if auth_dict and auth_dict.get('type') == 'gh':
        endpoints.insert(
            len(endpoints) - 1, (r"/ghauth", GithubOAuth2LoginHandler)),

    return Application(
        endpoints,
        workspace_path=workspace,
        auth=auth_dict,
        login_url="/login",
        debug="True",
        cookie_secret=
        "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo="  # TODO: make configurable
    )
Example #6
0
 def run(self):
     if self.pipe:
         return self.pipe.run()
     else:
         raise PipelinesError('AsyncRunner error. No pipeline.')
Example #7
0
def make_app(cookie_secret=None,
             workspace='fixtures/workspace',
             title='Pipelines',
             auth=None,
             history_limit=0,
             prefix='/'):
    if cookie_secret is None:
        raise PipelineError('Cookie secret can not be empty')

    if not os.path.isdir(workspace):
        raise PipelinesError('Workspace is not a valid directory: %s' %
                             workspace)

    auth_dict = _get_auth_dict(auth)

    slug_regexp = '[0-9a-zA-Z_\\-]+'
    endpoints = [
        Rule(PathMatches(r"/api/pipelines/"),
             GetPipelinesHandler,
             name='api_base'),
        Rule(PathMatches(r"/api/pipelines/({slug})/".format(slug=slug_regexp)),
             GetPipelineHandler),
        Rule(
            PathMatches(
                r"/api/pipelines/({slug})/run".format(slug=slug_regexp)),
            RunPipelineHandler),
        Rule(
            PathMatches(r"/api/pipelines/({slug})/({slug})/status".format(
                slug=slug_regexp)), GetStatusHandler),
        Rule(
            PathMatches(r"/api/pipelines/({slug})/({slug})/log".format(
                slug=slug_regexp)), GetLogsHandler),
        Rule(
            PathMatches(
                r"/api/pipelines/({slug})/triggers".format(slug=slug_regexp)),
            GetTriggersHandler),
        Rule(PathMatches(r"/api/webhook/({slug})".format(slug=slug_regexp)),
             WebhookHandler),
        Rule(PathMatches(r"/api/slackbot/({slug})".format(slug=slug_regexp)),
             SlackbotHandler),
        Rule(PathMatches(r"/login"), LoginHandler, name='login'),
        Rule(PathMatches(r'/(.*)'), AuthStaticFileHandler, {
            'path': _get_static_path('app'),
            "default_filename": "index.html"
        }),
    ]

    if auth_dict and auth_dict.get('type') == 'gh':
        hdl = Rule(PathMatches('/ghauth'),
                   GithubOAuth2LoginHandler,
                   name='ghauth')
        endpoints.insert(len(endpoints) - 1, hdl)

    # prefix support
    login_url, endpoints = add_prefix_to_handlers(prefix, auth_dict, endpoints)

    return Application(
        endpoints,
        title=title,
        workspace_path=workspace,
        auth=auth_dict,
        login_url=login_url,
        debug="True",
        cookie_secret=cookie_secret,
        history_limit=history_limit,
        prefix=prefix.rstrip('/'),
    )