Debian Codegraph @

ansible_collections/community/grafana/plugins/module_utils/base.py

raw
1 # -*- coding: utf-8 -*-
2 # This file is part of Ansible
3 #
4 # Ansible is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # Ansible is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # Copyright: (c) 2019, Rémi REY (@rrey)
18
19 from __future__ import absolute_import, division, print_function
20 from ansible.module_utils.urls import url_argument_spec
21
22 __metaclass__ = type
23
24
25 def clean_url(url):
26 return url.rstrip("/")
27
28
29 def grafana_argument_spec():
30 argument_spec = url_argument_spec()
31
32 del argument_spec["force"]
33 del argument_spec["force_basic_auth"]
34 del argument_spec["http_agent"]
35 # Avoid sanity error with devel
36 if "use_gssapi" in argument_spec:
37 del argument_spec["use_gssapi"]
38
39 argument_spec.update(
40 state=dict(choices=["present", "absent"], default="present"),
41 url=dict(aliases=["grafana_url"], type="str", required=True),
42 grafana_api_key=dict(type="str", no_log=True),
43 url_username=dict(aliases=["grafana_user"], default="admin"),
44 url_password=dict(aliases=["grafana_password"], default="admin", no_log=True),
45 )
46 return argument_spec
47
48
49 def grafana_required_together():
50 return [["url_username", "url_password"]]
51
52
53 def grafana_mutually_exclusive():
54 return [["url_username", "grafana_api_key"]]
55
56
57 def parse_grafana_version(version):
58 version, sep, build_meta = version.partition("+")
59 version, sep, pre_release = version.partition("-")
60 major, minor, rev = version.split(".")
61 return {
62 "major": int(major),
63 "minor": int(minor),
64 "rev": int(rev),
65 "pre_release": pre_release,
66 "build_meta": build_meta,
67 }