summaryrefslogtreecommitdiff
path: root/icktool
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-10-16 21:23:39 +0300
committerLars Wirzenius <liw@liw.fi>2017-10-16 21:23:39 +0300
commit1b6b97834362ba42b7fcc5cc6f7c1d7398198ce0 (patch)
tree20b6023e337b9f349f3e7a96fb3024bbcea0f583 /icktool
parent535a1408ae09cda294bbd9895272fb336989f159 (diff)
downloadick2-1b6b97834362ba42b7fcc5cc6f7c1d7398198ce0.tar.gz
Add: icktool list-projects, create-project
Diffstat (limited to 'icktool')
-rwxr-xr-xicktool30
1 files changed, 28 insertions, 2 deletions
diff --git a/icktool b/icktool
index caff5fb..6dfed57 100755
--- a/icktool
+++ b/icktool
@@ -90,6 +90,15 @@ class Icktool(cliapp.Application):
api = self._new_api()
self._prettyson(api.get('/version'))
+ def cmd_list_projects(self, args):
+ api = self._new_api()
+ self._prettyson(api.get('/projects'))
+
+ def cmd_create_project(self, args):
+ obj = self._read_object()
+ api = self._new_api()
+ api.post('/projects', obj)
+
def _new_token(self):
scopes = self.settings['scope']
cmd = self.settings['token-private-key-cmd']
@@ -113,6 +122,9 @@ class Icktool(cliapp.Application):
json.dump(obj, sys.stdout, indent=4)
sys.stdout.write('\n')
+ def _read_object(self):
+ return json.load(sys.stdin)
+
class API:
@@ -134,13 +146,27 @@ class API:
assert self._url is not None
assert self._token is not None
- version_url = '{}/version'.format(self._url)
+ full_url = '{}/{}'.format(self._url, path)
headers = {
'Authorization': 'Bearer {}'.format(self._token),
}
- r = requests.get(version_url, headers=headers, verify=self._verify)
+ r = requests.get(full_url, headers=headers, verify=self._verify)
return r.json()
+ def post(self, path, obj):
+ assert self._url is not None
+ assert self._token is not None
+
+ full_url = '{}{}'.format(self._url, path)
+ headers = {
+ 'Authorization': 'Bearer {}'.format(self._token),
+ 'Content-Type': 'applicatin/json',
+ }
+ print('full_url:', full_url)
+ r = requests.post(
+ full_url, data=obj, headers=headers, verify=self._verify)
+ print(r.text)
+
class TokenGenerator: