Skip to content

Commit fed2278

Browse files
committed
OIDC login for inventory plugin
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
1 parent 475a119 commit fed2278

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

plugins/inventory/hypercore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def parse(self, inventory, loader, path, cache=False):
223223
username = os.getenv("SC_USERNAME")
224224
password = os.getenv("SC_PASSWORD")
225225
timeout = os.getenv("SC_TIMEOUT")
226+
auth_method = os.getenv("SC_AUTH_METHOD")
226227
if timeout:
227228
try:
228229
timeout = float(timeout)
@@ -234,7 +235,7 @@ def parse(self, inventory, loader, path, cache=False):
234235
raise errors.ScaleComputingError(
235236
"Missing one or more parameters: sc_host, sc_username, sc_password."
236237
)
237-
client = Client(host, username, password, timeout)
238+
client = Client(host, username, password, timeout, auth_method)
238239
rest_client = RestClient(client)
239240
vms = rest_client.list_records("/rest/v1/VirDomain")
240241

tests/integration/targets/inventory/runme.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ print("export SC_HOST='{}'".format(sc_host))
1212
print("export SC_TIMEOUT='{}'".format(sc_timeout))
1313
print("export SC_USERNAME='{}'".format(data["sc_config"][sc_host]["sc_username"]))
1414
print("export SC_PASSWORD='{}'".format(data["sc_config"][sc_host]["sc_password"]))
15+
# SC_AUTH_METHOD==local by default, leave it unset
1516
EOF
1617
)"
1718

@@ -45,8 +46,27 @@ ansible-playbook -i localhost, -i hypercore_inventory_ansible_enable.yml run_ans
4546
ansible-playbook -i localhost, -i hypercore_inventory_ansible_disable.yml run_ansible_disable_tests.yml
4647
ansible-playbook -i localhost, -i hypercore_inventory_ansible_both_true.yml run_ansible_both_true_tests.yml
4748

48-
unset SC_TIMEOUT # do one test without SC_TIMEOUT
49+
# do one test without SC_TIMEOUT
50+
unset SC_TIMEOUT
51+
ansible-playbook -i localhost, -i hypercore_inventory_ansible_both_false.yml run_ansible_both_false_tests.yml
52+
# test with SC_AUTH_METHOD being set to "local"
53+
export SC_AUTH_METHOD=local
54+
ansible-playbook -i localhost, -i hypercore_inventory_ansible_both_false.yml run_ansible_both_false_tests.yml
4955

56+
# test with OIDC user
57+
eval "$(cat <<EOF | python
58+
import yaml
59+
with open("$vars_file") as fd:
60+
data = yaml.safe_load(fd)
61+
sc_host=data["sc_host"]
62+
sc_timeout=data["sc_timeout"]
63+
print("export SC_HOST='{}'".format(sc_host))
64+
print("export SC_TIMEOUT='{}'".format(sc_timeout))
65+
print("export SC_USERNAME='{}'".format(data["sc_config"][sc_host]["oidc"]["users"][0]["username"]))
66+
print("export SC_PASSWORD='{}'".format(data["sc_config"][sc_host]["oidc"]["users"][0]["password"]))
67+
print("export SC_AUTH_METHOD=oidc")
68+
EOF
69+
)"
5070
ansible-playbook -i localhost, -i hypercore_inventory_ansible_both_false.yml run_ansible_both_false_tests.yml
5171

5272
ansible-playbook cleanup.yml

0 commit comments

Comments
 (0)