示例#1
0
 def __init__(self, methodName):
     super().__init__(methodName)
     assemblyParsing = self.createAssemplyParsing()
     self.parseResult = self.executeProcess(assemblyParsing)
     
     self.groups = {group.groupName:group for group in 
                    listBFS(self.parseResult.solicit.repository, RepositoryGroup.children, RepositoryGroup.groupName)}
     
     self.rightRepos = listBFS(self.parseResult.solicit.repository, RepositoryGroup.children, RepositoryRight.rightName)
     self.rights = {right.rightName:right for right in self.rightRepos}
     self.rightsInheritance = {right.rightName:[right] for right in self.rightRepos}
     
     self.syncRigthsAssembler = SynchronizeRightsHandler()
示例#2
0
    def process(self, chain, solicit: Solicit, **keyargs):
        '''
        @see: HandlerProcessor.process
        
        Synchronize the accesses in the configuration file with the accesses in the database.
        '''
        assert isinstance(chain, Chain), 'Invalid chain %s' % chain
        assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
        assert isinstance(
            solicit.repository,
            RepositoryRight), 'Invalid repository %s' % solicit.repository

        rights = listBFS(solicit.repository, RepositoryRight.children,
                         RepositoryRight.rightId)
        #first group the accesses by right id: rightId -> [accesses]
        idNameMapping = self.getIdNameMapping(rights, RepositoryRight,
                                              RepositoryRight.rightId,
                                              RepositoryRight.rightName)
        rightAccesses = self.groupAccesses(rights, RepositoryRight,
                                           RepositoryRight.rightId)

        if not solicit.syncAccesses: solicit.syncAccesses = []
        solicit.syncAccesses.extend(
            self.createSyncAccesses(chain.arg.SyncAccess, rightAccesses,
                                    idNameMapping, True))
示例#3
0
 def process(self, chain, solicit:Solicit, **keyargs):
     '''
     @see: HandlerProcessor.process
     
     Synchronize the actions in the configuration file with the actions in the database.
     '''
     assert isinstance(chain, Chain), 'Invalid chain %s' % chain
     assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
     assert isinstance(solicit.repository, Repository), 'Invalid repository %s' % solicit.repository
     
     groups = listBFS(solicit.repository, Repository.children, Repository.actions)
     
     actionsFromConfig = {}
     # check for actions with the same path -> display warning message
     isWarning = False
     for repository in groups:
         assert isinstance(repository, Repository), 'Invalid repository %s' % repository
         for action in repository.actions:
             if action.path in actionsFromConfig:
                 action1, action2 = action, actionsFromConfig[action.path]
                 diffs = self.compareActions(action1, action2)
                 if diffs:
                     isWarning = True
                     warningId = '%s_%s_%s' % (action.path, action1.lineNumber, action2.lineNumber)
                     if warningId in self._warnings: continue
                     
                     log.warning('Attributes: "%s" are different for Action with path="%s" at Line %s and Line %s',
                                 ', '.join(diffs), action1.path, action1.lineNumber, action2.lineNumber)
                     self._warnings.add(warningId)
                     
             else: actionsFromConfig[action.path] = action
     # if everything was ok, erase all warnings
     if not isWarning and len(self._warnings) > 0: 
         log.warning('Actions OK')
         self._warnings.clear()
         
     actionsFromDb = set(self.actionManagerService.getAll())
     
     for action in sorted(actionsFromConfig.values(), key=lambda action:action.path):
         assert isinstance(action, ActionDefinition), 'Invalid action %s' % action
         data = asData(action, ActionDefinition)
         data = {modifyFirst(name, True): value for name, value in data.items()}
         apiAction = copyContainer(data, Action())
         resolved = False
         if action.path not in actionsFromDb:
             try:
                 self.actionManagerService.insert(apiAction)
                 resolved = True
             except: log.warn('Cannot add action %s, maybe already exists' % apiAction.Path)
             
         if not resolved:
             self.actionManagerService.update(apiAction)
             # except: log.warn('Cannot update action %s' % apiAction.Path)
             actionsFromDb.discard(action.path)
     
     for path in actionsFromDb: self.actionManagerService.delete(path)
示例#4
0
    def process(self, chain, solicit: Solicit, **keyargs):
        '''
        @see: HandlerProcessor.process
        
        Synchronize the rights of the groups in the configuration file with the database.
        '''
        assert isinstance(chain, Chain), 'Invalid chain %s' % chain
        assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
        assert isinstance(
            solicit.repository,
            RepositoryRight), 'Invalid repository %s' % solicit.repository

        try:
            self.rightTypeService.getById(self.type_name)
        except:
            rightType = RightType()
            rightType.Name = self.type_name
            self.rightTypeService.insert(rightType)

        #maps name to id
        rightsDb = {
            e.Name: e.Id
            for e in [
                self.rightService.getById(id)
                for id in self.rightService.getAll(self.type_name)
            ]
        }
        #maps right_name to arguments required for right creation
        rightRepositories = listBFS(solicit.repository,
                                    RepositoryRight.children,
                                    RepositoryRight.rightName)
        #do rights inheritance
        self.doInheritance(rightRepositories)
        rights = {
            r.rightName: (partial(self.createEntity, r), r)
            for r in rightRepositories
        }
        rightIds = syncWithDatabase(self.rightService, rights, rightsDb)

        #add id to right repositories
        for r in rightRepositories:
            r.rightId = rightIds.get(r.rightName)

        #create root role ("Admin") and add all the rights on it
        try:
            self.roleService.getById(self.role_name)
        except:
            role = Role()
            role.Name = self.role_name
            self.roleService.insert(role)
        for rightId in rightIds.values():
            self.roleService.addRight(self.role_name, rightId)
