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.

secrets.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from ..api import APIClient
  2. from .resource import Model, Collection
  3. class Secret(Model):
  4. """A secret."""
  5. id_attribute = 'ID'
  6. def __repr__(self):
  7. return f"<{self.__class__.__name__}: '{self.name}'>"
  8. @property
  9. def name(self):
  10. return self.attrs['Spec']['Name']
  11. def remove(self):
  12. """
  13. Remove this secret.
  14. Raises:
  15. :py:class:`docker.errors.APIError`
  16. If secret failed to remove.
  17. """
  18. return self.client.api.remove_secret(self.id)
  19. class SecretCollection(Collection):
  20. """Secrets on the Docker server."""
  21. model = Secret
  22. def create(self, **kwargs):
  23. obj = self.client.api.create_secret(**kwargs)
  24. obj.setdefault("Spec", {})["Name"] = kwargs.get("name")
  25. return self.prepare_model(obj)
  26. create.__doc__ = APIClient.create_secret.__doc__
  27. def get(self, secret_id):
  28. """
  29. Get a secret.
  30. Args:
  31. secret_id (str): Secret ID.
  32. Returns:
  33. (:py:class:`Secret`): The secret.
  34. Raises:
  35. :py:class:`docker.errors.NotFound`
  36. If the secret does not exist.
  37. :py:class:`docker.errors.APIError`
  38. If the server returns an error.
  39. """
  40. return self.prepare_model(self.client.api.inspect_secret(secret_id))
  41. def list(self, **kwargs):
  42. """
  43. List secrets. Similar to the ``docker secret ls`` command.
  44. Args:
  45. filters (dict): Server-side list filtering options.
  46. Returns:
  47. (list of :py:class:`Secret`): The secrets.
  48. Raises:
  49. :py:class:`docker.errors.APIError`
  50. If the server returns an error.
  51. """
  52. resp = self.client.api.secrets(**kwargs)
  53. return [self.prepare_model(obj) for obj in resp]