Skip to content

Commit 788ce67

Browse files
authored
Storagebox: deprecate hetzner_user, deprecate compatibility shim return values (#178)
* Deprecate hetzner_user and hetzner_pass parameters; deprecate hetzner_token not being required; deprecate membership of robot action group. * Add new rate limiting tests. * Deprecate old return values. * Work around bug in ansible-test's pylint check. Ref: ansible/ansible#85614
1 parent 54954d3 commit 788ce67

15 files changed

+505
-56
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
deprecated_features:
2+
- "storagebox\\* modules - the ``hetzner_user`` and ``hetzner_pass`` options for these modules are deprecated; support will be removed in community.hrobot 3.0.0. Use ``hetzner_token`` instead (https://github.com/ansible-collections/community.hrobot/pull/178)."
3+
- "storagebox\\* modules - the ``hetzner_token`` option for these modules will be required from community.hrobot 3.0.0 on (https://github.com/ansible-collections/community.hrobot/pull/178)."
4+
- "storagebox\\* modules - membership in the ``community.hrobot.robot`` action group (module defaults group) is deprecated; the modules will be removed from the group in community.hrobot 3.0.0. Use ``community.hrobot.api`` instead (https://github.com/ansible-collections/community.hrobot/pull/178)."
5+
- "storagebox_info - the ``storageboxes[].login``, ``storageboxes[].disk_quota``, ``storageboxes[].disk_usage``, ``storageboxes[].disk_usage_data``, ``storageboxes[].disk_usage_snapshot``, ``storageboxes[].webdav``, ``storageboxes[].samba``, ``storageboxes[].ssh``, ``storageboxes[].external_reachability``, and ``storageboxes[].zfs`` return values are deprecated and will be removed from community.routeros. Check out the documentation to find out their new names according to the new API (https://github.com/ansible-collections/community.hrobot/pull/178)."
6+
- "storagebox_snapshot_info - the ``snapshots[].timestamp``, ``snapshots[].size``, ``snapshots[].filesystem_size``, ``snapshots[].automatic``, and ``snapshots[].comment`` return values are deprecated and will be removed from community.routeros. Check out the documentation to find out their new names according to the new API (https://github.com/ansible-collections/community.hrobot/pull/178)."
7+
- "storagebox_snapshot_plan - the ``plans[].month`` return value is deprecated, since it only returns ``null`` with the new API and cannot be set to any other value (https://github.com/ansible-collections/community.hrobot/pull/178)."
8+
- "storagebox_snapshot_plan_info - the ``plans[].month`` return value is deprecated, since it only returns ``null`` with the new API and cannot be set to any other value (https://github.com/ansible-collections/community.hrobot/pull/178)."
9+
- "storagebox_subaccount - the ``subaccount.homedirectory``, ``subaccount.samba``, ``subaccount.ssh``, ``subaccount.external_reachability``, ``subaccount.webdav``, ``subaccount.readonly``, ``subaccount.createtime``, and ``subaccount.comment`` return values are deprecated and will be removed from community.routeros. Check out the documentation to find out their new names according to the new API (https://github.com/ansible-collections/community.hrobot/pull/178)."
10+
- "storagebox_subaccount_info - the ``subaccounts[].accountid``, ``subaccounts[].homedirectory``, ``subaccounts[].samba``, ``subaccounts[].ssh``, ``subaccounts[].external_reachability``, ``subaccounts[].webdav``, ``subaccounts[].readonly``, ``subaccounts[].createtime``, and ``subaccounts[].comment`` return values are deprecated and will be removed from community.routeros. Check out the documentation to find out their new names according to the new API (https://github.com/ansible-collections/community.hrobot/pull/178)."

plugins/doc_fragments/api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,27 @@ class ModuleDocFragment(object):
4747
- If O(hetzner_password) is specified, O(hetzner_user) must also be specified, and O(hetzner_token) must not be specified.
4848
required: false
4949
"""
50+
51+
# Only for transition period
52+
_ROBOT_COMPAT_SHIM_DEPRECATION = r"""
53+
options:
54+
hetzner_token:
55+
description:
56+
- The API token for the Robot web-service user.
57+
- One of O(hetzner_token) and O(hetzner_user) must be specified.
58+
- This option will be required from community.hrobot 3.0.0 on.
59+
required: false
60+
hetzner_user:
61+
description:
62+
- The username for the Robot web-service user.
63+
- One of O(hetzner_token) and O(hetzner_user) must be specified.
64+
- If O(hetzner_user) is specified, O(hetzner_password) must also be specified, and O(hetzner_token) must not be specified.
65+
- This option is deprecated for this module, and support will be removed in community.hrobot 3.0.0.
66+
required: false
67+
hetzner_password:
68+
description:
69+
- The password for the Robot web-service user.
70+
- If O(hetzner_password) is specified, O(hetzner_user) must also be specified, and O(hetzner_token) must not be specified.
71+
- This option is deprecated for this module, and support will be removed in community.hrobot 3.0.0.
72+
required: false
73+
"""

plugins/doc_fragments/attributes.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ class ModuleDocFragment(object):
8080
- community.hrobot.robot
8181
'''
8282

83+
# Only for transition period
84+
_ACTIONGROUP_ROBOT_AND_API_DEPRECATION = r'''
85+
options: {}
86+
attributes:
87+
action_group:
88+
description:
89+
- Use C(group/community.hrobot.robot) or C(group/community.hrobot.api) in C(module_defaults) to set defaults for this module.
90+
- The C(group/community.hrobot.robot) group is B(deprecated) for this module; the module will be removed from the group in community.hrobot 3.0.0.
91+
support: full
92+
membership:
93+
- community.hrobot.api
94+
- community.hrobot.robot
95+
'''
96+
8397
CONN = r"""
8498
options: {}
8599
attributes:

plugins/module_utils/_tagging.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright (c) 2025 Felix Fontein <[email protected]>
4+
# This code is licensed under the following two licenses:
5+
# - Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
6+
# - GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
7+
# SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later
8+
9+
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
10+
# Do not use this from other collections or standalone plugins/modules!
11+
12+
from __future__ import absolute_import, division, print_function
13+
__metaclass__ = type
14+
15+
16+
try:
17+
from ansible.module_utils.datatag import deprecate_value as _deprecate_value
18+
HAS_DEPRECATE_VALUE = True
19+
except ImportError:
20+
HAS_DEPRECATE_VALUE = False
21+
22+
23+
def deprecate_value(value, msg, version, help_text=None):
24+
"""
25+
Given a value, tag it as deprecated (with message, removal version, and optional help text).
26+
27+
For ansible-core versions that do not support data tagging, simply returns the value as-is.
28+
"""
29+
if not HAS_DEPRECATE_VALUE:
30+
return value
31+
# Assign this to a variable to work around a bug in ansible-test's pylint check (https://github.com/ansible/ansible/issues/85614)
32+
collection_name = "community.hrobot"
33+
return _deprecate_value(
34+
value,
35+
msg,
36+
collection_name=collection_name,
37+
version=version,
38+
help_text=help_text,
39+
)

plugins/module_utils/robot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
hetzner_password=dict(type='str', required=False, no_log=True),
3434
)
3535