示例#5
0
 def process(self, chain, solicit:Solicit, **keyargs):
     '''
     @see: HandlerProcessor.process
     
     Synchronize the actions of the groups in the configuration file with the database.
     '''
     assert isinstance(chain, Chain), 'Invalid chain %s' % chain
     assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
     assert isinstance(solicit.repository, RepositoryRight), 'Invalid repository %s' % solicit.repository
     
     rights = listBFS(solicit.repository, RepositoryRight.children, RepositoryRight.rightId)
     #group the actions by right name: rightId -> [actions]
     rightActions = self.groupActions(rights, RepositoryRight, 'rightId')
     self.synchronize(rightActions)
示例#6
0
 def process(self, chain, solicit:Solicit, **keyargs):
     '''
     @see: HandlerProcessor.process
     
     Synchronize the actions of the groups in the configuration file with the database.
     '''
     assert isinstance(chain, Chain), 'Invalid chain %s' % chain
     assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
     assert isinstance(solicit.repository, RepositoryGroup), 'Invalid repository %s' % solicit.repository
     
     groups = listBFS(solicit.repository, RepositoryGroup.children, RepositoryGroup.groupName)
     #first group the actions by group name: groupName -> [actions]
     groupActions = self.groupActions(groups, RepositoryGroup, 'groupName')        
     self.synchronize(groupActions)
 def process(self, chain, solicit:Solicit, **keyargs):
     '''
     @see: HandlerProcessor.process
     
     Synchronize the group accesses in the configuration file with the accesses in the database.
     '''
     assert isinstance(chain, Chain), 'Invalid chain %s' % chain
     assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
     assert isinstance(solicit.repository, RepositoryGroup), 'Invalid repository %s' % solicit.repository
     
     groups = listBFS(solicit.repository, RepositoryGroup.children, RepositoryGroup.groupName)
     #first group the accesses by group name: groupName -> [accesses]
     groupAccesses = self.groupAccesses(groups, RepositoryGroup, RepositoryGroup.groupName)
     
     if not solicit.syncAccesses: solicit.syncAccesses = []
     solicit.syncAccesses.extend(self.createSyncAccesses(chain.arg.SyncAccess, groupAccesses))
示例#8
0
 def process(self, chain, solicit:Solicit, **keyargs):
     '''
     @see: HandlerProcessor.process
     
     Synchronize the groups of the groups in the configuration file with the database.
     '''
     assert isinstance(chain, Chain), 'Invalid chain %s' % chain
     assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
     assert isinstance(solicit.repository, RepositoryGroup), 'Invalid repository %s' % solicit.repository
     
     #maps name to id
     groupsDb = {name:name for name in self.groupService.getAll()}
     #maps group_name to arguments required for group creation (None for groups)
     groups = {r.groupName: (self.createEntity, r) for r in listBFS(solicit.repository, 
                                                              RepositoryGroup.children, RepositoryGroup.groupName)}
     syncWithDatabase(self.groupService, groups, groupsDb)
 def process(self, chain, solicit:Solicit, **keyargs):
     '''
     @see: HandlerProcessor.process
     
     Synchronize the accesses in the configuration file with the accesses in the database.
     '''
     assert isinstance(chain, Chain), 'Invalid chain %s' % chain
     assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
     assert isinstance(solicit.repository, RepositoryRight), 'Invalid repository %s' % solicit.repository
     
     rights = listBFS(solicit.repository, RepositoryRight.children, RepositoryRight.rightId)
     #first group the accesses by right id: rightId -> [accesses]
     idNameMapping = self.getIdNameMapping(rights, RepositoryRight, RepositoryRight.rightId, RepositoryRight.rightName)
     rightAccesses = self.groupAccesses(rights, RepositoryRight, RepositoryRight.rightId)
     
     if not solicit.syncAccesses: solicit.syncAccesses = []
     solicit.syncAccesses.extend(self.createSyncAccesses(chain.arg.SyncAccess, rightAccesses, idNameMapping, True))
示例#10
0
    def process(self, chain, solicit: Solicit, **keyargs):
        '''
        @see: HandlerProcessor.process
        
        Synchronize the groups of the groups in the configuration file with the database.
        '''
        assert isinstance(chain, Chain), 'Invalid chain %s' % chain
        assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
        assert isinstance(
            solicit.repository,
            RepositoryGroup), 'Invalid repository %s' % solicit.repository

        #maps name to id
        groupsDb = {name: name for name in self.groupService.getAll()}
        #maps group_name to arguments required for group creation (None for groups)
        groups = {
            r.groupName: (self.createEntity, r)
            for r in listBFS(solicit.repository, RepositoryGroup.children,
                             RepositoryGroup.groupName)
        }
        syncWithDatabase(self.groupService, groups, groupsDb)
