Debian Codegraph @

ansible_collections/theforeman/foreman/plugins/modules/http_proxy.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # (c) 2020 Evgeni Golov
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import absolute_import, division, print_function
19 __metaclass__ = type
20
21
22 DOCUMENTATION = '''
23 ---
24 module: http_proxy
25 version_added: 1.1.0
26 short_description: Manage HTTP Proxies
27 description:
28 - Create, update, and delete HTTP Proxies
29 author:
30 - "Evgeni Golov (@evgeni)"
31 options:
32 name:
33 description:
34 - The HTTP Proxy name
35 required: true
36 type: str
37 url:
38 description:
39 - URL of the HTTP Proxy
40 - Required when creating a new HTTP Proxy.
41 required: false
42 type: str
43 proxy_username:
44 description:
45 - Username used to authenticate with the HTTP Proxy
46 required: false
47 type: str
48 proxy_password:
49 description:
50 - Password used to authenticate with the HTTP Proxy
51 - When this parameter is set, the module will not be idempotent.
52 required: false
53 type: str
54 extends_documentation_fragment:
55 - theforeman.foreman.foreman
56 - theforeman.foreman.foreman.entity_state
57 - theforeman.foreman.foreman.taxonomy
58 '''
59
60 EXAMPLES = '''
61 - name: create example.org proxy
62 theforeman.foreman.http_proxy:
63 name: "example.org"
64 url: "http://example.org:3128"
65 locations:
66 - "Munich"
67 organizations:
68 - "ACME"
69 server_url: "https://foreman.example.com"
70 username: "admin"
71 password: "changeme"
72 state: present
73 '''
74
75 RETURN = '''
76 entity:
77 description: Final state of the affected entities grouped by their type.
78 returned: success
79 type: dict
80 contains:
81 http_proxies:
82 description: List of HTTP proxies.
83 type: list
84 elements: dict
85 '''
86
87 from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanTaxonomicEntityAnsibleModule
88
89
90 class ForemanHttpProxyModule(ForemanTaxonomicEntityAnsibleModule):
91 pass
92
93
94 def main():
95 module = ForemanHttpProxyModule(
96 foreman_spec=dict(
97 name=dict(required=True),
98 url=dict(),
99 proxy_username=dict(flat_name='username'),
100 proxy_password=dict(no_log=True, flat_name='password'),
101 ),
102 )
103
104 with module.api_connection():
105 entity = module.lookup_entity('entity')
106
107 if not module.desired_absent:
108 if 'url' not in module.foreman_params:
109 if not entity:
110 module.fail_json(msg="The 'url' parameter is required when creating a new HTTP Proxy.")
111 else:
112 module.foreman_params['url'] = entity['url']
113
114 module.run()
115
116
117 if __name__ == '__main__':
118 main()