36+
_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT_DEPRECATED = dict(
37+
hetzner_user=dict(type='str', required=False, removed_in_version="3.0.0", removed_from_collection="community.hrobot"),
38+
hetzner_password=dict(type='str', required=False, no_log=True, removed_in_version="3.0.0", removed_from_collection="community.hrobot"),
39+
)
40+
41+
3642
# The API endpoint is fixed.
3743
BASE_URL = "https://robot-ws.your-server.de"
3844

plugins/modules/storagebox.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
description:
1919
- Modify a storage box's basic configuration.
2020
extends_documentation_fragment:
21-
- community.hrobot.api._robot_compat_shim # must come before api and robot
21+
- community.hrobot.api._robot_compat_shim_deprecation # must come before api and robot
2222
- community.hrobot.api
2323
- community.hrobot.robot
2424
- community.hrobot.attributes
25-
- community.hrobot.attributes._actiongroup_robot_and_api # must come before the other two!
25+
- community.hrobot.attributes._actiongroup_robot_and_api_deprecation # must come before the other two!
2626
- community.hrobot.attributes.actiongroup_api
2727
- community.hrobot.attributes.actiongroup_robot
2828
attributes:
@@ -126,7 +126,7 @@
126126
from ansible_collections.community.hrobot.plugins.module_utils.robot import (
127127
BASE_URL,
128128
ROBOT_DEFAULT_ARGUMENT_SPEC,
129-
_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT,
129+
_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT_DEPRECATED,
130130
fetch_url_json,
131131
)
132132

