Skip to content

Commit

Permalink
Merge pull request #7400 from fstagni/90_fixes1
Browse files Browse the repository at this point in the history
[9.0] Style and cleanup
  • Loading branch information
chrisburr authored Jan 18, 2024
2 parents 85ed4e5 + 734af08 commit eebd912
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 175 deletions.
12 changes: 6 additions & 6 deletions src/DIRAC/ConfigurationSystem/Client/CSAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

import datetime

from DIRAC import gLogger, gConfig, S_OK, S_ERROR
from DIRAC import S_ERROR, S_OK, gConfig, gLogger
from DIRAC.ConfigurationSystem.Client.ConfigurationClient import ConfigurationClient
from DIRAC.Core.Utilities import List
from DIRAC.Core.Security.X509Chain import X509Chain # pylint: disable=import-error
from DIRAC.Core.Security import Locations
from DIRAC.ConfigurationSystem.private.Modificator import Modificator
from DIRAC.ConfigurationSystem.Client.Helpers import CSGlobals
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getSites, getCESiteMapping
from DIRAC.ConfigurationSystem.Client.Helpers.Path import cfgPath
from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getCESiteMapping, getSites
from DIRAC.ConfigurationSystem.private.Modificator import Modificator
from DIRAC.Core.Security import Locations
from DIRAC.Core.Security.X509Chain import X509Chain # pylint: disable=import-error
from DIRAC.Core.Utilities import List


class CSAPI:
Expand Down
21 changes: 0 additions & 21 deletions src/DIRAC/Core/Security/VOMSService.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,6 @@ def __init__(self, vo=None):

self.userDict = None

def attGetUserNickname(self, dn, _ca=None):
"""Get user nickname for a given DN if any
:param str dn: user DN
:param str _ca: CA, kept for backward compatibility
:return: S_OK with Value: nickname
"""

if self.userDict is None:
result = self.getUsers()
if not result["OK"]:
return result

uDict = self.userDict.get(dn)
if not uDict:
return S_ERROR(DErrno.EVOMS, "No nickname defined")
nickname = uDict.get("nickname")
if not nickname:
return S_ERROR(DErrno.EVOMS, "No nickname defined")
return S_OK(nickname)

def getUsers(self):
"""Get all the users of the VOMS VO with their detailed information
Expand Down
7 changes: 5 additions & 2 deletions src/DIRAC/Core/scripts/dirac_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import os
import sys
import warnings

import urllib3

import DIRAC
Expand Down Expand Up @@ -235,9 +236,10 @@ def runConfigurationWizard(params):
"""Interactively configure DIRAC using metadata from installed extensions"""
import subprocess

from DIRAC.Core.Utilities.Extensions import extensionsByPriority, getExtensionMetadata
from prompt_toolkit import HTML, print_formatted_text, prompt

from DIRAC.Core.Utilities.Extensions import extensionsByPriority, getExtensionMetadata

for extension in extensionsByPriority():
extensionMetadata = getExtensionMetadata(extension)
if extensionMetadata.get("primary_extension", False):
Expand Down Expand Up @@ -302,13 +304,14 @@ def main():


def login(params):
from prompt_toolkit import HTML, print_formatted_text, prompt

from DIRAC.FrameworkSystem.private.authorization.utils.Tokens import (
getTokenFileLocation,
readTokenFromFile,
writeTokenDictToTokenFile,
)
from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory
from prompt_toolkit import HTML, print_formatted_text, prompt

# Init authorization client
result = IdProviderFactory().getIdProvider("DIRACCLI", issuer=params.issuer, scope=" ")
Expand Down
26 changes: 12 additions & 14 deletions src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,30 @@
import datetime
import errno
import os
from urllib import parse
import time

# from threading import current_thread
from multiprocessing.pool import ThreadPool

# We use the dummy module because we use the ThreadPool
from multiprocessing.dummy import current_process
from socket import gethostname

from DIRAC import S_OK, S_ERROR

# from threading import current_thread
from multiprocessing.pool import ThreadPool
from socket import gethostname
from urllib import parse

from DIRAC.MonitoringSystem.Client.DataOperationSender import DataOperationSender
from DIRAC import S_ERROR, S_OK
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations as opHelper
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername
from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getFTS3ServerDict
from DIRAC.Core.Base.AgentModule import AgentModule
from DIRAC.Core.Utilities.DErrno import cmpError
from DIRAC.Core.Utilities.DictCache import DictCache
from DIRAC.Core.Utilities.TimeUtilities import fromString
from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getFTS3ServerDict
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations as opHelper
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername
from DIRAC.DataManagementSystem.Client.FTS3Job import FTS3Job
from DIRAC.DataManagementSystem.DB.FTS3DB import FTS3DB
from DIRAC.DataManagementSystem.private import FTS3Utilities
from DIRAC.FrameworkSystem.Client.Logger import gLogger
from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager
from DIRAC.DataManagementSystem.private import FTS3Utilities
from DIRAC.DataManagementSystem.DB.FTS3DB import FTS3DB
from DIRAC.DataManagementSystem.Client.FTS3Job import FTS3Job
from DIRAC.MonitoringSystem.Client.DataOperationSender import DataOperationSender
from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient

# pylint: disable=attribute-defined-outside-init
Expand Down
7 changes: 2 additions & 5 deletions src/DIRAC/DataManagementSystem/Service/FTS3ManagerHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
:caption: FTS3Manager options
"""
from DIRAC import S_OK, S_ERROR, gLogger
from DIRAC import S_ERROR, S_OK, gLogger
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername
from DIRAC.Core.DISET.RequestHandler import RequestHandler, getServiceOption
from DIRAC.Core.Security.Properties import FULL_DELEGATION, LIMITED_DELEGATION
from DIRAC.Core.Utilities import DErrno
from DIRAC.Core.Utilities.JEncode import strToIntDict


