Skip to content

Commit 93cb64b

Browse files
Migrated User-related list module to new framework (#578)
* Migrated user list module * Fixed docs
1 parent c718506 commit 93cb64b

File tree

3 files changed

+26
-86
lines changed

3 files changed

+26
-86
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Name | Description |
109109
[linode.cloud.stackscript_list](./docs/modules/stackscript_list.md)|List and filter on StackScripts.|
110110
[linode.cloud.token_list](./docs/modules/token_list.md)|List and filter on Tokens.|
111111
[linode.cloud.type_list](./docs/modules/type_list.md)|List and filter on Types.|
112-
[linode.cloud.user_list](./docs/modules/user_list.md)|List Users.|
112+
[linode.cloud.user_list](./docs/modules/user_list.md)|List and filter on Users.|
113113
[linode.cloud.vlan_list](./docs/modules/vlan_list.md)|List and filter on Linode VLANs.|
114114
[linode.cloud.volume_list](./docs/modules/volume_list.md)|List and filter on Linode Volumes.|
115115
[linode.cloud.vpc_ip_list](./docs/modules/vpc_ip_list.md)|List and filter on VPC IP Addresses.|

docs/modules/user_list.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# user_list
22

3-
List Users.
3+
List and filter on Users.
44

55
- [Minimum Required Fields](#minimum-required-fields)
66
- [Examples](#examples)
@@ -24,12 +24,21 @@ List Users.
2424
2525
| Field | Type | Required | Description |
2626
|-----------|------|----------|------------------------------------------------------------------------------|
27-
| `order` | <center>`str`</center> | <center>Optional</center> | The order to list users in. **(Choices: `desc`, `asc`; Default: `asc`)** |
28-
| `count` | <center>`int`</center> | <center>Optional</center> | The number of results to return. If undefined, all results will be returned. |
27+
| `order` | <center>`str`</center> | <center>Optional</center> | The order to list Users in. **(Choices: `desc`, `asc`; Default: `asc`)** |
28+
| `order_by` | <center>`str`</center> | <center>Optional</center> | The attribute to order Users by. |
29+
| [`filters` (sub-options)](#filters) | <center>`list`</center> | <center>Optional</center> | A list of filters to apply to the resulting Users. |
30+
| `count` | <center>`int`</center> | <center>Optional</center> | The number of Users to return. If undefined, all results will be returned. |
31+
32+
### filters
33+
34+
| Field | Type | Required | Description |
35+
|-----------|------|----------|------------------------------------------------------------------------------|
36+
| `name` | <center>`str`</center> | <center>**Required**</center> | The name of the field to filter on. Valid filterable fields can be found [here](https://techdocs.akamai.com/linode-api/reference/get-users). |
37+
| `values` | <center>`list`</center> | <center>**Required**</center> | A list of values to allow for this field. Fields will pass this filter if at least one of these values matches. |
2938

3039
## Return Values
3140

32-
- `users` - The returned users.
41+
- `users` - The returned Users.
3342

3443
- Sample Response:
3544
```json
@@ -47,6 +56,6 @@ List Users.
4756
}
4857
]
4958
```
50-
- See the [Linode API response documentation](https://techdocs.akamai.com/linode-api/reference/get-account) for a list of returned fields
59+
- See the [Linode API response documentation](https://techdocs.akamai.com/linode-api/reference/get-users) for a list of returned fields
5160

5261

plugins/modules/user_list.py

+11-80
Original file line numberDiff line numberDiff line change
@@ -4,97 +4,28 @@
44
"""This module allows users to list Users."""
55
from __future__ import absolute_import, division, print_function
66

7-
from typing import Any, Dict, Optional
8-
97
import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.user_list as docs
10-
from ansible_collections.linode.cloud.plugins.module_utils.linode_common import (
11-
LinodeModuleBase,
12-
)
13-
from ansible_collections.linode.cloud.plugins.module_utils.linode_docs import (
14-
global_authors,
15-
global_requirements,
16-
)
17-
from ansible_collections.linode.cloud.plugins.module_utils.linode_helper import (
18-
get_all_paginated,
19-
)
20-
from ansible_specdoc.objects import (
21-
FieldType,
22-
SpecDocMeta,
23-
SpecField,
24-
SpecReturnValue,
8+
from ansible_collections.linode.cloud.plugins.module_utils.linode_common_list import (
9+
ListModule,
2510
)
2611

27-
spec = {
28-
# Disable the default values
29-
"state": SpecField(type=FieldType.string, required=False, doc_hide=True),
30-
"label": SpecField(type=FieldType.string, required=False, doc_hide=True),
31-
"order": SpecField(
32-
type=FieldType.string,
33-
description=["The order to list users in."],
34-
default="asc",
35-
choices=["desc", "asc"],
36-
),
37-
"count": SpecField(
38-
type=FieldType.integer,
39-
description=[
40-
"The number of results to return.",
41-
"If undefined, all results will be returned.",
42-
],
43-
),
44-
}
45-
46-
SPECDOC_META = SpecDocMeta(
47-
description=["List Users."],
48-
requirements=global_requirements,
49-
author=global_authors,
50-
options=spec,
12+
module = ListModule(
13+
result_display_name="Users",
14+
result_field_name="users",
15+
endpoint_template="/account/users",
16+
result_docs_url="https://techdocs.akamai.com/linode-api/reference/get-users",
5117
examples=docs.specdoc_examples,
52-
return_values={
53-
"users": SpecReturnValue(
54-
description="The returned users.",
55-
docs_url=(
56-
"https://techdocs.akamai.com/linode-api/reference/get-account"
57-
),
58-
type=FieldType.list,
59-
elements=FieldType.dict,
60-
sample=docs.result_users_samples,
61-
)
62-
},
18+
result_samples=docs.result_users_samples,
6319
)
6420

21+
SPECDOC_META = module.spec
22+
6523
DOCUMENTATION = r"""
6624
"""
6725
EXAMPLES = r"""
6826
"""
6927
RETURN = r"""
7028
"""
7129

72-
73-
class Module(LinodeModuleBase):
74-
"""Module for getting a list of Users"""
75-
76-
def __init__(self) -> None:
77-
self.module_arg_spec = SPECDOC_META.ansible_spec
78-
self.results: Dict[str, Any] = {"users": []}
79-
80-
super().__init__(module_arg_spec=self.module_arg_spec)
81-
82-
def exec_module(self, **kwargs: Any) -> Optional[dict]:
83-
"""Entrypoint for user module"""
84-
85-
self.results["users"] = get_all_paginated(
86-
self.client,
87-
"/account/users",
88-
None,
89-
num_results=self.module.params["count"],
90-
)
91-
return self.results
92-
93-
94-
def main() -> None:
95-
"""Constructs and calls the module"""
96-
Module()
97-
98-
9930
if __name__ == "__main__":
100-
main()
31+
module.run()

0 commit comments

Comments
 (0)