-
Notifications
You must be signed in to change notification settings - Fork 6
/
memsource_import_settings.py
155 lines (135 loc) · 3.9 KB
/
memsource_import_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: memsource_import_settings
short_description: Manage a Memsource import settings configuration
version_added: 0.0.1
description:
- Manage a Memsource import settings configuration
author: 'Yanis Guenane (@Spredzy)'
options:
input_charset:
description:
- TODO
type: str
output_charset:
description:
- TODO
type: str
zip_charset:
description:
- TODO
type: str
file_Format:
description:
- TODO
type: str
file_format_configuration:
description:
- TODO
type: dict
target_length:
description:
- TODO
type: bool
target_length_max:
description:
- TODO
type: str
target_length_percent:
description:
- TODO
type: bool
target_length_percent_value:
description:
- TODO
type: int
segmentation_rule_id:
description:
- TODO
type: int
target_segmentation_rule_id:
description:
- TODO
type: int
extends_documentation_fragment:
- ansible.memsource.memsource
requirements: [memsource]
"""
EXAMPLES = """
"""
RETURN = """
import_settings:
returned: on success
description: >
Import Settings' up to date information
type: dict
"""
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.ansible.memsource.plugins.module_utils.memsource import (
get_action,
get_default_argspec,
get_memsource_client,
)
def main():
argument_spec = get_default_argspec()
argument_spec.update(
dict(
uid=dict(type="str"),
name=dict(type="str"),
output_charset=dict(type="str"),
zip_charset=dict(type="str"),
file_format=dict(type="str"),
file_format_configuration=dict(type="dict"),
target_length=dict(type="bool"),
target_length_max=dict(type="str"),
target_length_percent=dict(type="bool"),
target_length_perence_value=dict(type="int"),
segmentation_rule_id=dict(type="int"),
target_segmentation_rule_id=dict(type="int"),
android=dict(type="dict"),
state=dict(type="str", default="present", choices=["absent", "present"]),
),
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)
_memsource = get_memsource_client(module.params)
_action = get_action(module.params)
_result = {}
import_settings = {}
if _action == "create":
file_import_settings = {}
for param in module.params:
if param not in ["uid", "state", "name", "file_format_configuraton"]:
if module.params.get(param) is not None:
_param_split = param.split("_")
_param = _param_split[0] + "".join(
x.title() for x in _param_split[1:]
)
file_import_settings.update({_param: module.params.get(param)})
file_import_settings.update(
{
module.params.get("file_format"): module.params.get(
"file_format_configuration"
)
}
)
import_settings = _memsource.create_import_settings(
module.params.get("name"), file_import_settings
)
_result.update({"changed": True})
elif _action == "read":
import_settings = _memsource.get_import_settings_by_id(module.params["uid"])
elif _action == "update":
pass
else:
res = _memsource.delete_import_settings(
module.params["uid"],
do_not_fail_on_404=True,
)
if res.status_code == 204:
_result.update({"changed": True})
_result.update({"import_settings": import_settings})
module.exit_json(**_result)
if __name__ == "__main__":
main()