コード例 #1
0
ファイル: ProxyManagerClient.py プロジェクト: pmusset/DIRAC
import datetime

from DIRAC import S_OK, S_ERROR, gLogger
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
from DIRAC.Core.Utilities import ThreadSafe, DIRACSingleton
from DIRAC.Core.Utilities.DictCache import DictCache
from DIRAC.Core.Security.ProxyFile import multiProxyArgument, deleteMultiProxy
from DIRAC.Core.Security.X509Chain import X509Chain  # pylint: disable=import-error
from DIRAC.Core.Security.X509Request import X509Request  # pylint: disable=import-error
from DIRAC.Core.Security.VOMS import VOMS
from DIRAC.Core.Security import Locations
from DIRAC.Core.DISET.RPCClient import RPCClient

__RCSID__ = "$Id$"

gUsersSync = ThreadSafe.Synchronizer()
gProxiesSync = ThreadSafe.Synchronizer()
gVOMSProxiesSync = ThreadSafe.Synchronizer()


@six.add_metaclass(DIRACSingleton.DIRACSingleton)
class ProxyManagerClient(object):
  def __init__(self):
    self.__usersCache = DictCache()
    self.__proxiesCache = DictCache()
    self.__vomsProxiesCache = DictCache()
    self.__pilotProxiesCache = DictCache()
    self.__filesCache = DictCache(self.__deleteTemporalFile)

  def __deleteTemporalFile(self, filename):
    """ Delete temporal file
コード例 #2
0
ファイル: IdProviderFactory.py プロジェクト: TaykYoku/DIRAC
# File :   IdProviderFactory.py
# Author : A.T.
########################################################################
"""  The Identity Provider Factory instantiates IdProvider objects
     according to their configuration
"""
import jwt

from DIRAC import S_OK, S_ERROR, gLogger
from DIRAC.Core.Utilities import ObjectLoader, ThreadSafe
from DIRAC.Core.Utilities.DictCache import DictCache
from DIRAC.Resources.IdProvider.Utilities import getProviderInfo, getSettingsNamesForIdPIssuer
from DIRAC.FrameworkSystem.private.authorization.utils.Clients import getDIRACClients
from DIRAC.FrameworkSystem.private.authorization.utils.Utilities import collectMetadata

gCacheMetadata = ThreadSafe.Synchronizer()


class IdProviderFactory(object):
    def __init__(self):
        """Standard constructor"""
        self.log = gLogger.getSubLogger(self.__class__.__name__)
        self.cacheMetadata = DictCache()

    @gCacheMetadata
    def getMetadata(self, idP):
        return self.cacheMetadata.get(idP) or {}

    @gCacheMetadata
    def addMetadata(self, idP, data, time=24 * 3600):
        if data:
コード例 #3
0
ファイル: CFG.py プロジェクト: sposs/DIRAC
__RCSID__ = "$Id$"

import types
import copy
import os
try:
    import zipfile
    gZipEnabled = True
except ImportError:
    gZipEnabled = False

try:
    from DIRAC.Core.Utilities import S_OK, S_ERROR
    from DIRAC.Core.Utilities import List, ThreadSafe

    gCFGSynchro = ThreadSafe.Synchronizer(recursive=True)
except Exception:
    #We're out of python, define required utilities
    import threading
    from types import StringTypes

    def S_ERROR(messageString=''):
        return {'OK': False, 'Message': str(messageString)}

    def S_OK(value=''):
        return {'OK': True, 'Value': value}

    class ListDummy:
        def fromChar(self, inputString, sepChar=","):
            if not (type(inputString) in StringTypes
                    and type(sepChar) in StringTypes and
コード例 #4
0
"""
__RCSID__ = "$Id$"

import time
import os
import threading
import Queue
from DIRAC  import gLogger, gConfig, gMonitor, S_OK, S_ERROR
from DIRAC.Core.Base.AgentModule import AgentModule
from DIRAC.WorkloadManagementSystem.DB.JobDB         import JobDB
from DIRAC.WorkloadManagementSystem.DB.JobLoggingDB  import JobLoggingDB
from DIRAC.Core.Utilities import ThreadSafe, List
from DIRAC.Core.Utilities.Shifter import setupShifterProxyInEnv


