|
|
@@ -49,3 +49,41 @@ alter("/conf.toml", "secret_code", cod
|
|
|
|
|
|
|
|
|
|
|
|
+#---------V2============
|
|
|
+
|
|
|
+
|
|
|
+import boto3
|
|
|
+import time
|
|
|
+client = boto3.client('ssm')
|
|
|
+
|
|
|
+def alter(file,old_str,new_str):
|
|
|
+ file_data = ""
|
|
|
+
|
|
|
+ with open(file, "r", encoding="utf-8") as f:
|
|
|
+ for line in f:
|
|
|
+ if old_str in line:
|
|
|
+ line = line.replace(line,new_str)
|
|
|
+ file_data += line
|
|
|
+ with open(file,"w",encoding="utf-8") as f:
|
|
|
+ f.write(f'[DEFAULT]\nlog_path = "/root/"\n{file_data}')
|
|
|
+ # f.write(file_data)
|
|
|
+ f.close()
|
|
|
+def old_read(file,old_str):
|
|
|
+ with open(file, "r", encoding="utf-8") as f:
|
|
|
+ for line in f:
|
|
|
+ if old_str in line:
|
|
|
+ return line
|
|
|
+
|
|
|
+while True:
|
|
|
+ global old
|
|
|
+ respond = client.get_parameter(Name='Secret')
|
|
|
+ code_ori = respond['Parameter']['Value']
|
|
|
+ code_pro = code_ori.replace("'", '')
|
|
|
+ code = f'secret_code = "{code_pro}"'
|
|
|
+ time.sleep(3)
|
|
|
+ old = old_read("/conf.toml", "secret_code")
|
|
|
+ if old == code:
|
|
|
+ print('NO')
|
|
|
+ else:
|
|
|
+ print('OK')
|
|
|
+ alter("/conf.toml", "secret_code", code)
|