@@ -199,7 +199,7 @@ def main():
199199
zfs=dict(type='bool'),
200200
)
201201
argument_spec.update(ROBOT_DEFAULT_ARGUMENT_SPEC)
202-
argument_spec.update(_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT)
202+
argument_spec.update(_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT_DEPRECATED)
203203
argument_spec.update(API_DEFAULT_ARGUMENT_SPEC)
204204
argument_spec.update(_API_DEFAULT_ARGUMENT_SPEC_COMPAT)
205205
module = AnsibleModule(
@@ -216,6 +216,11 @@ def main():
216216
changes = {}
217217

218218
if module.params["hetzner_user"] is not None:
219+
module.deprecate(
220+
"The hetzner_token parameter will be required from community.hrobot 3.0.0 on.",
221+
collection_name="community.hrobot",
222+
version="3.0.0",
223+
)
219224
# DEPRECATED: old API
220225
url = "{0}/storagebox/{1}".format(BASE_URL, storagebox_id)
221226
result, error = fetch_url_json(module, url, accept_errors=['STORAGEBOX_NOT_FOUND'])

plugins/modules/storagebox_info.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
description:
1919
- Query information on one or more storage box.
2020
extends_documentation_fragment:
21-
- community.hrobot.api._robot_compat_shim # must come before api and robot
21+
- community.hrobot.api._robot_compat_shim_deprecation # must come before api and robot
2222
- community.hrobot.api
2323
- community.hrobot.robot
2424
- community.hrobot.attributes
25-
- community.hrobot.attributes._actiongroup_robot_and_api # must come before the other two!
25+
- community.hrobot.attributes._actiongroup_robot_and_api_deprecation # must come before the other two!
2626
- community.hrobot.attributes.actiongroup_api
2727
- community.hrobot.attributes.actiongroup_robot
2828
- community.hrobot.attributes.idempotent_not_modify_state
@@ -88,6 +88,8 @@
8888
description:
8989
- The storage box's login name.
9090
- Note that this is copied from RV(storageboxes[].username) in case O(hetzner_token) is specified.
91+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
92+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
9193
type: str
9294
sample: u12345
9395
returned: success
@@ -200,62 +202,80 @@
200202
description:
201203
- Total amount of MB available.
202204
- Note that this is copied from RV(storageboxes[].storage_box_type.size) in case O(hetzner_token) is specified.
205+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
206+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
203207
type: int
204208
sample: 10240000
205209
returned: when O(full_info=true), or O(hetzner_token) is specified
206210
disk_usage:
207211
description:
208212
- The amount of MB in use.
209213
- Note that this is copied from RV(storageboxes[].stats.size) in case O(hetzner_token) is specified.
214+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
215+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
210216
type: int
211217
sample: 900
212218
returned: when O(full_info=true), or O(hetzner_token) is specified
213219
disk_usage_data:
214220
description:
215221
- The amount of MB used by files.
216222
- Note that this is copied from RV(storageboxes[].stats.size_data) in case O(hetzner_token) is specified.
223+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
224+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
217225
type: int
218226
sample: 500
219227
returned: when O(full_info=true), or O(hetzner_token) is specified
220228
disk_usage_snapshots:
221229
description:
222230
- The amount of MB used by snapshots.
223231
- Note that this is copied from RV(storageboxes[].stats.size_snapshots) in case O(hetzner_token) is specified.
232+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
233+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
224234
type: int
225235
sample: 400
226236
returned: when O(full_info=true), or O(hetzner_token) is specified
227237
webdav:
228238
description:
229239
- Whether WebDAV is active.
230240
- Note that this is copied from RV(storageboxes[].access_settings.webdav_enabled) in case O(hetzner_token) is specified.
241+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
242+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
231243
type: bool
232244
sample: true
233245
returned: when O(full_info=true), or O(hetzner_token) is specified
234246
samba:
235247
description:
236248
- Whether SAMBA is active.
237249
- Note that this is copied from RV(storageboxes[].access_settings.samba_enabled) in case O(hetzner_token) is specified.
250+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
251+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
238252
type: bool
239253
sample: true
240254
returned: when O(full_info=true), or O(hetzner_token) is specified
241255
ssh:
242256
description:
243257
- Whether SSH is active.
244258
- Note that this is copied from RV(storageboxes[].access_settings.ssh_enabled) in case O(hetzner_token) is specified.
259+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
260+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
245261
type: bool
246262
sample: true
247263
returned: when O(full_info=true), or O(hetzner_token) is specified
248264
external_reachability:
249265
description:
250266
- Whether the storage box is reachable externally.
251267
- Note that this is copied from RV(storageboxes[].access_settings.reachable_externally) in case O(hetzner_token) is specified.
268+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
269+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
252270
type: bool
253271
sample: true
254272
returned: when O(full_info=true), or O(hetzner_token) is specified
255273
zfs:
256274
description:
257275
- Shows whether the ZFS directory is visible.
258276
- Note that this is copied from RV(storageboxes[].access_settings.zfs_enabled) in case O(hetzner_token) is specified.
277+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
278+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value when using O(hetzner_token).
259279
type: bool
260280
sample: false
261281
returned: when O(full_info=true), or O(hetzner_token) is specified
@@ -521,7 +541,7 @@
521541
from ansible_collections.community.hrobot.plugins.module_utils.robot import (
522542
BASE_URL,
523543
ROBOT_DEFAULT_ARGUMENT_SPEC,
524-
_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT,
544+
_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT_DEPRECATED,
525545
fetch_url_json,
526546
)
527547

@@ -533,6 +553,10 @@
533553
api_fetch_url_json_list,
534554
)
535555