gOptimizerLoadSync = ThreadSafe.Synchronizer()

class ThreadedMightyOptimizer( AgentModule ):
  """
      The specific agents must provide the following methods:
      - initialize() for initial settings
      - beginExecution()
      - execute() - the main method called in the agent cycle
      - endExecution()
      - finalize() - the graceful exit of the method, this one is usually used
                 for the agent restart
  """

  __jobStates = [ 'Received', 'Checking' ]
  __defaultValidOptimizers = [ 'WorkloadManagement/JobPath',
                               'WorkloadManagement/JobSanity',
コード例 #5
0
ファイル: OAuth2IdProvider.py プロジェクト: TaykYoku/DIRAC
from DIRAC import S_OK, S_ERROR
from DIRAC.Core.Utilities import ThreadSafe
from DIRAC.Resources.IdProvider.IdProvider import IdProvider
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import (
    getVOMSRoleGroupMapping,
    getGroupOption,
    getAllGroups,
    wrapIDAsDN,
    getVOs,
)
from DIRAC.FrameworkSystem.private.authorization.utils.Tokens import OAuth2Token
from DIRAC.FrameworkSystem.private.authorization.utils.Requests import createOAuth2Request

DEFAULT_HEADERS = {"Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}

gJWKs = ThreadSafe.Synchronizer()
gMetadata = ThreadSafe.Synchronizer()
gRefreshToken = ThreadSafe.Synchronizer()


def claimParser(claimDict, attributes):
    """Parse claims to dictionary with certain keys

    :param dict claimDict: claims
    :param dict attributes: contain claim and regex to parse it

    :return: dict
    """
    profile = {}
    result = None
    for claim, reg in attributes.items():
コード例 #6
0
ファイル: MightyOptimizer.py プロジェクト: acasajus/DIRAC
"""
  SuperOptimizer
  One optimizer to rule them all, one optimizer to find them,
  one optimizer to bring them all, and in the darkness bind them.
"""
__RCSID__ = "$Id$"

import os
from DIRAC import gLogger, S_OK, S_ERROR
from DIRAC.Core.Base.AgentModule import AgentModule
from DIRAC.WorkloadManagementSystem.DB.JobDB import JobDB
from DIRAC.WorkloadManagementSystem.DB.JobLoggingDB import JobLoggingDB
from DIRAC.Core.Utilities import ThreadSafe
from DIRAC.Core.Utilities.Shifter import setupShifterProxyInEnv

gOptimizerLoadSync = ThreadSafe.Synchronizer()


class MightyOptimizer(AgentModule):
    """
      The specific agents must provide the following methods:
      - initialize() for initial settings
      - beginExecution()
      - execute() - the main method called in the agent cycle
      - endExecution()
      - finalize() - the graceful exit of the method, this one is usually used
                 for the agent restart
  """
    __jobStates = ['Received', 'Checking']

    def initialize(self):
コード例 #7
0
is taken and the **exchange token** request to Identity Provider is made. The received tokens are cached.
"""

import pprint

from DIRAC import S_OK, S_ERROR
from DIRAC.Core.Security import Properties
from DIRAC.Core.Utilities import ThreadSafe
from DIRAC.Core.Utilities.DictCache import DictCache
from DIRAC.Core.Tornado.Server.TornadoService import TornadoService
from DIRAC.FrameworkSystem.DB.TokenDB import TokenDB
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory

# Used to synchronize the cache with user tokens
gTokensSync = ThreadSafe.Synchronizer()


class TokenManagerHandler(TornadoService):

    DEFAULT_AUTHORIZATION = ["authenticated"]
    DEFAULT_RT_EXPIRATION_TIME = 24 * 3600

    @classmethod
    def initializeHandler(cls, *args):
        """Initialization

        :return: S_OK()/S_ERROR()
        """
        # Let's try to connect to the database
        try: