Oleksiy Petrenko | 95664c0 | 2018-04-19 17:05:16 +0300 | [diff] [blame] | 1 | try: |
| 2 | from urllib.parse import urlencode |
| 3 | except ImportError: |
| 4 | from urllib import urlencode |
| 5 | |
| 6 | from barbicanv1.common import send, get_by_name_or_uuid |
| 7 | |
| 8 | RESOURCE_LIST_KEY = 'secrets' |
| 9 | |
| 10 | |
| 11 | @send('get') |
| 12 | def secret_list(**kwargs): |
Vasyl Saienko | 1e36a46 | 2018-06-01 12:46:18 +0300 | [diff] [blame] | 13 | url = '/secrets?{}'.format(urlencode(kwargs)) |
Oleksiy Petrenko | 95664c0 | 2018-04-19 17:05:16 +0300 | [diff] [blame] | 14 | return url, {} |
| 15 | |
| 16 | |
| 17 | @send('post') |
| 18 | def secret_create(**kwargs): |
Vasyl Saienko | 1e36a46 | 2018-06-01 12:46:18 +0300 | [diff] [blame] | 19 | url = '/secrets' |
Oleksiy Petrenko | 95664c0 | 2018-04-19 17:05:16 +0300 | [diff] [blame] | 20 | return url, {'json': kwargs} |
| 21 | |
| 22 | |
| 23 | @get_by_name_or_uuid(secret_list, RESOURCE_LIST_KEY) |
| 24 | @send('get') |
| 25 | def secret_get_details(secret_uuid, **kwargs): |
Vasyl Saienko | 1e36a46 | 2018-06-01 12:46:18 +0300 | [diff] [blame] | 26 | url = '/secrets/{}'.format(secret_uuid) |
Oleksiy Petrenko | 95664c0 | 2018-04-19 17:05:16 +0300 | [diff] [blame] | 27 | return url, {} |
| 28 | |
| 29 | |
| 30 | @get_by_name_or_uuid(secret_list, RESOURCE_LIST_KEY) |
| 31 | @send('delete') |
| 32 | def secret_delete(secret_uuid, **kwargs): |
Vasyl Saienko | 1e36a46 | 2018-06-01 12:46:18 +0300 | [diff] [blame] | 33 | url = '/secrets/{}'.format(secret_uuid) |
Oleksiy Petrenko | 95664c0 | 2018-04-19 17:05:16 +0300 | [diff] [blame] | 34 | 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') |
| 43 | def secret_payload_set(secret_uuid, payload, **kwargs): |
Vasyl Saienko | 1e36a46 | 2018-06-01 12:46:18 +0300 | [diff] [blame] | 44 | url = '/secrets/{}'.format(secret_uuid) |
Oleksiy Petrenko | 95664c0 | 2018-04-19 17:05:16 +0300 | [diff] [blame] | 45 | # 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') |
| 59 | def secret_payload_get(secret_uuid, **kwargs): |
Vasyl Saienko | 1e36a46 | 2018-06-01 12:46:18 +0300 | [diff] [blame] | 60 | url = '/secrets/{}/payload'.format(secret_uuid) |
Oleksiy Petrenko | 95664c0 | 2018-04-19 17:05:16 +0300 | [diff] [blame] | 61 | return url, {} |