def _getProductVerisonFromDSConfig(shell, configPath): cat = getSafeCatCmd(shell) grep = getGrepCmd(shell) return cat(configPath) | grep('InstalledAppVer1')\ | cmdlets.executeCommand(shell) | cmdlets.stripOutput\ | FnCmdlet(_parseVersion)
def process(self, context): r''' @types: applications.ApplicationSignatureContext ''' shell = context.client fs = file_system.createFileSystem(shell) config = None configPath = getVsConfigPathFromCmdline(self._vscanRfcProcess.commandLine) try: config = fs.getFile(configPath, [file_topology.FileAttrs.NAME, file_topology.FileAttrs.PATH, file_topology.FileAttrs.CONTENT]) except file_topology.PathNotFoundException: logger.debugException('Failed to get config file for virus scan') configOsh = modeling.createConfigurationDocumentOshByFile(config, context.application.applicationOsh) context.resultsVector.add(configOsh) pathUtils = file_system.getPath(fs) exePath = (self._vscanRfcProcess.executablePath and pathUtils.isAbsolute(self._vscanRfcProcess.executablePath) and self._vscanRfcProcess.executablePath or _discoverProcessExecutablePath(shell, self._vscanRfcProcess)) if exePath: logger.debug('vscan_rfc executable path: %s' % exePath) vscanRfcCmd = vscan_rfc(exePath) vsiVersion = vscanRfcCmd.version() | cmdlet.executeCommand(shell) | cmdlet.produceResult if vsiVersion: softwareBuilder = SoftwareBuilder() softwareBuilder.updateVersion(context.application.applicationOsh, vsiVersion.kernelRelease) softwareBuilder.updateVsiVersion(context.application.applicationOsh, vsiVersion.vsiVersion) appVersionDescription = 'Versiontext: %s. Build release: %s. Build date: %s. Build platform: %s' % (vsiVersion.versionText, vsiVersion.buildRelease, vsiVersion.buildDate, vsiVersion.buildPlatform) softwareBuilder.updateVersionDescription(context.application.applicationOsh, appVersionDescription) else: logger.debug('Failed to discover path to vscan_rfc executable. No version info discovered.') appSignature = context.application.getApplicationComponent().getApplicationSignature() adjoinedTopologyCookie = _getOrCreateAdjoinedTopologyCookie(appSignature) adjoinedTopologyCookie.virusScanOsh = context.application.applicationOsh adjoinedTopologyReporter = _VirusScanAdjoinedTopologyReporter() if adjoinedTopologyReporter.isDataEnough(adjoinedTopologyCookie): context.resultsVector.addAll(adjoinedTopologyReporter.reportApplicationComponentsLinks(adjoinedTopologyCookie.virusScanOsh, \ adjoinedTopologyCookie.sapGatewayOsh)) else: logger.debug('Data is not enough for building adjoined topology from VirusScanPlugin')
def _discoverProcessExecutablePath(shell, process): if shell.isWinOs(): return process.executablePath return readlink(process.getPid()) | cmdlet.executeCommand(shell) | cmdlet.produceResult
def getFileContent(shell, filePath): ''' @types: shellutils.Shell, str -> str ''' return (shell.isWinOs() and win_type or cat)(filePath) | cmdlet.executeCommand(shell) | cmdlet.produceResult
def _getProductVerisonFromProductId(shell, configPath): cat = getSafeCatCmd(shell) return cat(configPath) | cmdlets.executeCommand(shell) | cmdlets.stripOutput\ | FnCmdlet(_parseVersion)