def json_to_PolicyBean(self, json_data): username = json_data['username'] ahenk_prof_json_arr = json_data['agentPolicyProfiles'] user_prof_json_arr = json_data['userPolicyProfiles'] ahenk_prof_arr = [] user_prof_arr = [] if ahenk_prof_json_arr is not None: for prof in ahenk_prof_json_arr: plu = json.loads(json.dumps(prof['plugin'])) plugin = PluginBean(p_id=plu['id'], active=plu['active'], create_date=plu['createDate'], deleted=plu['deleted'], description=plu['description'], machine_oriented=plu['machineOriented'], modify_date=plu['modifyDate'], name=plu['name'], policy_plugin=plu['policyPlugin'], user_oriented=plu['userOriented'], version=plu['version'], task_plugin=plu['taskPlugin'], x_based=plu['xBased']) ahenk_prof_arr.append( ProfileBean(prof['id'], prof['createDate'], prof['label'], prof['description'], prof['overridable'], prof['active'], prof['deleted'], json.dumps(prof['profileData']), prof['modifyDate'], plugin, username)) if user_prof_json_arr is not None: for prof in user_prof_json_arr: plu = json.loads(json.dumps(prof['plugin'])) plugin = PluginBean(p_id=plu['id'], active=plu['active'], create_date=plu['createDate'], deleted=plu['deleted'], description=plu['description'], machine_oriented=plu['machineOriented'], modify_date=plu['modifyDate'], name=plu['name'], policy_plugin=plu['policyPlugin'], user_oriented=plu['userOriented'], version=plu['version'], task_plugin=plu['taskPlugin'], x_based=plu['xBased']) user_prof_arr.append( ProfileBean(prof['id'], prof['createDate'], prof['label'], prof['description'], prof['overridable'], prof['active'], prof['deleted'], json.dumps(prof['profileData']), prof['modifyDate'], plugin, username)) return PolicyBean(ahenk_policy_version=json_data['agentPolicyVersion'], user_policy_version=json_data['userPolicyVersion'], ahenk_profiles=ahenk_prof_arr, user_profiles=user_prof_arr, timestamp=json_data['timestamp'], username=json_data['username'], agent_execution_id=json_data['agentCommandExecutionId'], user_execution_id=json_data['userCommandExecutionId'], agent_expiration_date=json_data['agentPolicyExpirationDate'], user_expiration_date=json_data['userPolicyExpirationDate'])
def get_active_policies(self, username): try: # TODO vt den gecerli son tarihi olani cek user_policy = self.db_service.select( 'policy', ['id', 'version', 'name', 'expiration_date'], ' type=\'U\' and name=\'' + username + '\'') ahenk_policy = self.db_service.select( 'policy', ['id', 'version', 'expiration_date'], ' type=\'A\' ') plugin_columns = [ 'id', 'active', 'create_date', 'deleted', 'description', 'machine_oriented', 'modify_date', 'name', 'policy_plugin', 'user_oriented', 'version', 'task_plugin', 'x_based' ] profile_columns = [ 'id', 'create_date', 'label', 'description', 'overridable', 'active', 'deleted', 'profile_data', 'modify_date', 'plugin' ] policy = PolicyBean(username=username) if len(user_policy) > 0 and self.check_expiration( user_policy[0][3]): user_policy_version = user_policy[0][0] policy.set_user_policy_version(user_policy_version) user_profiles = self.db_service.select( 'profile', profile_columns, ' id=' + str(user_policy_version) + ' ') arr_profiles = [] if len(user_profiles) > 0: for profile in user_profiles: plu = self.db_service.select( 'plugin', plugin_columns, ' id=\'' + profile[9] + '\'')[0] plugin = PluginBean(p_id=plu[0], active=plu[1], create_date=plu[2], deleted=plu[3], description=plu[4], machine_oriented=plu[5], modify_date=plu[6], name=plu[7], policy_plugin=plu[8], user_oriented=plu[9], version=plu[10], task_plugin=plu[11], x_based=plu[12]) arr_profiles.append( ProfileBean(profile[0], profile[1], profile[2], profile[3], profile[4], profile[5], profile[6], profile[7], profile[8], plugin, policy.get_username())) policy.set_user_profiles(arr_profiles) if len(ahenk_policy) > 0 and self.check_expiration( ahenk_policy[0][2]): ahenk_policy_version = ahenk_policy[0][0] policy.set_ahenk_policy_version(ahenk_policy_version) ahenk_profiles = self.db_service.select( 'profile', profile_columns, ' id=' + str(ahenk_policy_version) + ' ') arr_profiles = [] if len(ahenk_profiles) > 0: for profile in ahenk_profiles: plu = self.db_service.select( 'plugin', plugin_columns, ' id=\'' + profile[9] + '\'')[0] plugin = PluginBean(p_id=plu[0], active=plu[1], create_date=plu[2], deleted=plu[3], description=plu[4], machine_oriented=plu[5], modify_date=plu[6], name=plu[7], policy_plugin=plu[8], user_oriented=plu[9], version=plu[10], task_plugin=plu[11], x_based=plu[12]) arr_profiles.append( ProfileBean(profile[0], profile[1], profile[2], profile[3], profile[4], profile[5], profile[6], profile[7], profile[8], plugin, policy.get_username())) policy.set_ahenk_profiles(arr_profiles) return policy except Exception as e: self.logger.error( 'A problem occurred while getting active policies. Error Message : {0}' .format(str(e)))
def get_active_policies(self, username): user_policy = self.db_service.select( 'policy', ['id', 'version', 'name'], ' type=\'U\' and name=\'' + username + '\'') ahenk_policy = self.db_service.select('policy', ['id', 'version'], ' type=\'A\' ') plugin_columns = [ 'id', 'active', 'create_date', 'deleted', 'description', 'machine_oriented', 'modify_date', 'name', 'policy_plugin', 'user_oriented', 'version', 'task_plugin', 'x_based' ] profile_columns = [ 'id', 'create_date', 'label', 'description', 'overridable', 'active', 'deleted', 'profile_data', 'modify_date', 'plugin' ] policy = PolicyBean(username=username) if len(user_policy) > 0: user_policy_version = user_policy[0][0] policy.set_user_policy_version(user_policy_version) user_profiles = self.db_service.select( 'profile', profile_columns, ' id=' + str(user_policy_version) + ' ') arr_profiles = [] if len(user_profiles) > 0: for profile in user_profiles: plu = self.db_service.select('plugin', plugin_columns, ' id=\'' + profile[9] + '\'')[0] plugin = PluginBean(p_id=plu[0], active=plu[1], create_date=plu[2], deleted=plu[3], description=plu[4], machine_oriented=plu[5], modify_date=plu[6], name=plu[7], policy_plugin=plu[8], user_oriented=plu[9], version=plu[10], task_plugin=plu[11], x_based=plu[12]) arr_profiles.append( ProfileBean(profile[0], profile[1], profile[2], profile[3], profile[4], profile[5], profile[6], profile[7], profile[8], plugin, policy.get_username())) policy.set_user_profiles(arr_profiles) if len(ahenk_policy) > 0: ahenk_policy_version = ahenk_policy[0][0] policy.set_ahenk_policy_version(ahenk_policy_version) ahenk_profiles = self.db_service.select( 'profile', profile_columns, ' id=' + str(ahenk_policy_version) + ' ') arr_profiles = [] if len(ahenk_profiles) > 0: for profile in ahenk_profiles: plu = self.db_service.select('plugin', plugin_columns, ' id=\'' + profile[9] + '\'')[0] plugin = PluginBean(p_id=plu[0], active=plu[1], create_date=plu[2], deleted=plu[3], description=plu[4], machine_oriented=plu[5], modify_date=plu[6], name=plu[7], policy_plugin=plu[8], user_oriented=plu[9], version=plu[10], task_plugin=plu[11], x_based=plu[12]) arr_profiles.append( ProfileBean(profile[0], profile[1], profile[2], profile[3], profile[4], profile[5], profile[6], profile[7], profile[8], plugin, policy.get_username())) policy.set_ahenk_profiles(arr_profiles) return policy