1) 数据库和相关应用的用户名, 密码等敏感信息加密之后集中存放在某一文件
2) Production Service 只需一键执行脚本即可把用户名和密码更新到指定路径下相应的配置文件(支持迭代).
#!/usr/bin/env python import os import sys import re # To read from credential file and put key/value pairs into a map def getCredentialMap(credentialFile): credentialsMap={} f = open(credentialFile, 'r') for line in f.readlines(): if not line.startswith('#'): tokens = line.split('=') credentialsMap['${' + tokens[0].strip() + '}'] = tokens[1].strip() return credentialsMap # To scan recursively from a specific top folder where there are configuration files need to update their credentials def scan(path, map, extensions, log): for i in os.walk(path): dirpath=i[0] dirnames=i[1] filenames=i[2] for j in filenames: processFile(os.path.join(dirpath, j), map, extensions, log) for k in dirnames: scan(os.path.join(dirpath, k), map, extensions, log) # To process a specific file def processFile(pathfile, map, extensions, log): extension = os.path.splitext(pathfile)[1] if extension not in extensions: return else: fh = open(pathfile, 'r+') newFile = '' updated = False lineNo = 0 for line in fh.readlines(): lineNo += 1 replaced, text = processLine(line, map) if replaced: updated = True log.write(pathfile + os.linesep) log.write('Line %3d: %s' % (lineNo, line.rstrip()) + os.linesep) log.write('========> %s' % (text.rstrip()) + os.linesep) newFile = newFile + text fh.close() if updated: fh = open(pathfile, 'r+') fh.truncate() fh.write(newFile) fh.close() # To process a specific line def processLine(line, map): text = line pattern = r'\${.+?}' replaced = False for match in re.finditer(pattern, line): s = match.start() e = match.end() key = line[s:e] value = map[key] if value: text = line.replace(key, value) replaced = True return (replaced, text) # The entry of this program def main(): sampleFile=''' #-----Follows are the content of a sample configuration file----- #path to the credentials file ssts.credentials.path=./credentials.properties #path(s) to the target top foder(s). Please separate with ";" when there is more than one target top folder ssts.target.path=./config;./build #the extentions of configuration files file.extention.filter=.xml;.properties #--------------------------------------------------------------- ''' configFile = os.path.splitext(sys.argv[0])[0] + '.properties' logFile = os.path.splitext(sys.argv[0])[0] + '.log' log = open(logFile, 'w') log.truncate() map = {} targetPath = [] try: fh = open(configFile, 'r') for line in fh.readlines(): if line.startswith('ssts.credentials.path'): credentialFile=line.split('=')[1].strip() if line.startswith('ssts.target.path'): targetPath=line.split('=')[1].strip().split(';') if line.startswith('file.extension.filter'): extensions=line.split('=')[1].strip().split(';') map = getCredentialMap(credentialFile) except IOError, e: print 'Please prepare ' + configFile + ' with this script ' + sys.argv[0], print sampleFile print e except Exception, e: print e for path in targetPath: scan(path, map, extensions, log) log.close() if __name__ == '__main__': main()
Groovy version:
#!/usr/bin/env groovy // To read from credential file and put key/value pairs into a map def getCredentialMap(String credentialFile){ credentialsMap=[:] def f = new File(credentialFile) f.eachLine{ if(!it.startsWith('#')){ def tokens = it.split('=') credentialsMap.put('${'+tokens[0].trim()+'}', tokens[1].trim()) } } return credentialsMap } // To scan recursively from a specific top folder where there are configuration files need to update their credentials def scan(path, map, extensions, log){ new File(path).eachFileRecurse { if(it.isFile()){ processFile(it, map, extensions, log) } } } // To process a specific file def processFile(file, map, extensions, log){ def extension = '.' + file.getName().split(/\./)[1] if(extension in extensions){ def newFile = new StringBuilder() def updated = false def lineNo = 0 file.eachLine{ lineNo += 1 def result = processLine(it, map) def replaced = result[0] def text = result[1] if(replaced){ updated = true log.append(file.getCanonicalFile().toString() + System.getProperty('line.separator')) log.append(String.format('Line %3d: %s', lineNo, it.trim()) + System.getProperty('line.separator')) log.append(String.format('========> %s', text.trim()) + System.getProperty('line.separator')) } newFile.append(text) } if(updated){ file.write('') file.write(newFile.toString()) } } } // To process a specific line def processLine(line, map){ def text = line def pattern = ~/\$\{.+?\}/ def replaced = false def matcher = pattern.matcher(line) def count = matcher.getCount() for(i in 0..<count){ def key = matcher[i] def value = map.get(key) if( value != null){ text = line.replace(key, value) replaced = true } } text = text + System.getProperty('line.separator') return [replaced, text] } def void MAIN(){ def sampleFile=''' #-----Follows are the content of a sample configuration file----- #path to the credentials file. (Don't input any space in between) suez.credentials.path=./ssts-credentials.properties #path(s) to the target top foder(s). Please separate with ";" when there is more than one target top folder. (Don't input any space in between) suez.target.path=./config;./build #the extentions of configuration files. (Don't input any space in between) file.extention.filter=.xml;.properties;.cfg #---------------------------------------------------------------- ''' def configFile = this.class.name + '.properties' def logFile = this.class.name + '.log' def log = new File(logFile) log.write('') def map = [:] def credentialFile def targetPath = [] def extensions = [] try{ new File(configFile).eachLine{ if(it.startsWith('suez.credentials.path')) credentialFile=it.split('=')[1].trim() if(it.startsWith('suez.target.path')) targetPath=it.split('=')[1].trim().split(';') if(it.startsWith('file.extension.filter')) extensions=it.split('=')[1].trim().split(';') } map = getCredentialMap(credentialFile) }catch(IOException e){ println 'Please prepare ' + configFile + ' for this script ' + this.class.name + '.groovy' println sampleFile println e }catch(Exception e){ println e } for(path in targetPath){ scan(path, map, extensions, log) } } MAIN()
相关推荐
在执行上传时,可能需要提供服务器的URL、用户名、密码以及目标路径等信息。 整个过程的自动化意味着开发者编写了一段Java程序或者脚本,能够协调这些步骤,从用户触发操作到最终文件上传到服务器,全程无需人工...
少儿编程scratch项目源代码文件案例素材-绝地求生.zip
嵌入式八股文面试题库资料知识宝典-文思创新面试题2010-04-08.zip
一种基于剪切波和特征信息检测的太阳斑点图融合算法.pdf
内容概要:本文详细介绍了并联型有源电力滤波器(APF)在Matlab/Simulink环境下的仿真研究。主要内容涵盖三个关键技术点:一是dq与αβ坐标系下的谐波和无功检测,利用dq变换和FBD技术实现实时检测;二是两相旋转坐标系(dq)与两相静止坐标系(αβ)下的PI控制,通过调整比例和积分环节实现精准控制;三是SVPWM调制方式的应用,通过优化开关时序提升系统效率和性能。文中还提供了详细的仿真介绍文档,包括模型搭建、参数设定以及结果分析。 适合人群:从事电力电子、自动化控制领域的研究人员和技术人员,尤其是对电力滤波器仿真感兴趣的读者。 使用场景及目标:适用于需要深入了解并联型APF工作原理和实现方式的研究人员,旨在通过仿真工具掌握谐波和无功检测、PI控制及SVPWM调制的具体应用。 其他说明:本文不仅提供了理论知识,还结合了实际操作步骤,使读者能够通过仿真模型加深对APF的理解。
Arduino KEY实验例程,开发板:正点原子EPS32S3,本人主页有详细实验说明可供参考。
嵌入式八股文面试题库资料知识宝典-嵌入式C语言面试题汇总(66页带答案).zip
.archivetempdebug.zip
嵌入式系统开发_CH551单片机_USB_HID复合设备模拟_基于CH551单片机的USB键盘鼠标复合设备模拟器项目_用于通过CH551微控制器模拟USB键盘和鼠标输入设备_实现硬
少儿编程scratch项目源代码文件案例素材-剑客冲刺.zip
少儿编程scratch项目源代码文件案例素材-火影.zip
内容概要:本文详细介绍了两极式单相光伏并网系统的组成及其仿真优化方法。前级采用Boost电路结合扰动观察法(P&O)进行最大功率点跟踪(MPPT),将光伏板输出电压提升至并网所需水平;后级利用全桥逆变加L型滤波以及电压外环电流内环控制,确保并网电流与电网电压同频同相,实现高效稳定的并网传输。文中还提供了具体的仿真技巧,如开关频率设置、L滤波参数计算和并网瞬间软启动等,最终实现了98.2%的系统效率和低于0.39%的总谐波失真率(THD)。 适合人群:从事光伏并网系统研究、设计和开发的技术人员,特别是对Boost电路、MPPT算法、逆变技术和双环控制系统感兴趣的工程师。 使用场景及目标:适用于希望深入了解两极式单相光伏并网系统的工作原理和技术细节的研究人员和工程师。目标是在实际项目中应用这些理论和技术,提高光伏并网系统的效率和稳定性。 其他说明:文中提供的仿真技巧和伪代码有助于读者更好地理解和实现相关算法,在实践中不断优化系统性能。同时,注意电网电压跌落时快速切换到孤岛模式的需求,确保系统的安全性和可靠性。
矢量边界,行政区域边界,精确到乡镇街道,可直接导入arcgis使用
嵌入式八股文面试题库资料知识宝典-嵌入式c面试.zip
嵌入式八股文面试题库资料知识宝典-I2C总线.zip
内容概要:本文详细介绍了三种注浆模型——随机裂隙网络注浆模型、基于两相达西定律的注浆模型、基于层流和水平集的注浆扩散模型。首先,随机裂隙网络注浆模型基于地质学原理,模拟裂隙网络发育的实际地质情况,在不同注浆压力下进行注浆作业,以增强地基稳定性和提高承载能力。其次,基于两相达西定律的注浆模型利用数学公式模拟裂隙网络中的流体输送过程,适用于裂隙网络地质条件下的注浆效果分析。最后,基于层流和水平集的注浆扩散模型通过引入层流特性和水平集方法,更准确地模拟注浆过程中的扩散过程。文中还讨论了不同注浆压力对注浆效果的影响,并提出了优化建议。 适合人群:从事岩土工程、地基加固等相关领域的工程师和技术人员。 使用场景及目标:①帮助工程师选择合适的注浆模型和注浆压力;②为实际工程项目提供理论支持和技术指导;③提升地基加固的效果和效率。 其他说明:文章强调了在实际应用中需要结合地质条件、裂隙网络特点等因素进行综合分析,以达到最佳注浆效果。同时,鼓励不断创新注浆工艺和方法,以满足日益增长的地基加固需求。
内容概要:本文详细比较了COMSOL Multiphysics软件5.5和6.0版本在模拟Ar棒板粗通道流注放电现象方面的异同。重点探讨了不同版本在处理电子密度、电子温度、电场强度以及三维视图等方面的优缺点。文中不仅介绍了各版本特有的操作方式和技术特点,还提供了具体的代码实例来展示如何进行精确的仿真设置。此外,文章还讨论了网格划分、三维数据提取和电场强度后处理等方面的技术难点及其解决方案。 适合人群:从事等离子体物理研究的专业人士,尤其是熟悉COMSOL Multiphysics软件并希望深入了解其最新特性的研究人员。 使用场景及目标:帮助用户选择合适的COMSOL版本进行高效、精确的等离子体仿真研究,特别是在处理复杂的Ar棒板粗通道流注放电现象时提供指导。 其他说明:文章强调了在实际应用中,选择COMSOL版本不仅要考虑便捷性和视觉效果,还需兼顾仿真精度和可控性。
嵌入式八股文面试题库资料知识宝典-C and C++ normal interview_8.doc.zip
内容概要:本文详细介绍了在现代通信系统中,抗干扰技术的重要性和具体应用方法。首先阐述了抗干扰技术的背景及其重要性,随后分别讨论了捷变频技术和波形优化技术的具体机制和优势。捷变频技术能快速改变工作频率,防止被干扰源锁定;波形优化技术则通过改进信号波形来提升抗干扰性能。接着,文章探讨了两种技术相结合的协同效应,最后重点介绍了发射信号及接收滤波器联合优化的抗干扰策略(ISRJ),这是一种综合性优化手段,旨在最大化抗干扰效果并提高通信质量。 适合人群:从事通信工程及相关领域的研究人员和技术人员,尤其是关注抗干扰技术的专业人士。 使用场景及目标:适用于需要提升通信系统稳定性和可靠性的场合,如军事通信、卫星通信等领域。目标是帮助技术人员理解和掌握先进的抗干扰技术,应用于实际项目中。 其他说明:文中提到的技术不仅限于理论层面,还涉及具体的实施细节和应用场景,有助于读者深入理解并应用于实践中。