-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathoidc_config_info.py
More file actions
95 lines (79 loc) · 2.63 KB
/
oidc_config_info.py
File metadata and controls
95 lines (79 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2022, XLAB Steampunk <steampunk@xlab.si>
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
__metaclass__ = type
# language=yaml
DOCUMENTATION = r"""
module: oidc_config_info
author:
- Domen Dobnikar (@domen_dobnikar)
short_description: Returns information about openID connect configuration.
description:
- Can list openID connect configuration.
- One openID connect configuration per cluster is supported.
version_added: 1.1.0
extends_documentation_fragment:
- scale_computing.hypercore.cluster_instance
seealso: []
"""
# language=yaml
EXAMPLES = r"""
- name: info OIDC config
scale_computing.hypercore.oidc_config_info:
"""
# language=yaml
RETURN = r"""
record:
description:
- OIDC config record.
returned: success
type: dict
contains:
client_id:
description: Provided by authentication server when configuring a new client
type: str
sample: d2298ec0-0596-49d2-9554-840a2fe20603
config_url:
description: The OpenID Connect Provider Configuration Information endpoint
type: str
sample: https://login.microsoftonline.com/your_uuid/v2.0/.well-known/openid-configuration
scopes:
description: Scopes required to obtain necessary claims
type: str
sample: openid+profile
"""
from typing import Optional
from typing import Tuple
from ansible.module_utils.basic import AnsibleModule
from ..module_utils import arguments
from ..module_utils import errors
from ..module_utils.client import Client
from ..module_utils.oidc import Oidc
from ..module_utils.rest_client import CachedRestClient
from ..module_utils.typed_classes import TypedOidcToAnsible
def run(module: AnsibleModule, rest_client: CachedRestClient) -> Tuple[bool, Optional[TypedOidcToAnsible]]:
oidc_list = rest_client.list_records("/rest/v1/OIDCConfig")
if oidc_list:
return False, Oidc.from_hypercore(oidc_list[0]).to_ansible()
return False, None
def main() -> None:
module = AnsibleModule(
supports_check_mode=True,
argument_spec=dict(
arguments.get_spec("cluster_instance"),
),
)
try:
with Client.get_client(module.params["cluster_instance"]) as client:
rest_client = CachedRestClient(client=client)
changed, record = run(module, rest_client)
module.exit_json(changed=changed, record=record)
except errors.ScaleComputingError as e:
module.fail_json(msg=str(e))
if __name__ == "__main__":
main()