def __init__(self): ''' LOGS THE APPLICATION ''' try: self.configdb = Config.Config(mongodb).getConfigByName("AppLogger") if self.configdb: self.enable_logging = str( self.configdb["enable"]).lower() == "true" self.log_to_console = str( self.configdb["log_to_console"]).lower() == "true" self.loggingLevel = self.configdb['loggingLevel'].upper() self.logFormat = self.configdb.get("logFormat") self.logDateFmt = self.configdb.get("dateFormat") self.backupCount = self.configdb.get("backupCount") else: self.enable_logging = True self.log_to_console = False self.loggingLevel = "TRACE" self.logFormat = "%(asctime)s[%(levelname)-5.5s]%(message)s" self.logDateFmt = "%d-%m-%Y %H:%M:%S" self.backupCount = 0 if self.enable_logging: print "enable was found to be true. 'applicationLogs' will be created everyday" rootLogger = logging.getLogger() # Get logger rootLogger.setLevel(self.loggingLevel) self.configdb = Config.Config(mongodb) logFormatter = logging.Formatter(self.logFormat, datefmt=self.logDateFmt) # TO PRINT LOGGER TO FILE fileHandler = TimedRotatingFileHandler( "{0}/{1}".format(log_full_path, "applicationLogs"), when='midnight', interval=1, backupCount=self.backupCount ) # FileName #EveryMidnight #Interval=1Day fileHandler.setFormatter(logFormatter) rootLogger.addHandler(fileHandler) if self.log_to_console: # TO PRINT LOGGER ON SCREEN consoleHandler = logging.StreamHandler( ) # Stream all logs to sys.stdout consoleHandler.setFormatter(logFormatter) rootLogger.addHandler(consoleHandler) # All print will get written in rootLogger sys.stdout = StreamToLogger.StreamToLogger( rootLogger, logging.INFO) # Hook of sys.stdout # All exceptions will get written in rootLogger sys.stderr = StreamToLogger.StreamToLogger( rootLogger, logging.ERROR) # Hook of sys.stderr # else: # print "enable was found to be false. " + current_path + "/log/out_logs.log' and " + current_path + "/log/err_logs.log' will be created " # sys.stdout = open(os.path.join(log_full_path,"out_logs.log"), 'a', 0) # sys.stderr = open(os.path.join(log_full_path,"err_logs.log"), 'a', 0) except Exception as e: # catch *all* exceptions print "Unable to start Logger.Reason :" + str(e) raise Exception("Unable to start Logger.Reason :" + str(e))
def __init__(self, db): ''' General description : This function initializes the database variables and \ index to refer in functions. ''' self.db = db self.configdb = Config.Config(db) self.toolDB = Tool.Tool(self.db) self.userDB = Users.Users(self.db) self.roleDB = Role.Role(self.db) self.buildsDB = Build.Build() self.versionsDB = Versions.Versions(db) self.emailsDB = Emails.Emails(self.db) self.deploymentRequestDB = DeploymentRequest.DeploymentRequest(db) self.CloneRequestDB = CloneRequest.CloneRequest(db) self.contributionGitPushLogs = ContributionGitPushLogs.ContributionGitPushLogs( db) self.sync = Sync.Sync(db) self.auditingDB = Auditing.Auditing() self.distributionSync = DistributionSync.DistributionSync(db) self.mediaFilesDB = MediaFiles.MediaFiles(self.db) self.logo_path = logo_path self.full_logo_path = str(current_path) + self.logo_path self.media_files_path = media_path self.full_media_files_path = media_full_path self.folder_list_to_clean = [ export_full_path, distribution_center_export_full_path ] self.config_id = 15 self.load_configuration() self.schedulerService = SchedulerService.SchedulerService() self.deploymentUnitDB = DeploymentUnit.DeploymentUnit() self.repositoryDB = Repository.Repository()
def __init__(self): """Initializing Variable """ self.db = mongodb self.distributionSync = DistributionSync.DistributionSync(self.db) self.toolDB = Tool.Tool(self.db) self.versionsDB = Versions.Versions(self.db) self.mailer = Mailer.Mailer() self.static_folder_path = current_path self.current_import_path = distribution_center_import_full_path self.current_import_small_path = distribution_center_import_path if self.current_import_path in [None, ""]: raise ValueError("Import path was not provided") if not os.path.exists(self.current_import_path): os.makedirs(self.current_import_path) if not os.access(os.path.dirname(self.current_import_path), os.W_OK): raise ValueError("The directory does not have write access :" + self.current_import_path) self.current_export_path = distribution_center_export_full_path if self.current_export_path in [None, ""]: raise ValueError("Export path was not provided") if not os.path.exists(self.current_export_path): os.makedirs(self.current_export_path) if not os.access(os.path.dirname(self.current_export_path), os.W_OK): raise ValueError("The directory does not have write access :" + self.current_export_path) self.configdb = Config.Config(self.db) self.logo_path = logo_path self.full_logo_path = logo_full_path self.media_files_path = media_path self.full_media_files_path = media_full_path self.config_id = 13 self.load_configuration() self.schedulerService = SchedulerService.SchedulerService()
def __init__(self): self.db = mongodb self.current_import_path = import_full_path if not os.path.exists(self.current_import_path): os.makedirs(self.current_import_path) if not os.access(self.current_import_path, os.W_OK): raise ValueError( "The directory does not have write access :" + self.current_import_path) self.configdb = Config.Config(self.db) self.syncdb = Sync.Sync(self.db) self.syncRequestdb = SyncRequest.SyncRequest(self.db) self.mailer = Mailer.Mailer() self.syncService = SyncServices.SyncServices() self.systemDetailsDb = SystemDetails.SystemDetails(self.db) self.systemDetail = self.systemDetailsDb.get_system_details_single() self.remoteAuthenticationService = RemoteAuthenticationService.RemoteAuthenticationService() if not self.systemDetail: raise Exception("systemDeatils not found") if not self.systemDetail.get("hostname"): raise Exception("hostname not found in systemDeatils") self.host_name = self.systemDetail.get("hostname") self.post_url = "/sync/pull/export" self.config_id = 10 self.count_of_files = 2 # Minimum Threads is 2 self.load_configuration() self.schedulerService = SchedulerService.SchedulerService()
def __init__(self, db): """Initializing Variable """ self.configdb = Config.Config(db) self.distributionMachinetDB = DistributionMachine.DistributionMachine( db) self.syncService = SyncServices.SyncServices() self.machineDB = Machine.Machine(db) self.mailer = Mailer.Mailer() self.current_path = distribution_center_export_full_path self.systemDetailsDb = SystemDetails.SystemDetails(db) if not os.path.exists(self.current_path): os.makedirs(self.current_path) if not os.access(os.path.dirname(self.current_path), os.W_OK): raise ValueError("The directory does not have write access :" + self.current_path) systemDetail = self.systemDetailsDb.get_system_details_single() if not systemDetail: raise Exception("systemDeatils not found") if not systemDetail.get("hostname"): raise Exception("hostname not found in systemDeatils") self.remote_trigger_api_path = "/clonerequest/distribution/pull/" + \ systemDetail.get("hostname") self.config_id = 12 self.load_configuration() self.schedulerService = SchedulerService.SchedulerService() self.remote_authentication_service = RemoteAuthenticationService.RemoteAuthenticationService( )
def __init__(self, db): # Need to add code for Clone self.CloneRequestDB = CloneRequest.CloneRequest(db) self.noOfThreads = 1 # Minimum Threads is 1 self.configdb = Config.Config(db) self.config_id = 4 self.load_configuration() self.schedulerService = SchedulerService.SchedulerService()
def __init__(self): """ # Init's Data ############### # Db instance ##############""" ############### # Collection ############## self.emaildb = Emails.Emails(mongodb) self.configdb = Config.Config(mongodb) self.interinterval = 7 # Time to sleep after every email self.config_id = 2 self.load_configuration() self.schedulerService = SchedulerService.SchedulerService()
def __init__(self): self.db = mongodb self.current_import_path = import_full_path if self.current_import_path in [None, ""]: raise ValueError("Import path was not provided") if not os.path.exists(self.current_import_path): os.makedirs(self.current_import_path) if not os.access(os.path.dirname(self.current_import_path), os.W_OK): raise ValueError("The directory does not have write access :" + self.current_import_path) self.current_export_path = export_full_path if self.current_export_path in [None, ""]: raise ValueError("Export path was not provided") if not os.path.exists(self.current_export_path): os.makedirs(self.current_export_path) if not os.access(os.path.dirname(self.current_export_path), os.W_OK): raise ValueError("The directory does not have write access :" + self.current_export_path) self.configdb = Config.Config(self.db) self.versionsDB = Versions.Versions(self.db) self.toolDB = Tool.Tool(self.db) self.deploymentFieldsDB = DeploymentFields.DeploymentFields(self.db) self.machineDB = Machine.Machine(self.db) self.syncDb = Sync.Sync(self.db) self.mailer = Mailer.Mailer() self.syncRequestDb = SyncRequest.SyncRequest(self.db) self.buildsDB = Build.Build() self.documentsDB = Documents.Documents(self.db) self.toolDB = Tool.Tool(self.db) self.deploymentunitDB = DeploymentUnit.DeploymentUnit() self.deploymentunitsetDB = DeploymentUnitSet.DeploymentUnitSet() self.mediaFilesDB = MediaFiles.MediaFiles(self.db) self.tagsDB = Tags.Tags() self.preRequisitesDB = PreRequisites.PreRequisites(self.db) self.logo_path = logo_path self.full_logo_path = logo_full_path self.media_files_path = media_path self.full_media_files_path = media_full_path self.systemDetailsDb = SystemDetails.SystemDetails(self.db) self.systemDetail = self.systemDetailsDb.get_system_details_single() self.statedb = State.State(self.db) if not self.systemDetail: raise Exception("systemDeatils not found") self.config_id = 9 self.load_configuration() self.schedulerService = SchedulerService.SchedulerService() self.flexAttrDB = FlexibleAttributes.FlexibleAttributes()
def __init__(self, db): ''' General description : This function initializes the database variables and \ index to refer in functions. ''' self.configdb = Config.Config(db) self.toolDb = Tool.Tool(db) self.versionsDb = Versions.Versions(db) self.contributionGitPushLogsDb = \ ContributionGitPushLogs.ContributionGitPushLogs(db) self.mailer = Mailer.Mailer() self.systemDetailsDb = SystemDetails.SystemDetails(db) self.config_id = 14 self.load_configuration() self.schedulerService = SchedulerService.SchedulerService()
def __init__(self, db, key): self.RSAKEY = RSA.generate(1024) self.SECRET_KEY = self.RSAKEY.exportKey('PEM') self.SECRET_PUBLIC_KEY = self.RSAKEY.publickey().exportKey('PEM') self.ENCRYPTION_METHOD = 'RS512' # WE WILL VERIFY EXPIRATION BY OURSELVES self.JWT_OPTIONS = {'verify_exp': False, } self.userdb = Users.Users(db) self.auditdb = Auditing.Auditing() self.roledb = Role.Role(db) self.passHelper = PasswordHelper.PasswordHelper(key) self.permissiondb = Permissions.Permissions(db) self.permissiongroupdb = PermissionGroup.PermissionGroup(db) self.accountDB = Accounts.Accounts() self.configdb = Config.Config(db) self.systemDetailsDB = SystemDetails.SystemDetails(db) self.configdbData = self.configdb.getConfigByName("AuthService") # 6 is for AuthRequestService configuration self.auditing_config = self.configdb.getConfigByName("AuditingServices") # 6 is for AuthRequestService configuration self.mailer = Mailer.Mailer() self.validTokens = {} self.teamService = TeamService.TeamService() self.collection = db.SystemDetails # Set Collection as Permissions self.teamsdb = Teams.Teams(db) if self.configdbData is not None: if self.configdbData.get("expiration") is not None: self.expiration = int(self.configdbData.get("expiration")) else: raise Exception( "Config AuthService does not have expiration set") if self.configdbData.get("email_domain") is not None: self.email_domain = str(self.configdbData.get("email_domain")) else: raise Exception( "Config AuthService does not have email_domain set") self.allow_multi_user_session = self.configdbData.get("allow_multi_user_session","false") else: raise Exception("Config was not found for Authorization services") # ADD DEAMON THREAD TO REMOVE IN VALID TOKENS AUTOMATICALLY pool = ThreadPoolExecutor(2,__name__+".__init__") pool.submit(self.removeInvalidTokens) pool.submit(self.check_if_user_logged_in_from_last_6_months)
def populate_config_data(self, db): self.collection = db.Config # Set Collection as Config # 525 self.configdb = Config.Config(db) # Loop over the configuration data list and insert into the Config # collection if not present for configDetail in dynamicInstanceOfInitData.CONFIG_DATA: IsFound = self.get_record_by_name(configDetail["name"]) if IsFound is None: # 525 configDetail = self.configdb.encrypt(configDetail) self.insert_record(configDetail) count = self.get_all_count() if count >= len(dynamicInstanceOfInitData.CONFIG_DATA): print "Config data Populated Successful" else: raise ValueError( "Insufficient Config detected. " + str(len(dynamicInstanceOfInitData.CONFIG_DATA) - count) + " entries are missing")
def __init__(self): self.db = mongodb self.current_path = export_full_path if not os.path.exists(self.current_path): os.makedirs(self.current_path) if not os.access(os.path.dirname(self.current_path), os.W_OK): raise ValueError("The directory does not have write access :" + self.current_path) self.remoteAuthenticationService = RemoteAuthenticationService.RemoteAuthenticationService( ) self.configdb = Config.Config(self.db) self.syncdb = Sync.Sync(self.db) self.syncRequestdb = SyncRequest.SyncRequest(self.db) self.syncService = SyncServices.SyncServices() self.remote_import_path = None self.count_of_files = 2 # Minimum Threads is 2 self.allow_split = "true" # Default split allowed self.config_id = 11 self.load_configuration() self.schedulerService = SchedulerService.SchedulerService()
def __init__(self, db=None): # init db conneciton if db is None: self.db = mongodb """# Init's Data""" self.app = Flask(__name__) self.mail = Mail(self.app) self.app.config.from_object(__name__) self.app.config.from_envvar('MINITWIT_SETTINGS', silent=True) ############### # Collection ############## self.templatedb = EmailTemplate.EmailTemplate(self.db) self.emaildb = Emails.Emails(self.db) self.configdb = Config.Config(self.db) self.SystemDetailsDb = SystemDetails.SystemDetails(self.db) # Initialize Email Configuration self.result = self.configdb.getConfigByName("Mailer") # 1 is for mailer configuration if self.result is None: raise Exception("Config not found for Mailer") self.app.config.update( DEBUG=self.str_to_bool(str(self.result['debug']).strip()), MAIL_HOST=str(self.result['host']).strip(), MAIL_SERVER=str(self.result['server']).strip(), MAIL_PORT=int(str(self.result['port']).strip()), MAIL_USE_TLS=self.str_to_bool(str(self.result['tls']).strip()), MAIL_USE_SSL=self.str_to_bool(str(self.result['ssl']).strip()), MAIL_USERNAME=str(self.result['username']).strip(), MAIL_PASSWORD=str(self.result['password']).strip(), DEFAULT_MAIL_SENDER=str(self.result['defaultsender']).strip() ) # Setup socket Info socket.getaddrinfo(str(self.result['socketip']).strip(), str( self.result['socketport']).strip()) # Env Variable self.mailfrom = str(self.result['defaultsender']).strip()
from settings import mongodb, relative_path from flask_restplus import Resource from modules.apimodels import DistributionCenterModel from modules.apimodels.Restplus import api, header_parser # blueprint declaration distributionCenterAPI = Blueprint('distributionCenterAPI', __name__) # restplus declaration distributionCenterAPINs = api.namespace( 'clonerequest/distribution', description='Distribution Center Operations') # get global db connection db = mongodb # collection configdb = Config.Config(db) distributionCenterConfig = configdb.getConfigByName("PushServices") # collections cloneRequestDB = CloneRequest.CloneRequest(db) machineDB = Machine.Machine(db) distributionMachinetDB = DistributionMachine.DistributionMachine(db) if distributionCenterConfig: distributionCenterService = DistributionCenterService.DistributionCenterService( db) distributionsyncDB = DistributionSync.DistributionSync(db) tooldb = Tool.Tool(db) versionsDB = Versions.Versions(db) accountDB = Accounts.Accounts() distributionMachinetDB = DistributionMachine.DistributionMachine(db) # classes
''' Created on Jun 30, 2017 @author: PDINDA ''' from DBUtil import Config from settings import mongodb configdb = Config.Config(mongodb) def load_common_configuration(obj): try: """Loads configuration required to run service using config_id""" obj.result = configdb.getConfigByConfigId(obj.config_id) if obj.result: # CHECK IF NEED TO SCHEDULE THIS SERVICE if str(obj.result.get("enable").lower()) == "true": obj.start_service = True else: obj.start_service = False obj.service_type = str(obj.result.get("type")).lower() if obj.service_type not in ["interval", "scheduled"]: raise ValueError( 'Invalid scheduler type found.Valid values are "interval","scheduled"' ) if obj.service_type in ["scheduled"]: obj.hours = str(obj.result.get("hrs")) obj.minutes = str(obj.result.get("min")) if not obj.hours and not int(obj.minutes):
from DBUtil import Build, Users, SystemDetails, State, Config from settings import mongodb, default_nexus_container_name, temp_files_full_path from Services import StateHelperService, BuildHelperService, HelperServices from Services.AppInitServices import authService import os import json # blueprint declaration buildAPI = Blueprint('buildAPI', __name__) # get global db connection db = mongodb buildDB = Build.Build() userDB = Users.Users(db) systemDetailsDB = SystemDetails.SystemDetails(db) stateDb = State.State(mongodb) configDb = Config.Config(mongodb) ''' INPUT REQUEST: { "_id" : ObjectId("5abbc6749e53f700787d3997"), "status" : "1", "file_size" : "4.0K", "type" : "url", "file_path" : "http://illin4490:8081/nexus/content/repositories/yum-test/com/amdocs/core/crm/crm-playbooks/10.2.4-1620/crm-playbooks-10.2.4-1620.tar", "build_number": 22, "package_name" : "crm-playbooks-10.2.4-1620.tar", "package_type" : "tar", "parent_entity_id" : "5abbbf5ff13a94007945f01a", "additional_artifacts" : { "artifacts" : [ {
userAPINs = api.namespace('user', description='User Operations') # get global db connection db = mongodb accountDB = Accounts.Accounts() userdb = Users.Users(db) roledb = Role.Role(db) machineFavDb = UserFavoriteMachine.UserFavoriteMachine(db) emaildb = Emails.Emails(db) perGroup = PermissionGroup.PermissionGroup(db) teamDB = Teams.Teams(db) mailer = Mailer.Mailer() systemDetailsDB = SystemDetails.SystemDetails(db) teamService = TeamService.TeamService() machine_db = Machine.Machine(db) configDb = Config.Config(db) @userAPINs.route('/new', methods=['POST']) class addNewUser(Resource): @api.expect(header_parser, UserModel.add_user_input_model, validate=True) @api.marshal_with(UserModel.add_user_response_model) @authService.authorized def post(self): user = request.get_json() HelperServices.validate_name(user.get("user"), "username") user_id = authService.get_userid_by_auth_token() if user_id is None: raise Exception("Token verification failed") loggedInUser = userdb.get_user_by_id(user_id, False) loggedInUserRole = roledb.get_role_by_id(loggedInUser["roleid"], True)