556+
from ansible_collections.community.hrobot.plugins.module_utils._tagging import (
557+
deprecate_value,
558+
)
559+
536560
try:
537561
from urllib.parse import urlencode
538562
except ImportError:
@@ -560,7 +584,11 @@ def add_hrobot_compat_shim(storagebox):
560584
value = storagebox
561585
for src in source:
562586
value = value[src]
563-
result[dest] = value
587+
result[dest] = deprecate_value(
588+
value,
589+
"The return value `{0}` is deprecated; use `{1}` instead.".format(dest, ".".join(source)),
590+
version="3.0.0",
591+
)
564592
return result
565593

566594

@@ -571,7 +599,7 @@ def main():
571599
full_info=dict(type='bool', default=False),
572600
)
573601
argument_spec.update(ROBOT_DEFAULT_ARGUMENT_SPEC)
574-
argument_spec.update(_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT)
602+
argument_spec.update(_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT_DEPRECATED)
575603
argument_spec.update(API_DEFAULT_ARGUMENT_SPEC)
576604
argument_spec.update(_API_DEFAULT_ARGUMENT_SPEC_COMPAT)
577605
module = AnsibleModule(
@@ -588,6 +616,11 @@ def main():
588616

589617
storageboxes = []
590618
if module.params["hetzner_user"] is not None:
619+
module.deprecate(
620+
"The hetzner_token parameter will be required from community.hrobot 3.0.0 on.",
621+
collection_name="community.hrobot",
622+
version="3.0.0",
623+
)
591624
# DEPRECATED: old API
592625
if storagebox_id is not None:
593626
storagebox_ids = [storagebox_id]

plugins/modules/storagebox_set_password.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
description:
1818
- (Re)set the password for a storage box.
1919
extends_documentation_fragment:
20-
- community.hrobot.api._robot_compat_shim # must come before api and robot
20+
- community.hrobot.api._robot_compat_shim_deprecation # must come before api and robot
2121
- community.hrobot.api
2222
- community.hrobot.robot
2323
- community.hrobot.attributes
24-
- community.hrobot.attributes._actiongroup_robot_and_api # must come before the other two!
24+
- community.hrobot.attributes._actiongroup_robot_and_api_deprecation # must come before the other two!
2525
- community.hrobot.attributes.actiongroup_api
2626
- community.hrobot.attributes.actiongroup_robot
2727
@@ -85,7 +85,7 @@
8585
from ansible_collections.community.hrobot.plugins.module_utils.robot import (
8686
BASE_URL,
8787
ROBOT_DEFAULT_ARGUMENT_SPEC,
88-
_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT,
88+
_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT_DEPRECATED,
8989
fetch_url_json,
9090
)
9191

@@ -110,7 +110,7 @@ def main():
110110
password=dict(type="str", no_log=True),
111111
)
112112
argument_spec.update(ROBOT_DEFAULT_ARGUMENT_SPEC)
113-
argument_spec.update(_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT)
113+
argument_spec.update(_ROBOT_DEFAULT_ARGUMENT_SPEC_COMPAT_DEPRECATED)
114114
argument_spec.update(API_DEFAULT_ARGUMENT_SPEC)
115115
argument_spec.update(_API_DEFAULT_ARGUMENT_SPEC_COMPAT)
116116
module = AnsibleModule(
@@ -123,6 +123,11 @@ def main():
123123
password = module.params.get("password")
124124

125125
if module.params["hetzner_user"] is not None:
126+
module.deprecate(
127+
"The hetzner_token parameter will be required from community.hrobot 3.0.0 on.",
128+
collection_name="community.hrobot",
129+
version="3.0.0",
130+
)
126131
# DEPRECATED: old API
127132
url = "{0}/storagebox/{1}/password".format(BASE_URL, id)
128133
accepted_errors = ["STORAGEBOX_NOT_FOUND", "STORAGEBOX_INVALID_PASSWORD"]

0 commit comments

Comments
 (0)