from DIRAC.Core.Utilities.JEncode import decode, encode, strToIntDict
from DIRAC.DataManagementSystem.DB.FTS3DB import FTS3DB
from DIRAC.Core.Utilities.JEncode import encode, decode

########################################################################

Expand Down
3 changes: 1 addition & 2 deletions src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import MySQLdb
from diraccfg import CFG
from prompt_toolkit import prompt
from typing import cast

import DIRAC
from DIRAC import gConfig, gLogger, rootPath
Expand All @@ -85,10 +84,10 @@
JOB_ADMINISTRATOR,
NORMAL_USER,
OPERATOR,
PRODUCTION_MANAGEMENT,
PROXY_MANAGEMENT,
SERVICE_ADMINISTRATOR,
TRUSTED_HOST,
PRODUCTION_MANAGEMENT,
)
from DIRAC.Core.Utilities.Extensions import (
extensionsByPriority,
Expand Down
15 changes: 7 additions & 8 deletions src/DIRAC/FrameworkSystem/Service/TornadoTokenManagerHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@

import pprint

from DIRAC import S_OK, S_ERROR
from DIRAC import S_ERROR, S_OK
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
from DIRAC.Core.Security import Properties
from DIRAC.Core.Tornado.Server.TornadoService import TornadoService
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
from DIRAC.FrameworkSystem.Utilities.TokenManagementUtilities import (
getIdProviderClient,
DEFAULT_AT_EXPIRATION_TIME,
DEFAULT_RT_EXPIRATION_TIME,
getCachedKey,
getCachedToken,
DEFAULT_RT_EXPIRATION_TIME,
DEFAULT_AT_EXPIRATION_TIME,
getIdProviderClient,
)

from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory

# Used to synchronize the cache with user tokens
gTokensSync = ThreadSafe.Synchronizer()
Expand Down
37 changes: 17 additions & 20 deletions src/DIRAC/FrameworkSystem/scripts/dirac_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,41 @@
# Return token
$ dirac-login dirac_user --token
"""
import copy
import os
import sys
import copy
import datetime
import json
from pathlib import Path
from prompt_toolkit import prompt, print_formatted_text as print, HTML

from prompt_toolkit import HTML, prompt
from prompt_toolkit import print_formatted_text as print

import DIRAC
from DIRAC import gConfig, gLogger, S_OK, S_ERROR
from DIRAC.Core.Security.Locations import getDefaultProxyLocation, getCertificateAndKeyLocation
from DIRAC.Core.Security.VOMS import VOMS
from DIRAC import S_ERROR, S_OK, gConfig, gLogger
from DIRAC.Core.Base.Script import Script
from DIRAC.Core.Security.DiracX import addTokenToPEM
from DIRAC.Core.Security.Locations import getCertificateAndKeyLocation, getDefaultProxyLocation
from DIRAC.Core.Security.ProxyFile import writeToProxyFile
from DIRAC.Core.Security.ProxyInfo import getProxyInfo, formatProxyInfoAsString
from DIRAC.Core.Security.ProxyInfo import formatProxyInfoAsString, getProxyInfo
from DIRAC.Core.Security.VOMS import VOMS
from DIRAC.Core.Security.X509Chain import X509Chain # pylint: disable=import-error
from DIRAC.Core.Base.Script import Script
from DIRAC.Core.Base.Client import Client


# At this point, we disable CS synchronization so that an error related
# to the lack of a proxy certificate does not occur when trying to synchronize.
# Synchronization will take place after passing the authorization algorithm (creating a proxy).
Script.disableCS()

from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory
from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager
from DIRAC.FrameworkSystem.private.authorization.utils.Tokens import (
writeTokenDictToTokenFile,
readTokenFromFile,
getTokenFileLocation,
)
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import (
findDefaultGroupForDN,
getGroupOption,
getVOMSAttributeForGroup,
getVOMSVOForGroup,
findDefaultGroupForDN,
)
from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager
from DIRAC.FrameworkSystem.private.authorization.utils.Tokens import (
getTokenFileLocation,
readTokenFromFile,
writeTokenDictToTokenFile,
)
from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory

# This value shows what authorization way will be by default
DEFAULT_AUTH_WAY = "certificate" # possible values are "certificate", "diracas"
Expand Down
7 changes: 3 additions & 4 deletions src/DIRAC/FrameworkSystem/scripts/dirac_proxy_destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import os

import DIRAC
from DIRAC import gLogger, S_OK
from DIRAC import S_OK, gLogger
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
from DIRAC.Core.Base.Client import Client
from DIRAC.Core.Base.Script import Script

from DIRAC.Core.Security import Locations, ProxyInfo
from DIRAC.Core.Base.Client import Client
from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager
from DIRAC.ConfigurationSystem.Client.Helpers import Registry


class Params:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"""
import sys

from DIRAC import gLogger, S_OK
from DIRAC import S_OK, gLogger
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
from DIRAC.Core.Base.Script import Script
from DIRAC.FrameworkSystem.Client.ProxyManagerClient import ProxyManagerClient
from DIRAC.Core.Security import Properties
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
from DIRAC.FrameworkSystem.Client.ProxyManagerClient import ProxyManagerClient

userName = False

Expand Down
2 changes: 1 addition & 1 deletion src/DIRAC/Interfaces/API/DiracAdmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def checkProxyUploaded(self, userDN, userGroup, requiredTime):
Example usage:
>>> gLogger.notice(diracAdmin.setProxyPersistency( 'some DN', 'dirac group', True ))
>>> gLogger.notice(diracAdmin.checkProxyUploaded( 'some DN', 'dirac group', True ))
{'OK': True, 'Value' : True/False }
:param userDN: User DN
Expand Down
51 changes: 9 additions & 42 deletions src/DIRAC/Interfaces/Utilities/DCommands.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#!/usr/bin/env python
import glob
import json
import os.path
import random
import re
import uuid
import stat
import json
import random
import glob
import time
from configparser import ConfigParser, NoSectionError, NoOptionError
import uuid
from configparser import ConfigParser, NoOptionError, NoSectionError

import DIRAC
import DIRAC.Core.Security.ProxyInfo as ProxyInfo
import DIRAC.FrameworkSystem.Client.ProxyGeneration as ProxyGeneration
from DIRAC import S_OK, S_ERROR, gConfig, gLogger
from DIRAC.Core.Security.Locations import getCAsLocation
from DIRAC.Core.Security import Locations, VOMS
from DIRAC import S_ERROR, S_OK, gConfig, gLogger
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
from DIRAC.Core.Security import VOMS, Locations
from DIRAC.Core.Security.DiracX import addTokenToPEM
from DIRAC.Core.Security.Locations import getCAsLocation
from DIRAC.Core.Utilities.PrettyPrint import printTable
from DIRAC.FrameworkSystem.Client.BundleDeliveryClient import BundleDeliveryClient
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
from DIRAC.Resources.Catalog.FileCatalog import FileCatalog


# -----------------------------
# Proxy manipulation functions
# -----------------------------
Expand Down Expand Up @@ -530,16 +529,6 @@ def addVomsExt(self, proxy):
chain = result["Value"]
chain.dumpAllToFile(proxy)

def checkProxyOrInit(self):
create = False
try:
create = not self.proxyIsValid()
except:
create = True

if create:
self.proxyInit()

def getUserName(self):
proxyPath = _getProxyLocation()
if not proxyPath:
Expand Down Expand Up @@ -601,28 +590,6 @@ def guessConfigFromCS(config, section, userName, groupName):
config.set(section, "default_se", defaultSESite)


def sessionFromProxy(config=None, sessionDir=None):
session = DSession(None, config, sessionDir=sessionDir)
# force copy of config profile options to environment
session.copyProfile()
return session


def getDNFromProxy():
proxyPath = _getProxyLocation()
if not proxyPath:
gLogger.error("No proxy found")
return None

retVal = _getProxyInfo(proxyPath)
if not retVal["OK"]:
return retVal

pi = retVal["Value"]

return S_OK(pi["identity"])


# -------------------------
# DCommands FC/LFN helpers
# -------------------------
Expand Down
Loading

0 comments on commit eebd912

Please sign in to comment.