Skip to content

Commit fa0c769

Browse files
committed
chore: lint python files with Ruff
1 parent 857c862 commit fa0c769

File tree

10 files changed

+98
-115
lines changed

10 files changed

+98
-115
lines changed

.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore = ["E402"]

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ repository: https://github.com/Devolutions/ansible-dvls
1616
documentation: https://github.com/Devolutions/ansible-dvls
1717
homepage: https://github.com/Devolutions/ansible-dvls
1818
issues: https://github.com/Devolutions/ansible-dvls/issues
19-
build_ignore: [.github, requirements.txt, tests]
19+
build_ignore: [.github, .ruff.toml, requirements.txt, tests]

plugins/module_utils/auth.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
import requests
22
import json
33

4+
45
def login(server_base_url, app_key, app_secret):
56
login_url = f"{server_base_url}/api/v1/login"
6-
login_data = {
7-
"appKey": app_key,
8-
"appSecret": app_secret
9-
}
10-
login_headers = {
11-
"Content-Type": "application/json"
12-
}
7+
login_data = {"appKey": app_key, "appSecret": app_secret}
8+
login_headers = {"Content-Type": "application/json"}
139

1410
try:
15-
response = requests.post(login_url, headers=login_headers, data=json.dumps(login_data))
11+
response = requests.post(
12+
login_url, headers=login_headers, data=json.dumps(login_data)
13+
)
1614
response.raise_for_status()
1715
except Exception as e:
18-
raise Exception(f"Failed to login: Unable to reach the server. Verify your network connection and server URL: {e}")
16+
raise Exception(
17+
f"Failed to login: Unable to reach the server. Verify your network connection and server URL: {e}"
18+
)
1919

2020
auth_response = response.json()
21-
token = auth_response.get('tokenId')
21+
token = auth_response.get("tokenId")
2222

2323
if not token or token == "null":
2424
raise Exception("Failed to login or obtain token.")
2525

2626
return token
2727

28+
2829
def logout(server_base_url, token):
2930
logout_url = f"{server_base_url}/api/v1/logout"
30-
logout_headers = {
31-
"Content-Type": "application/json",
32-
"tokenId": token
33-
}
31+
logout_headers = {"Content-Type": "application/json", "tokenId": token}
3432

3533
requests.post(logout_url, headers=logout_headers)
3634
return None

plugins/module_utils/server.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import requests
22

3+
34
def public_instance_information(server_base_url, token):
45
url = f"{server_base_url}/api/public-instance-information"
5-
headers = {
6-
"Content-Type": "application/json",
7-
"tokenId": token
8-
}
6+
headers = {"Content-Type": "application/json", "tokenId": token}
97

108
try:
119
response = requests.get(url, headers=headers)
1210
return response.json()
1311
except Exception as e:
14-
raise Exception(f"An error occurred while fetching public instance information: {e}")
12+
raise Exception(
13+
f"An error occurred while fetching public instance information: {e}"
14+
)
15+
1516

1617
def private_instance_information(server_base_url, token):
1718
url = f"{server_base_url}/api/private-instance-information"
18-
headers = {
19-
"Content-Type": "application/json",
20-
"tokenId": token
21-
}
19+
headers = {"Content-Type": "application/json", "tokenId": token}
2220

2321
try:
2422
response = requests.get(url, headers=headers)
2523
response.raise_for_status()
2624
return response.json()
2725
except Exception as e:
28-
raise Exception(f"An error occurred while fetching private instance information: {e}")
26+
raise Exception(
27+
f"An error occurred while fetching private instance information: {e}"
28+
)

plugins/module_utils/utils.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from ansible_collections.devolutions.dvls.plugins.module_utils.vaults import get_vault_entry
1+
from ansible_collections.devolutions.dvls.plugins.module_utils.vaults import (
2+
get_vault_entry,
3+
)
4+
25

36
def get_sensible_value(server_base_url, token, vault_id, entries):
47
fetched_secrets = {}
58

6-
if isinstance(entries, dict) and 'data' in entries:
7-
entries = entries.get('data', [])
9+
if isinstance(entries, dict) and "data" in entries:
10+
entries = entries.get("data", [])
811

912
if not isinstance(entries, list):
1013
return {"error": f"Expected list of entries, got {type(entries).__name__}"}
@@ -13,14 +16,14 @@ def get_sensible_value(server_base_url, token, vault_id, entries):
1316
if not isinstance(secret, dict):
1417
continue
1518

16-
entry_name = secret.get('name')
17-
if not entry_name or 'id' not in secret:
19+
entry_name = secret.get("name")
20+
if not entry_name or "id" not in secret:
1821
continue
1922

2023
try:
21-
entry = get_vault_entry(server_base_url, token, vault_id, secret['id'])
22-
if isinstance(entry, dict) and 'data' in entry:
23-
fetched_secrets[entry_name] = entry['data']
24+
entry = get_vault_entry(server_base_url, token, vault_id, secret["id"])
25+
if isinstance(entry, dict) and "data" in entry:
26+
fetched_secrets[entry_name] = entry["data"]
2427
except Exception as e:
2528
fetched_secrets[entry_name] = {"error": str(e)}
2629

