diff options
-rw-r--r-- | ick2/client.py | 4 | ||||
-rwxr-xr-x | icktool | 15 |
2 files changed, 15 insertions, 4 deletions
diff --git a/ick2/client.py b/ick2/client.py index 00fc9c0..bd0586e 100644 --- a/ick2/client.py +++ b/ick2/client.py @@ -214,6 +214,10 @@ class ControllerClient: url = self.url(path) return self._api.post(url, body=obj) + def update(self, path, obj): # pragma: no cover + url = self.url(path) + return self._api.put(url, body=obj) + def trigger(self, project_name, pipeline_name): # pragma: no cover path = '/projects/{}/pipelines/{}/+trigger'.format( project_name, pipeline_name) @@ -142,15 +142,22 @@ class Icktool(cliapp.Application): api = self._new_api() api.set_token(token) - self._create_resources(api, '/projects', obj.get('projects', [])) - self._create_resources(api, '/pipelines', obj.get('pipelines', [])) + self._create_resources( + api, '/projects', 'project', obj.get('projects', [])) + self._create_resources( + api, '/pipelines', 'pipeline', obj.get('pipelines', [])) def _read_object(self): return yaml.load(sys.stdin) - def _create_resources(self, api, path, objs): + def _create_resources(self, api, path, field, objs): for obj in objs: - api.create(path, obj) + try: + api.create(path, obj) + except ick2.HttpError: + if field in obj: + obj_path = '{}/{}'.format(path, obj[field]) + api.update(path, obj) def cmd_show(self, args): token = self._new_token() |