Skip to content

Commit 44d4bee

Browse files
authored
script: Improve getenvvar helper
* Handle multiple clouds.yaml files * Use OS_CLOUDS if set * Add uv dependencies metadata header Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent a7c3703 commit 44d4bee

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

script/getenvvar

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/usr/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.13"
4+
# dependencies = [
5+
# "pyyaml>=6",
6+
# ]
7+
# ///
28

39
"""
410
Set environment variables required for the CI jobs by inspection of the
@@ -14,22 +20,40 @@ To unset them:
1420
"""
1521

1622
import argparse
23+
import os
1724
from pathlib import Path
1825
import sys
1926

2027
import yaml
2128

22-
p = Path('~/.config/openstack/clouds.yaml').expanduser()
2329
parser = argparse.ArgumentParser()
2430
parser.add_argument(
2531
'cloud',
32+
default=os.getenv('OS_CLOUD'),
33+
nargs='?',
2634
help="Cloud to export credentials for",
2735
)
2836

2937
args = parser.parse_args()
3038

31-
with p.open() as fh:
32-
data = yaml.safe_load(fh)
39+
for p in (
40+
Path('clouds.yaml'),
41+
Path('~/.config/openstack/clouds.yaml').expanduser(),
42+
Path('/etc/openstack/clouds.yaml'),
43+
):
44+
if not p.exists():
45+
continue
46+
47+
with p.open() as fh:
48+
data = yaml.safe_load(fh)
49+
break
50+
else:
51+
print('Could not find clouds.yaml file', file=sys.stderr)
52+
sys.exit(1)
53+
54+
if not args.cloud:
55+
print('Need to provide cloud argument or set OS_CLOUD', file=sys.stderr)
56+
sys.exit(1)
3357

3458
if args.cloud not in data.get('clouds', {}) or {}:
3559
print(f'Could not find cloud {args.cloud} in {str(p)}', file=sys.stderr)

0 commit comments

Comments
 (0)