plugins/module_utils/vaults.py

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
import requests
22

3+
34
def get_vaults(server_base_url, token):
45
vaults_url = f"{server_base_url}/api/v1/vault"
5-
vaults_headers = {
6-
"Content-Type": "application/json",
7-
"tokenId": token
8-
}
6+
vaults_headers = {"Content-Type": "application/json", "tokenId": token}
97

108
try:
119
response = requests.get(vaults_url, headers=vaults_headers)
1210
response.raise_for_status()
1311

1412
json_data = response.json()
15-
if 'data' not in json_data:
13+
if "data" not in json_data:
1614
raise ValueError(f"'data' key missing in response: {json_data}")
1715

18-
return json_data.get('data', [])
16+
return json_data.get("data", [])
1917
except Exception as e:
2018
raise Exception(f"An error occurred while getting vaults: {e}")
2119

20+
2221
def get_vault_entry(server_base_url, token, vault_id, entry_id):
2322
vault_url = f"{server_base_url}/api/v1/vault/{vault_id}/entry/{entry_id}"
24-
vault_headers = {
25-
"Content-Type": "application/json",
26-
"tokenId": token
27-
}
23+
vault_headers = {"Content-Type": "application/json", "tokenId": token}
2824

2925
try:
3026
response = requests.get(vault_url, headers=vault_headers)
@@ -34,60 +30,60 @@ def get_vault_entry(server_base_url, token, vault_id, entry_id):
3430
except Exception as e:
3531
raise Exception(f"An error occurred while getting a vault entry: {e}")
3632

33+
3734
def get_vault_entry_from_name(server_base_url, token, vault_id, entry_name):
3835
vault_url = f"{server_base_url}/api/v1/vault/{vault_id}/entry"
39-
vault_headers = {
40-
"Content-Type": "application/json",
41-
"tokenId": token
42-
}
36+
vault_headers = {"Content-Type": "application/json", "tokenId": token}
4337

4438
try:
45-
response = requests.get(vault_url, headers=vault_headers, params={'name': entry_name})
39+
response = requests.get(
40+
vault_url, headers=vault_headers, params={"name": entry_name}
41+
)
4642
response.raise_for_status()
4743

4844
return response.json()
4945
except Exception as e:
5046
raise Exception(f"An error occurred while getting a vault entry: {e}")
5147

48+
5249
def get_vault_entry_from_tag(server_base_url, token, vault_id, entry_tag):
5350
vault_url = f"{server_base_url}/api/v1/vault/{vault_id}/entry"
54-
vault_headers = {
55-
"Content-Type": "application/json",
56-
"tokenId": token
57-
}
51+
vault_headers = {"Content-Type": "application/json", "tokenId": token}
5852

5953
try:
60-
response = requests.get(vault_url, headers=vault_headers, params={'tag': entry_tag})
54+
response = requests.get(
55+
vault_url, headers=vault_headers, params={"tag": entry_tag}
56+
)
6157
response.raise_for_status()
6258

6359
return response.json()
6460
except Exception as e:
6561
raise Exception(f"An error occurred while getting a vault entry: {e}")
6662

63+
6764
def get_vault_entry_from_path(server_base_url, token, vault_id, entry_path):
6865
vault_url = f"{server_base_url}/api/v1/vault/{vault_id}/entry"
69-
vault_headers = {
70-
"Content-Type": "application/json",
71-
"tokenId": token
72-
}
66+
vault_headers = {"Content-Type": "application/json", "tokenId": token}
7367

7468
try:
75-
response = requests.get(vault_url, headers=vault_headers, params={'path': entry_path})
69+
response = requests.get(
70+
vault_url, headers=vault_headers, params={"path": entry_path}
71+
)
7672
response.raise_for_status()
7773

7874
return response.json()
7975
except Exception as e:
8076
raise Exception(f"An error occurred while getting a vault entry: {e}")
8177

78+
8279
def get_vault_entry_from_type(server_base_url, token, vault_id, entry_type):
8380
vault_url = f"{server_base_url}/api/v1/vault/{vault_id}/entry"
84-
vault_headers = {
85-
"Content-Type": "application/json",
86-
"tokenId": token
87-
}
81+
vault_headers = {"Content-Type": "application/json", "tokenId": token}
8882

8983
try:
90-
response = requests.get(vault_url, headers=vault_headers, params={'type': entry_type})
84+
response = requests.get(
85+
vault_url, headers=vault_headers, params={"type": entry_type}
86+
)
9187
response.raise_for_status()
9288

9389
return response.json()
@@ -97,25 +93,23 @@ def get_vault_entry_from_type(server_base_url, token, vault_id, entry_type):
9793

