@@ -75,49 +75,12 @@ def download_license() -> str:
7575 return response .text
7676
7777
78- def is_license_valid () -> bool :
79- try :
80- with open (LICENSE_DEFAULT_LOCATION , "r" ) as f :
81- json_status = json .load (f )
82- issued_to = json_status .get ("issued_to" , "" )
83- e_uci = EUci ()
84- subscription = e_uci .get (
85- "ns-plug" , "config" , "type" , dtype = str , default = None
86- )
87- if subscription is not None and "Enterprise" not in issued_to :
88- logging .warning (
89- f"License type mismatch: expected Enterprise, got { issued_to } "
90- )
91- return False
92- elif "Community" not in issued_to :
93- logging .warning (
94- f"License type mismatch: expected Community, got { issued_to } "
95- )
96- return False
97-
98- expire_at = json_status .get ("expire_at" , {})
99- unix_expiration = expire_at .get ("unix" , 0 )
100- current_time = int (time .time ())
101- if unix_expiration > current_time :
102- logging .debug (f"License valid until { time .ctime (unix_expiration )} " )
103- return True
104- else :
105- logging .warning ("License expired, refresh triggered" )
106- return False
107- except FileNotFoundError :
108- logging .warning ("License missing, refresh triggered" )
109- return False
110-
111-
11278if __name__ == "__main__" :
11379 logger = logging .getLogger ()
11480 logger .setLevel (environ .get ("LOGLEVEL" , "INFO" ).upper ())
11581 handler = logging .StreamHandler ()
11682 logger .addHandler (handler )
11783
118- if is_license_valid ():
119- exit (0 )
120-
12184 try :
12285 upstream_license = download_license ()
12386 save_license (upstream_license )
0 commit comments