blob: d85c08afc12371206b853289fff5e9a01549a7a4 [file] [log] [blame]
Oleksiy Petrenko95664c02018-04-19 17:05:16 +03001try:
2 from urllib.parse import urlencode
3except ImportError:
4 from urllib import urlencode
5
6from barbicanv1.common import send, get_by_name_or_uuid
7
8RESOURCE_LIST_KEY = 'secrets'
9
10
11@send('get')
12def secret_list(**kwargs):
Vasyl Saienko1e36a462018-06-01 12:46:18 +030013 url = '/secrets?{}'.format(urlencode(kwargs))
Oleksiy Petrenko95664c02018-04-19 17:05:16 +030014 return url, {}
15
16
17@send('post')
18def secret_create(**kwargs):
Vasyl Saienko1e36a462018-06-01 12:46:18 +030019 url = '/secrets'
Oleksiy Petrenko95664c02018-04-19 17:05:16 +030020 return url, {'json': kwargs}
21
22
23@get_by_name_or_uuid(secret_list, RESOURCE_LIST_KEY)
24@send('get')
25def secret_get_details(secret_uuid, **kwargs):
Vasyl Saienko1e36a462018-06-01 12:46:18 +030026 url = '/secrets/{}'.format(secret_uuid)
Oleksiy Petrenko95664c02018-04-19 17:05:16 +030027 return url, {}
28
29
30@get_by_name_or_uuid(secret_list, RESOURCE_LIST_KEY)
31@send('delete')
32def secret_delete(secret_uuid, **kwargs):
Vasyl Saienko1e36a462018-06-01 12:46:18 +030033 url = '/secrets/{}'.format(secret_uuid)
Oleksiy Petrenko95664c02018-04-19 17:05:16 +030034 return url, {}
35
36# NOTE::
37# ** payload get and sett requires headers passed in kwargs that describe
38# ** content type of the payload
39
40
41@get_by_name_or_uuid(secret_list, RESOURCE_LIST_KEY)
42@send('put')
43def secret_payload_set(secret_uuid, payload, **kwargs):
Vasyl Saienko1e36a462018-06-01 12:46:18 +030044 url = '/secrets/{}'.format(secret_uuid)
Oleksiy Petrenko95664c02018-04-19 17:05:16 +030045 # Work around content headers
46 content_type = 'payload_content_type'
47 content_encoding = 'payload_content_encoding'
48 headers = kwargs.get('headers', {})
49 if content_type in kwargs:
50 headers['Content-Type'] = kwargs[content_type]
51 if content_type == 'application/octet-stream':
52 headers['Content-Encoding'] = kwargs[content_encoding]
53
54 return url, {'json': payload, 'headers': headers}
55
56
57@get_by_name_or_uuid(secret_list, RESOURCE_LIST_KEY)
58@send('get')
59def secret_payload_get(secret_uuid, **kwargs):
Vasyl Saienko1e36a462018-06-01 12:46:18 +030060 url = '/secrets/{}/payload'.format(secret_uuid)
Oleksiy Petrenko95664c02018-04-19 17:05:16 +030061 return url, {}