From de394b75d8b8df5980fd89a37ae3d384b439555a Mon Sep 17 00:00:00 2001 From: Stephan Lohse Date: Fri, 6 Oct 2017 15:49:15 +0200 Subject: [PATCH] incoming folder: make user/key for move command configurable --- config.yaml | 3 +++ rules/mv_runfolders_from_incoming_to_processing.yaml | 3 ++- sensors/incoming_sensor.py | 7 ++++++- sensors/incoming_sensor.yaml | 5 +++++ sensors/runfolder_sensor.py | 8 +++++--- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index 228ce8e..f4e0c38 100644 --- a/config.yaml +++ b/config.yaml @@ -48,6 +48,9 @@ runfolder_svc_urls: incoming_svc_urls: - url: http://testarteria1:10850/api/1.0/runfolders/next dest_folder: /data/testarteria1/runfolders + remote_user: arteria + user_key: /home/arteria/.ssh/id_rsa + charon_api_token: dummy_token charon_base_url: http://charon.url diff --git a/rules/mv_runfolders_from_incoming_to_processing.yaml b/rules/mv_runfolders_from_incoming_to_processing.yaml index 31e8681..6002553 100644 --- a/rules/mv_runfolders_from_incoming_to_processing.yaml +++ b/rules/mv_runfolders_from_incoming_to_processing.yaml @@ -14,4 +14,5 @@ action: hosts: "{{ trigger.host }}" source: "{{ trigger.runfolder }}" destination: "{{ trigger.destination }}" - + username: "{{ trigger.remote_user }}" + private_key: "{{ trigger.user_key }}" diff --git a/sensors/incoming_sensor.py b/sensors/incoming_sensor.py index 7d1bba3..0fd7323 100644 --- a/sensors/incoming_sensor.py +++ b/sensors/incoming_sensor.py @@ -18,7 +18,12 @@ def setup(self): try: self._load_config() client_urls = [x['url'] for x in self.config["incoming_svc_urls"]] - self._destinations = {x['url']: x['dest_folder'] for x in self.config["incoming_svc_urls"]} + # copy all further keys of every item over to self._hostconfigs + for x in self.config["incoming_svc_urls"]: + self._hostconfigs[x['url']] = {} + for y in x: + if y != 'url': + self._hostconfigs[x['url']][y] = x[y] self._client = RunfolderClient(client_urls, self._logger) self._infolog("Created client: {0}".format(self._client)) except Exception as ex: diff --git a/sensors/incoming_sensor.yaml b/sensors/incoming_sensor.yaml index dd3ed57..7bb3fc3 100644 --- a/sensors/incoming_sensor.yaml +++ b/sensors/incoming_sensor.yaml @@ -20,3 +20,8 @@ type: "string" destination: type: "string" + remote_user: + type: "string" + user_key: + type: "string" + diff --git a/sensors/runfolder_sensor.py b/sensors/runfolder_sensor.py index 9e09222..ea92e1a 100644 --- a/sensors/runfolder_sensor.py +++ b/sensors/runfolder_sensor.py @@ -14,7 +14,7 @@ def __init__(self, sensor_service, config=None, poll_interval=None, trigger='art self._infolog("__init__") self._client = None self._trigger = trigger - self._destinations = {} + self._hostconfigs = {} def setup(self): self._infolog("setup") @@ -66,8 +66,10 @@ def _handle_result(self, result): 'timestamp': datetime.utcnow().isoformat(), 'destination': "" } - if result['requesturl'] in self._destinations: - payload['destination'] = self._destinations[result['requesturl']] + if result['requesturl'] in self._hostconfigs: + payload['destination'] = self._hostconfigs[result['requesturl']].get('dest_folder', "") + payload['remote_user'] = self._hostconfigs[result['requesturl']].get('remote_user', "") + payload['user_key'] = self._hostconfigs[result['requesturl']].get('user_key', "") self._sensor_service.dispatch(trigger=trigger, payload=payload, trace_tag=runfolder_name) def _load_config(self):