Debian Codegraph @

ansible_collections/community/hashi_vault/plugins/module_utils/_auth_method_cert.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2021 Devon Mar (@devon-mar)
3 # Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
4 # SPDX-License-Identifier: BSD-2-Clause
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 from ansible_collections.community.hashi_vault.plugins.module_utils._hashi_vault_common import HashiVaultAuthMethodBase
10
11
12 class HashiVaultAuthMethodCert(HashiVaultAuthMethodBase):
13 """HashiVault option group class for auth: cert"""
14
15 NAME = "cert"
16 OPTIONS = ["cert_auth_public_key", "cert_auth_private_key", "mount_point", "role_id"]
17
18 def __init__(self, option_adapter, warning_callback, deprecate_callback):
19 super(HashiVaultAuthMethodCert, self).__init__(option_adapter, warning_callback, deprecate_callback)
20
21 def validate(self):
22 self.validate_by_required_fields("cert_auth_public_key", "cert_auth_private_key")
23
24 def authenticate(self, client, use_token=True):
25 options = self._options.get_filled_options(*self.OPTIONS)
26
27 params = {
28 "cert_pem": options["cert_auth_public_key"],
29 "key_pem": options["cert_auth_private_key"],
30 }
31
32 if "mount_point" in options:
33 params["mount_point"] = options["mount_point"]
34 if "role_id" in options:
35 params["name"] = options["role_id"]
36
37 try:
38 response = client.auth.cert.login(use_token=use_token, **params)
39 except NotImplementedError:
40 raise NotImplementedError("cert authentication requires HVAC version 0.10.12 or higher.")
41
42 return response