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): self.versionsDB = Versions.Versions(mongodb) self.toolDB = Tool.Tool(mongodb) self.tagDB = Tags.Tags() self.toolsetdb = ToolSet.ToolSet(mongodb) self.deploymentunitsetdb = DeploymentUnitSet.DeploymentUnitSet() self.deploymentunitdb = DeploymentUnit.DeploymentUnit() self.teamDB = Teams.Teams(mongodb) self.machineDB = Machine.Machine(mongodb) self.machinegroupsDB = MachineGroups.MachineGroups(mongodb) self.toolsetdb = ToolSet.ToolSet(mongodb) self.userdb = Users.Users(mongodb) self.roledb = Role.Role(mongodb)
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 create_token_for_ci(self, db): ''' General description: Create Team For Guests Args: param1 (db) : Database instance. Returns: None ''' try: userDB = Users.Users(db) data = userDB.get_user("DPMsysCI", False) if data and not data.get("access_token"): data1 = {} data1["_id"] = {"oid": str(data["_id"])} data1["access_token"] = ''.join( random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(25)) data1["access_exp_date"] = "2100-01-01T00:00:00" userDB.update_user(data1) except Exception: raise ValueError("Unable to create access token for DPMsysCI")
def create_guest_team(self, db): ''' General description: Create Team For Guests Args: param1 (db) : Database instance. Returns: None ''' try: teamDB = Teams.Teams(db) if teamDB.get_team_by_name("Guest_Team") is None: userDB = Users.Users(db) teamDetails = {} teamDetails["team_name"] = "Guest_Team" teamDetails[ "description"] = "This team has view access to all the tools, Du, tool set and Du set" teamDetails["distribution_list"] = "" try: teamDetails["users_id_list"] = [ userDB.get_user_by_name("Guest") ] except: raise ValueError("Guest User does not exist") teamDetails["tag_id_list"] = [] teamDetails["parent_entity_tag_list"] = [] teamDetails["parent_entity_set_tag_list"] = [] teamDetails["parent_entity_id_tool_list"] = [] teamDetails["parent_entity_id_du_list"] = [] teamDetails["parent_entity_tool_set_id_list"] = [] teamDetails["parent_entity_du_set_id_list"] = [] teamDetails["machine_id_list"] = [] teamDetails["machine_group_id_list"] = [] new_team_id = teamDB.add_team(teamDetails) print "Guest Team Created Sucessfull with Team Id" + new_team_id else: print "Guest Team already exists" except: raise ValueError("Unable to create Guest Team")
from urlparse import urlparse from bson.json_util import dumps from flask import Blueprint, jsonify, request 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",
import unittest import requests from GetAuthToken import getToken import json from settings import mongodb,unittest_test_url from DBUtil import MachineGroups,Accounts,Users,MachineType,Machine import verifyResponse UsersDb=Users.Users(mongodb) AccountsDb=Accounts.Accounts() MachineDb=Machine.Machine(mongodb) MachineTypeDb=MachineType.MachineType(mongodb) MachineGroupdb=MachineGroups.MachineGroups(mongodb) Baseurl = unittest_test_url+"machinegroups/" header = {'content-type': "application/json", 'token':str(getToken())} class AddMachineGroupTest(unittest.TestCase): oid=None; MacOid1=None; MacOid2=None def runTest(self): CreateMachinesForMachineGroup() url=Baseurl+"add" print "--------------------------------------------------------------------------------------------------------" print "Calling API :"+url + " For Create MachineGroup test" payload={"group_name":"UnitTestMachineGroup", "machine_id_list":[AddMachineGroupTest.MacOid1, AddMachineGroupTest.MacOid2]} response = requests.request("POST", url, data=json.dumps(payload), headers=header,verify=False) verifyResponse.PositiveTesting(response)
''' Created on Jan 5, 2018 @author: vijasing ''' from DBUtil import Teams, Machine, Users, Role, UserFavoriteMachine from settings import mongodb from Services.AppInitServices import authService from flask import jsonify teamsdb = Teams.Teams(mongodb) machinedb = Machine.Machine(mongodb) userdb = Users.Users(mongodb) roledb = Role.Role(mongodb) machineFavDb = UserFavoriteMachine.UserFavoriteMachine(mongodb) def delete_user(uid): """Start User Deletion""" user_id = authService.get_userid_by_auth_token() if user_id is None: return jsonify({ "result": "failed", "message": "Token verification failed" }), 404 loggedInUser = userdb.get_user_by_id(user_id, False) UserToDelete = userdb.get_user_by_id(uid, False) loggedInUserRole = roledb.get_role_by_id(loggedInUser["roleid"], True) if loggedInUserRole["name"].lower() == "superadmin": pass else:
from werkzeug import secure_filename from flask_restplus import Resource from modules.apimodels import UserModel from modules.apimodels.Restplus import api, header_parser from Services import LdapHelper from datetime import datetime, timedelta import re from Services.HelperServices import genrate_random_key # blueprint declaration userAPI = Blueprint('userAPI', __name__) 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)
# get global db connection db = mongodb # blueprint declaration syncAPI = Blueprint('syncAPI', __name__) # restPlus Declaration syncAPINs = api.namespace('sync', description='Sync Operations',path="/sync") # get global db connection db = mongodb # collection syncDb = Sync.Sync(db) userDb = Users.Users(db) configDb = Config.Config(db) cleanerServices = CleanerServices.CleanerServices(mongodb) SavedExportsDb = SavedExports.SavedExports() syncRequestDb = SyncRequest.SyncRequest(db) syncService = SyncServices.SyncServices() pullService = PullServices.PullServices() pushService = PushServices.PushServices() @syncAPINs.route('/savedexports', methods=['GET']) class get_saved_exports(Resource): @api.expect(header_parser, validate=True) @api.marshal_with(SyncAPIModel.get_saved_exports_response_model) @authService.authorized