def get_secrets(self, domain, name, reverse=False): # type: (str, str) -> List[Secret] """Get all secrets of a specific type for a domain. The resulting list of secrets is sorted based on secret versions from lowest to highest. :param str domain: Secret domain. :param str name: Secret name. :param bool reverse: Sort the Secrets in reverse order. :return: A list of secrets. :rtype: List[Secret] """ f = {} f[SecretUtils.L_MANAGED] = lambda x: x == "true" f[SecretUtils.L_DOMAIN] = lambda x: x == domain f[SecretUtils.L_NAME] = lambda x: x == name f[SecretUtils.L_VERSION] = lambda x: x is not None f[SecretUtils.L_FINGERPRINT] = lambda x: x is not None s = self.docker_client.secrets.list() s = SecretUtils.filter_secrets(s, f) s = SecretUtils.sort_secrets( s, SecretUtils.L_VERSION, reverse ) return s
def test_sort_secrets_different_default(self, secrets): a, b, c, d = [secrets[x] for x in sorted(secrets)] res = SecretUtils.sort_secrets( [a, b, c, d], SecretUtils.L_VERSION, reverse=True, default="100" ) assert res == [a, b, c, d] res = SecretUtils.sort_secrets( [a, b, c, d], SecretUtils.L_VERSION, reverse=True, default="-1" ) assert res == [d, a, b, c]
def test_sort_secrets(self, secrets): a, b, c, d = [secrets[x] for x in sorted(secrets)] res = SecretUtils.sort_secrets( [a, b, c], SecretUtils.L_VERSION, reverse=False, default=None ) assert res == [a, b, c]
def test_sort_secrets_reverse(self, secrets): a, b, c, d = [secrets[x] for x in sorted(secrets)] # Case 1 res = SecretUtils.sort_secrets( [a, b, c], SecretUtils.L_VERSION, reverse=True, default=None ) assert res == [c, b, a]