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.

secret.py 2.8KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import base64
  2. from .. import errors
  3. from .. import utils
  4. class SecretApiMixin:
  5. @utils.minimum_version('1.25')
  6. def create_secret(self, name, data, labels=None, driver=None):
  7. """
  8. Create a secret
  9. Args:
  10. name (string): Name of the secret
  11. data (bytes): Secret data to be stored
  12. labels (dict): A mapping of labels to assign to the secret
  13. driver (DriverConfig): A custom driver configuration. If
  14. unspecified, the default ``internal`` driver will be used
  15. Returns (dict): ID of the newly created secret
  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. }
  26. if driver is not None:
  27. if utils.version_lt(self._version, '1.31'):
  28. raise errors.InvalidVersion(
  29. 'Secret driver is only available for API version > 1.31'
  30. )
  31. body['Driver'] = driver
  32. url = self._url('/secrets/create')
  33. return self._result(
  34. self._post_json(url, data=body), True
  35. )
  36. @utils.minimum_version('1.25')
  37. @utils.check_resource('id')
  38. def inspect_secret(self, id):
  39. """
  40. Retrieve secret metadata
  41. Args:
  42. id (string): Full ID of the secret to inspect
  43. Returns (dict): A dictionary of metadata
  44. Raises:
  45. :py:class:`docker.errors.NotFound`
  46. if no secret with that ID exists
  47. """
  48. url = self._url('/secrets/{0}', id)
  49. return self._result(self._get(url), True)
  50. @utils.minimum_version('1.25')
  51. @utils.check_resource('id')
  52. def remove_secret(self, id):
  53. """
  54. Remove a secret
  55. Args:
  56. id (string): Full ID of the secret to remove
  57. Returns (boolean): True if successful
  58. Raises:
  59. :py:class:`docker.errors.NotFound`
  60. if no secret with that ID exists
  61. """
  62. url = self._url('/secrets/{0}', id)
  63. res = self._delete(url)
  64. self._raise_for_status(res)
  65. return True
  66. @utils.minimum_version('1.25')
  67. def secrets(self, filters=None):
  68. """
  69. List secrets
  70. Args:
  71. filters (dict): A map of filters to process on the secrets
  72. list. Available filters: ``names``
  73. Returns (list): A list of secrets
  74. """
  75. url = self._url('/secrets')
  76. params = {}
  77. if filters:
  78. params['filters'] = utils.convert_filters(filters)
  79. return self._result(self._get(url, params=params), True)