File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/python3
2
2
3
3
import argparse
4
+ import netrc
4
5
import os
5
6
from datetime import datetime , timedelta
7
+ from urllib .parse import urlparse
6
8
7
9
import requests
8
10
import yaml
@@ -150,6 +152,22 @@ def store_new_list(local_dir, missing_products):
150
152
f .write ("\n " .join (missing_products ))
151
153
152
154
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
+
153
171
def main ():
154
172
args = parse_arguments ()
155
173
config = read_configuration ()
@@ -159,6 +177,7 @@ def main():
159
177
sentinel_host = args .sentinelHost or config .get ("SENTINEL_HOST" )
160
178
if not sentinel_host :
161
179
raise Exception ("SENTINEL_HOST is not defined and sentinelHost parameter not passed!" )
180
+ check_host (sentinel_host )
162
181
local_dir = config .get ("LOCAL_DIR" )
163
182
164
183
timestamp = args .fromTimestamp or get_timestamp (local_dir )
You can’t perform that action at this time.
0 commit comments