diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-02-14 12:35:23 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-02-14 12:35:23 +0200 |
commit | d4d73a53266caf4ff183859f90e4a1055af44738 (patch) | |
tree | 6a362b98244c770c00319873770e34336a695742 /icktool | |
parent | 6fd66490f2cc23cb0d95a52486b72b7ec55d81ba (diff) | |
download | ick2-d4d73a53266caf4ff183859f90e4a1055af44738.tar.gz |
Fix: icktool to get blob service URL from controller
Diffstat (limited to 'icktool')
-rwxr-xr-x | icktool | 40 |
1 files changed, 25 insertions, 15 deletions
@@ -113,13 +113,10 @@ class Icktool(cliapp.Application): def cmd_version(self, args): api = self._new_api() - code, text = api.get('/version') - if code != 200: - sys.stderr.write('HTTP status {}\n'.format(code)) - sys.stderr.write(text) + version = api.get_version() + if not version: sys.exit(1) - obj = json.loads(text) - self._prettyson(obj) + self._prettyson(version) def cmd_status(self, args): rows = [] @@ -323,10 +320,11 @@ class Icktool(cliapp.Application): def cmd_get_blob(self, args): blob_id = args[0] - blob_api = self._new_blob_api() + api = self._new_api() + blob_api = self._new_blob_api(api) status_code, blob = blob_api.get(blob_id) if status_code == 200: - filename = self.settings['output'] or '/dev/stdout' + filename = self.settings['output'] with open(filename, 'wb') as f: f.write(blob) else: @@ -335,7 +333,8 @@ class Icktool(cliapp.Application): def cmd_put_blob(self, args): blob_id = args[0] blob = sys.stdin.read() - blob_api = self._new_blob_api() + api = self._new_api() + blob_api = self._new_blob_api(api) code, text = blob_api.put(blob_id, blob) if code != 200: sys.exit(text) @@ -361,13 +360,13 @@ class Icktool(cliapp.Application): api.set_verify(self.settings['verify-tls']) return api - def _new_blob_api(self): + def _new_blob_api(self, api): token = self.settings['token'] or self._new_token() - api = BlobAPI() - api.set_token(token) - api.set_url(self.settings['controller']) - api.set_verify(self.settings['verify-tls']) - return api + blob_api = BlobAPI() + blob_api.set_token(token) + blob_api.set_url(api.get_blob_service_url()) + blob_api.set_verify(self.settings['verify-tls']) + return blob_api def _new_rc(self, path, field_name): api = self._new_api() @@ -425,6 +424,16 @@ class API: def set_verify(self, verify): self._verify = verify + def get_version(self): + code, text = self.get('/version') + if code == 200: + return json.loads(text) + + def get_blob_service_url(self): + version = self.get_version() + if version: + return version.get('blob_service') + def get(self, path): assert self._url is not None assert self._token is not None @@ -498,6 +507,7 @@ class BlobAPI: 'Authorization': 'Bearer {}'.format(self._token), } r = requests.get(full_url, headers=headers, verify=self._verify) + print('blob length', len(r.content)) return r.status_code, r.content def put(self, blob_id, blob): |