def __transferFile(self, filetype, fileHelper): """ This file is creates and transfers the CAs or CRLs file to the client. :param str filetype: we can define which file will be transfered to the client :param object fileHelper: :return: S_OK or S_ERROR """ if filetype == 'CAs': retVal = Utilities.generateCAFile() elif filetype == 'CRLs': retVal = Utilities.generateRevokedCertsFile() else: return S_ERROR("Not supported file type %s" % filetype) if not retVal['OK']: return retVal else: result = fileHelper.getFileDescriptor(retVal['Value'], 'r') if not result['OK']: result = fileHelper.sendEOF() # better to check again the existence of the file if not os.path.exists(retVal['Value']): return S_ERROR('File %s does not exist' % os.path.basename(retVal['Value'])) else: return S_ERROR('Failed to get file descriptor') fileDescriptor = result['Value'] result = fileHelper.FDToNetwork(fileDescriptor) fileHelper.oFile.close() # close the file and return return result
def export_streamToClient(self, fileId): version = "" if isinstance(fileId, str): if fileId in ["CAs", "CRLs"]: retVal = Utilities.generateCAFile( ) if fileId == "CAs" else Utilities.generateRevokedCertsFile() if not retVal["OK"]: return retVal with open(retVal["Value"], "r") as fd: return S_OK(b64encode(fd.read()).decode()) bId = fileId elif isinstance(fileId, (list, tuple)): if len(fileId) == 0: return S_ERROR("No bundle specified!") bId = fileId[0] if len(fileId) != 1: version = fileId[1] if not self.bundleManager.bundleExists(bId): return S_ERROR("Unknown bundle %s" % bId) bundleVersion = self.bundleManager.getBundleVersion(bId) if bundleVersion is None: return S_ERROR("Empty bundle %s" % bId) if version == bundleVersion: return S_OK(bundleVersion) return S_OK(b64encode(self.bundleManager.getBundleData(bId)).decode())
def main(): Script.parseCommandLine(ignoreErrors=True) result = Utilities.generateRevokedCertsFile() if not result["OK"]: gLogger.error(result["Message"]) sys.exit(1)
def getCLRs(self): """ This method can be used to create the CAs. If the file can not be created, it will be downloaded from the server. """ retVal = Utilities.generateRevokedCertsFile() if not retVal['OK']: # if we can not found the file, we return the directory, where the file should be transferClient = self.__getTransferClient() casFile = os.path.join(os.path.dirname(retVal['Message']), "crls.pem") with open(casFile, "w") as fd: result = transferClient.receiveFile(fd, 'CRLs') if not result['OK']: return result return S_OK(casFile) else: return retVal
def getCAs(self): """ This method can be used to create the CAs. If the file can not be created, it will be downloaded from the server. :return: S_OK(str)/S_ERROR() """ retVal = Utilities.generateCAFile() if not retVal['OK']: self.log.warn("Could not generate/find CA file", retVal['Message']) # if we can not found the file, we return the directory, where the file should be transferClient = self.__getTransferClient() casFile = os.path.join(os.path.dirname(retVal['Message']), "cas.pem") with open(casFile, "w") as fd: result = transferClient.receiveFile(fd, 'CAs') if not result['OK']: return result return S_OK(casFile) else: return retVal