Skip to content

Commit 9ea0012

Browse files
committed
check netrc entry of host in gen_new_list.py
1 parent c07cfd4 commit 9ea0012

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

gen_new_list.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/python3
22

33
import argparse
4+
import netrc
45
import os
56
from datetime import datetime, timedelta
7+
from urllib.parse import urlparse
68

79
import requests
810
import yaml
@@ -150,6 +152,22 @@ def store_new_list(local_dir, missing_products):
150152
f.write("\n".join(missing_products))
151153

152154

155+
def check_host(sentinel_host):
156+
"""
157+
Checks sentinel_host variable was resolved and .netrc file contains authentication credentials.
158+
"""
159+
if not sentinel_host:
160+
raise Exception("Sentinel host not configured properly!")
161+
162+
try:
163+
auth_info = netrc.netrc()
164+
if not auth_info.authenticators(urlparse(sentinel_host).netloc):
165+
raise Exception(
166+
f"Host {urlparse(sentinel_host)} not found in authentication credentials in the .netrc file!")
167+
except (FileNotFoundError, netrc.NetrcParseError):
168+
raise Exception(f"Error parsing authentication file .netrc in the home directory.")
169+
170+
153171
def main():
154172
args = parse_arguments()
155173
config = read_configuration()
@@ -159,6 +177,7 @@ def main():
159177
sentinel_host = args.sentinelHost or config.get("SENTINEL_HOST")
160178
if not sentinel_host:
161179
raise Exception("SENTINEL_HOST is not defined and sentinelHost parameter not passed!")
180+
check_host(sentinel_host)
162181
local_dir = config.get("LOCAL_DIR")
163182

164183
timestamp = args.fromTimestamp or get_timestamp(local_dir)

0 commit comments

Comments
 (0)