Skip to content

Commit

Permalink
add Webhooks draft
Browse files Browse the repository at this point in the history
  • Loading branch information
anatskiy committed Jul 30, 2016
1 parent 5b0641f commit 5dfdf90
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 2 deletions.
6 changes: 4 additions & 2 deletions config/galaxy.ini.sample
Expand Up @@ -170,7 +170,7 @@ paste.app_factory = galaxy.web.buildapp:app_factory
# https://wiki.galaxyproject.org/Admin/Config/ToolDependencies
# Set to the string none to explicitly disable tool dependency handling.
# If this option is set to none or an invalid path, installing tools with dependencies
# from the Tool Shed will fail.
# from the Tool Shed will fail.
#tool_dependency_dir = database/dependencies

# The dependency resolves config file specifies an ordering and options for how
Expand Down Expand Up @@ -286,6 +286,9 @@ paste.app_factory = galaxy.web.buildapp:app_factory
# separated list.
#tour_config_dir = config/plugins/tours

# Webhooks directory
#webhooks_dir = config/plugins/webhooks

# Each job is given a unique empty directory as its current working directory.
# This option defines in what parent directory those directories will be
# created.
Expand Down Expand Up @@ -1228,4 +1231,3 @@ use_interactive = True
#exchange = galaxy_exchange
#routing_key = bar_code_scanner
#rabbitmqctl_path = /path/to/rabbitmqctl

5 changes: 5 additions & 0 deletions config/plugins/plugin1.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<webhook name="Plugin 1" type="topbar">
<params></params>
<template></template>
</webhook>
5 changes: 5 additions & 0 deletions config/plugins/plugin2.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<webhook name="Plugin 2" type="mainview">
<params></params>
<template></template>
</webhook>
2 changes: 2 additions & 0 deletions config/plugins/webhooks/plugin1/config/plugin1.yaml
@@ -0,0 +1,2 @@
name: Plugin 1
type: topbar
2 changes: 2 additions & 0 deletions config/plugins/webhooks/plugin2/config/plugin2.yml
@@ -0,0 +1,2 @@
name: Plugin 2
type: mainview
3 changes: 3 additions & 0 deletions lib/galaxy/app.py
Expand Up @@ -24,6 +24,7 @@ def pf_dec(func):
from galaxy.visualization.plugins.registry import VisualizationsRegistry
from galaxy.tools.special_tools import load_lib_tools
from galaxy.tours import ToursRegistry
from galaxy.webhooks import WebhooksRegistry
from galaxy.sample_tracking import external_service_types
from galaxy.openid.providers import OpenIDProviders
from galaxy.tools.data_manager.manager import DataManagers
Expand Down Expand Up @@ -123,6 +124,8 @@ def __init__( self, **kwargs ):
template_cache_dir=self.config.template_cache )
# Tours registry
self.tour_registry = ToursRegistry(self.config.tour_config_dir)
# Webhooks registry
self.webhooks_registry = WebhooksRegistry(self.config.webhooks_dir)
# Load security policy.
self.security_agent = self.model.security_agent
self.host_security_agent = galaxy.security.HostAgent(
Expand Down
2 changes: 2 additions & 0 deletions lib/galaxy/config.py
Expand Up @@ -111,6 +111,8 @@ def __init__( self, **kwargs ):

self.tour_config_dir = resolve_path( kwargs.get("tour_config_dir", "config/plugins/tours"), self.root)

self.webhooks_dir = resolve_path( kwargs.get("webhooks_dir", "config/plugins/webhooks"), self.root)

self.expose_user_name = kwargs.get( "expose_user_name", False )
self.expose_user_email = kwargs.get( "expose_user_email", False )
self.password_expiration_period = timedelta( days=int( kwargs.get( "password_expiration_period", 0 ) ) )
Expand Down
14 changes: 14 additions & 0 deletions lib/galaxy/webapps/galaxy/api/webhooks.py
@@ -0,0 +1,14 @@
"""
API Controller providing Galaxy Webhooks
"""

import logging

from galaxy.web.base.controller import BaseAPIController

log = logging.getLogger(__name__)


class WebhooksController(BaseAPIController):
def __init__(self, app):
super(WebhooksController, self).__init__(app)
50 changes: 50 additions & 0 deletions lib/galaxy/webhooks/__init__.py
@@ -0,0 +1,50 @@
"""
This module manages loading of Galaxy webhooks.
"""

import os
import yaml
import logging

from galaxy.util import galaxy_root_path

log = logging.getLogger(__name__)


class WebhooksRegistry(object):
webhooks = {}

def __init__(self, webhooks_directories):
path = os.path.join(galaxy_root_path, webhooks_directories)
self.webhooks_directories = \
[os.path.join(path, name)
for name in os.listdir(webhooks_directories)]
self.load_webhooks()

def load_webhooks(self):
for directory in self.webhooks_directories:
config_dir = os.path.join(directory, 'config')

if not os.path.exists(config_dir):
log.warning('directory not found: %s', config_dir)
continue

config_file = [conf for conf in os.listdir(config_dir)
if conf.endswith('.yml') or
conf.endswith('.yaml')][0]

if config_file:
self.load_webhook_from_config(
os.path.join(config_dir, config_file))

def load_webhook_from_config(self, config_file):
try:
with open(config_file) as f:
config = yaml.load(f)
if config['type'] not in self.webhooks.keys():
self.webhooks[config['type']] = []
self.webhooks[config['type']].append({
'name': config['name']
})
except Exception as e:
log.exception(e)

0 comments on commit 5dfdf90

Please sign in to comment.