diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-04-09 19:44:05 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-04-09 19:44:05 +0300 |
commit | ffc0cf5a24800d3ccf259c37f6d880da41a6ffe8 (patch) | |
tree | dabc9458c496eaf9dc9a47f4dbd83337a1616986 | |
parent | e9fa2085be5a6fa7a56cea506680041aea6ceb07 (diff) | |
download | ick2-ffc0cf5a24800d3ccf259c37f6d880da41a6ffe8.tar.gz |
Change: icktool make-it-so updates existing resources
-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() |