Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_user_certificate.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 __metaclass__ = type
7
8 ANSIBLE_METADATA = {'status': ['preview'],
9 'supported_by': 'community',
10 'metadata_version': '1.1'}
11
12 DOCUMENTATION = '''
13 ---
14 module: fmgr_user_certificate
15 short_description: Configure certificate users.
16 version_added: "2.2.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 revision_note:
22 description: The change note that can be specified when an object is created or updated.
23 type: str
24 adom:
25 description: The parameter (adom) in requested url.
26 type: str
27 required: true
28 user_certificate:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 common_name:
34 aliases: ['common-name']
35 type: str
36 description: Certificate common name.
37 id:
38 type: int
39 description: Id.
40 required: true
41 issuer:
42 type: str
43 description: CA certificate used for client certificate verification.
44 name:
45 type: str
46 description: User name.
47 status:
48 type: str
49 description: Enable/disable allowing the certificate user to authenticate with the FortiGate unit.
50 choices: ['disable', 'enable']
51 type:
52 type: str
53 description: Type of certificate authentication method.
54 choices: ['single-certificate', 'trusted-issuer']
55 '''
56
57 EXAMPLES = '''
58 - name: Example playbook (generated based on argument schema)
59 hosts: fortimanagers
60 connection: httpapi
61 gather_facts: false
62 tasks:
63 - name: Configure certificate users.
64 fortinet.fortimanager.fmgr_user_certificate:
65 # workspace_locking_adom: <global or your adom name>
66 adom: <your own value>
67 state: present # <value in [present, absent]>
68 user_certificate:
69 id: 0 # Required variable, integer
70 # common_name: <string>
71 # issuer: <string>
72 # name: <string>
73 # status: <value in [disable, enable]>
74 # type: <value in [single-certificate, trusted-issuer]>
75 '''
76
77 RETURN = '''
78 meta:
79 description: The result of the request.
80 type: dict
81 returned: always
82 contains:
83 request_url:
84 description: The full url requested.
85 returned: always
86 type: str
87 sample: /sys/login/user
88 response_code:
89 description: The status of api request.
90 returned: always
91 type: int
92 sample: 0
93 response_data:
94 description: The api response.
95 type: list
96 returned: always
97 response_message:
98 description: The descriptive message of the api response.
99 type: str
100 returned: always
101 sample: OK.
102 system_information:
103 description: The information of the target system.
104 type: dict
105 returned: always
106 rc:
107 description: The status the request.
108 type: int
109 returned: always
110 sample: 0
111 version_check_warning:
112 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
113 type: list
114 returned: complex
115 '''
116 from ansible.module_utils.basic import AnsibleModule
117 from ansible.module_utils.connection import Connection
118 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
119 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
120
121
122 def main():
123 urls_list = [
124 '/pm/config/adom/{adom}/obj/user/certificate',
125 '/pm/config/global/obj/user/certificate'
126 ]
127 module_arg_spec = {
128 'adom': {'required': True, 'type': 'str'},
129 'revision_note': {'type': 'str'},
130 'user_certificate': {
131 'type': 'dict', 'v_range': [['7.0.8', '7.0.16'], ['7.2.3', '']],
132 'options': {
133 'common-name': {'v_range': [['7.0.8', '7.0.16'], ['7.2.3', '']], 'type': 'str'},
134 'id': {'v_range': [['7.0.8', '7.0.16'], ['7.2.3', '']], 'required': True, 'type': 'int'},
135 'issuer': {'v_range': [['7.0.8', '7.0.16'], ['7.2.3', '']], 'type': 'str'},
136 'name': {'v_range': [['7.0.8', '7.0.16'], ['7.2.3', '']], 'type': 'str'},
137 'status': {'v_range': [['7.0.8', '7.0.16'], ['7.2.3', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
138 'type': {'v_range': [['7.0.8', '7.0.16'], ['7.2.3', '']], 'choices': ['single-certificate', 'trusted-issuer'], 'type': 'str'}
139 }
140 }
141 }
142
143 module_option_spec = get_module_arg_spec('full crud')
144 module_arg_spec.update(module_option_spec)
145 check_galaxy_version(module_arg_spec)
146 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'user_certificate'),
147 supports_check_mode=True)
148 if not module._socket_path:
149 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
150 connection = Connection(module._socket_path)
151 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
152 'id', 'data', module, connection)
153 fmgr.process_crud()
154 module.exit_json(meta=module.params)
155
156
157 if __name__ == '__main__':
158 main()