9894
def get_vault_entries(server_base_url, token, vault_id):
9995
vault_url = f"{server_base_url}/api/v1/vault/{vault_id}/entry"
100-
vault_headers = {
101-
"Content-Type": "application/json",
102-
"tokenId": token
103-
}
96+
vault_headers = {"Content-Type": "application/json", "tokenId": token}
10497

10598
try:
10699
response = requests.get(vault_url, headers=vault_headers)
107100
response.raise_for_status()
108101

109102
json_data = response.json()
110-
if 'data' not in json_data:
103+
if "data" not in json_data:
111104
raise ValueError(f"'data' key missing in response: {json_data}")
112105

113-
return json_data.get('data', [])
106+
return json_data.get("data", [])
114107
except Exception as e:
115108
raise Exception(f"An error occurred while getting vault entries: {e}")
116109

110+
117111
def find_entry_by_name(entries, name):
118112
for entry in entries:
119-
if entry.get('name') == name:
113+
if entry.get("name") == name:
120114
return entry
121115
return None

plugins/modules/create_secret.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
#!/usr/bin/python
22

3-
from __future__ import absolute_import, division, print_function
4-
5-
__metaclass__ = type
6-
7-
from ansible.module_utils.basic import AnsibleModule
8-
from ansible_collections.devolutions.dvls.plugins.module_utils.auth import login, logout
9-
from ansible_collections.devolutions.dvls.plugins.module_utils.vaults import (
10-
get_vault_entries,
11-
find_entry_by_name,
12-
)
13-
import requests
14-
153
DOCUMENTATION = r"""
164
---
175
module: create_secret
@@ -96,6 +84,14 @@
9684
returned: changed
9785
"""
9886

87+
from ansible.module_utils.basic import AnsibleModule
88+
from ansible_collections.devolutions.dvls.plugins.module_utils.auth import login, logout
89+
from ansible_collections.devolutions.dvls.plugins.module_utils.vaults import (
90+
get_vault_entries,
91+
find_entry_by_name,
92+
)
93+
import requests
94+
9995

10096
def run_module():
10197
module_args = dict(

plugins/modules/fetch_secrets.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
#!/usr/bin/python
22

3-
from __future__ import absolute_import, division, print_function
4-
5-
__metaclass__ = type
6-
7-
from ansible.module_utils.basic import AnsibleModule
8-
from ansible_collections.devolutions.dvls.plugins.module_utils.auth import login, logout
9-
from ansible_collections.devolutions.dvls.plugins.module_utils.utils import (
10-
get_sensible_value,
11-
)
12-
from ansible_collections.devolutions.dvls.plugins.module_utils.vaults import (
13-
get_vault_entry,
14-
get_vault_entry_from_name,
15-
get_vault_entry_from_tag,
16-
get_vault_entry_from_type,
17-
get_vault_entry_from_path,
18-
get_vault_entries,
19-
)
20-
21-
223
DOCUMENTATION = r"""
234
---
245
module: fetch_secrets
@@ -86,6 +67,20 @@
8667
returned: always
8768
"""
8869

70+
from ansible.module_utils.basic import AnsibleModule
71+
from ansible_collections.devolutions.dvls.plugins.module_utils.auth import login, logout
72+
from ansible_collections.devolutions.dvls.plugins.module_utils.utils import (
73+
get_sensible_value,
74+
)
75+
from ansible_collections.devolutions.dvls.plugins.module_utils.vaults import (
76+
get_vault_entry,
77+
get_vault_entry_from_name,
78+
get_vault_entry_from_tag,
79+
get_vault_entry_from_type,
80+
get_vault_entry_from_path,
81+
get_vault_entries,
82+
)
83+
8984

9085
def run_module():
9186
module_args = dict(

plugins/modules/fetch_server.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
#!/usr/bin/python
22

3-
from __future__ import absolute_import, division, print_function
4-
5-
__metaclass__ = type
6-
7-
from ansible.module_utils.basic import AnsibleModule
8-
from ansible_collections.devolutions.dvls.plugins.module_utils.auth import login, logout
9-
from ansible_collections.devolutions.dvls.plugins.module_utils.vaults import get_vaults
10-
from ansible_collections.devolutions.dvls.plugins.module_utils.server import (
11-
public_instance_information,
12-
private_instance_information,
13-
)
14-
15-
163
DOCUMENTATION = r"""
174
---
185
module: fetch_server
@@ -57,6 +44,14 @@
5744
returned: always
5845
"""
5946

47+
from ansible.module_utils.basic import AnsibleModule
48+
from ansible_collections.devolutions.dvls.plugins.module_utils.auth import login, logout
49+
from ansible_collections.devolutions.dvls.plugins.module_utils.vaults import get_vaults
50+
from ansible_collections.devolutions.dvls.plugins.module_utils.server import (
51+
public_instance_information,
52+
private_instance_information,
53+
)
54+
6055

6156
def run_module():
6257
module_args = dict(

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
ansible==11.3.0
1+
ansible~=11.3
2+
ansible-lint~=25.1
23
requests==2.32.3

0 commit comments

Comments
 (0)