示例#11
0
    def process(self, chain, solicit: Solicit, **keyargs):
        '''
        @see: HandlerProcessor.process
        
        Synchronize the group accesses in the configuration file with the accesses in the database.
        '''
        assert isinstance(chain, Chain), 'Invalid chain %s' % chain
        assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
        assert isinstance(
            solicit.repository,
            RepositoryGroup), 'Invalid repository %s' % solicit.repository

        groups = listBFS(solicit.repository, RepositoryGroup.children,
                         RepositoryGroup.groupName)
        #first group the accesses by group name: groupName -> [accesses]
        groupAccesses = self.groupAccesses(groups, RepositoryGroup,
                                           RepositoryGroup.groupName)

        if not solicit.syncAccesses: solicit.syncAccesses = []
        solicit.syncAccesses.extend(
            self.createSyncAccesses(chain.arg.SyncAccess, groupAccesses))
示例#12
0
 def process(self, chain, solicit:Solicit, **keyargs):
     '''
     @see: HandlerProcessor.process
     
     Synchronize the rights of the groups in the configuration file with the database.
     '''
     assert isinstance(chain, Chain), 'Invalid chain %s' % chain
     assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
     assert isinstance(solicit.repository, RepositoryRight), 'Invalid repository %s' % solicit.repository
     
     try: self.rightTypeService.getById(self.type_name)
     except:
         rightType = RightType()
         rightType.Name = self.type_name
         self.rightTypeService.insert(rightType)
     
     #maps name to id
     rightsDb = {e.Name: e.Id for e in [self.rightService.getById(id) for id in self.rightService.getAll(self.type_name)]}
     #maps right_name to arguments required for right creation
     rightRepositories = listBFS(solicit.repository, RepositoryRight.children, RepositoryRight.rightName)
     #do rights inheritance 
     self.doInheritance(rightRepositories)
     rights = {r.rightName: (partial(self.createEntity, r), r) for r in rightRepositories}
     rightIds = syncWithDatabase(self.rightService, rights, rightsDb)
     
     #add id to right repositories
     for r in rightRepositories:
         r.rightId = rightIds.get(r.rightName)
         
     #create root role ("Admin") and add all the rights on it
     try: self.roleService.getById(self.role_name)
     except:
         role = Role()
         role.Name = self.role_name
         self.roleService.insert(role)
     for rightId in rightIds.values(): self.roleService.addRight(self.role_name, rightId)
示例#13
0
    def process(self, chain, solicit: Solicit, **keyargs):
        '''
        @see: HandlerProcessor.process
        
        Synchronize the actions in the configuration file with the actions in the database.
        '''
        assert isinstance(chain, Chain), 'Invalid chain %s' % chain
        assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit
        assert isinstance(
            solicit.repository,
            Repository), 'Invalid repository %s' % solicit.repository

        groups = listBFS(solicit.repository, Repository.children,
                         Repository.actions)

        actionsFromConfig = {}
        # check for actions with the same path -> display warning message
        isWarning = False
        for repository in groups:
            assert isinstance(repository,
                              Repository), 'Invalid repository %s' % repository
            for action in repository.actions:
                if action.path in actionsFromConfig:
                    action1, action2 = action, actionsFromConfig[action.path]
                    diffs = self.compareActions(action1, action2)
                    if diffs:
                        isWarning = True
                        warningId = '%s_%s_%s' % (action.path,
                                                  action1.lineNumber,
                                                  action2.lineNumber)
                        if warningId in self._warnings: continue

                        log.warning(
                            'Attributes: "%s" are different for Action with path="%s" at Line %s and Line %s',
                            ', '.join(diffs), action1.path, action1.lineNumber,
                            action2.lineNumber)
                        self._warnings.add(warningId)

                else:
                    actionsFromConfig[action.path] = action
        # if everything was ok, erase all warnings
        if not isWarning and len(self._warnings) > 0:
            log.warning('Actions OK')
            self._warnings.clear()

        actionsFromDb = set(self.actionManagerService.getAll())

        for action in sorted(actionsFromConfig.values(),
                             key=lambda action: action.path):
            assert isinstance(action,
                              ActionDefinition), 'Invalid action %s' % action
            data = asData(action, ActionDefinition)
            data = {
                modifyFirst(name, True): value
                for name, value in data.items()
            }
            apiAction = copyContainer(data, Action())
            resolved = False
            if action.path not in actionsFromDb:
                try:
                    self.actionManagerService.insert(apiAction)
                    resolved = True
                except:
                    log.warn('Cannot add action %s, maybe already exists' %
                             apiAction.Path)

            if not resolved:
                self.actionManagerService.update(apiAction)
                # except: log.warn('Cannot update action %s' % apiAction.Path)
                actionsFromDb.discard(action.path)

        for path in actionsFromDb:
            self.actionManagerService.delete(path)