Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.py 2.6KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import base64
  2. from .. import utils
  3. class ConfigApiMixin:
  4. @utils.minimum_version('1.30')
  5. def create_config(self, name, data, labels=None, templating=None):
  6. """
  7. Create a config
  8. Args:
  9. name (string): Name of the config
  10. data (bytes): Config data to be stored
  11. labels (dict): A mapping of labels to assign to the config
  12. templating (dict): dictionary containing the name of the
  13. templating driver to be used expressed as
  14. { name: <templating_driver_name>}
  15. Returns (dict): ID of the newly created config
  16. """
  17. if not isinstance(data, bytes):
  18. data = data.encode('utf-8')
  19. data = base64.b64encode(data)
  20. data = data.decode('ascii')
  21. body = {
  22. 'Data': data,
  23. 'Name': name,
  24. 'Labels': labels,
  25. 'Templating': templating
  26. }
  27. url = self._url('/configs/create')
  28. return self._result(
  29. self._post_json(url, data=body), True
  30. )
  31. @utils.minimum_version('1.30')
  32. @utils.check_resource('id')
  33. def inspect_config(self, id):
  34. """
  35. Retrieve config metadata
  36. Args:
  37. id (string): Full ID of the config to inspect
  38. Returns (dict): A dictionary of metadata
  39. Raises:
  40. :py:class:`docker.errors.NotFound`
  41. if no config with that ID exists
  42. """
  43. url = self._url('/configs/{0}', id)
  44. return self._result(self._get(url), True)
  45. @utils.minimum_version('1.30')
  46. @utils.check_resource('id')
  47. def remove_config(self, id):
  48. """
  49. Remove a config
  50. Args:
  51. id (string): Full ID of the config to remove
  52. Returns (boolean): True if successful
  53. Raises:
  54. :py:class:`docker.errors.NotFound`
  55. if no config with that ID exists
  56. """
  57. url = self._url('/configs/{0}', id)
  58. res = self._delete(url)
  59. self._raise_for_status(res)
  60. return True
  61. @utils.minimum_version('1.30')
  62. def configs(self, filters=None):
  63. """
  64. List configs
  65. Args:
  66. filters (dict): A map of filters to process on the configs
  67. list. Available filters: ``names``
  68. Returns (list): A list of configs
  69. """
  70. url = self._url('/configs')
  71. params = {}
  72. if filters:
  73. params['filters'] = utils.convert_filters(filters)
  74. return self._result(self._get(url, params=params), True)