Skip to content

Commit 01573e8

Browse files
committed
fix: added possibility to specify a TokenOwner
1 parent 80abd40 commit 01573e8

File tree

6 files changed

+51
-35
lines changed

6 files changed

+51
-35
lines changed

src/DIRAC/Core/scripts/dirac_install_db.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def main():
3333
DIRACExit(1)
3434

3535
if db != "InstalledComponentsDB":
36-
3736
# get the user that installed the DB
3837
if useServerCertificate():
3938
user = "DIRAC"

src/DIRAC/DataManagementSystem/scripts/dirac_admin_allow_se.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def main():
1717
remove = False
1818
site = ""
1919
mute = False
20+
userName = ""
2021

2122
Script.registerSwitch("r", "AllowRead", " Allow only reading from the storage element")
2223
Script.registerSwitch("w", "AllowWrite", " Allow only writing to the storage element")
@@ -25,6 +26,7 @@ def main():
2526
Script.registerSwitch("a", "All", " Allow all access to the storage element")
2627
Script.registerSwitch("m", "Mute", " Do not send email")
2728
Script.registerSwitch("S:", "Site=", " Allow all SEs associated to site")
29+
Script.registerSwitch("t:", "tokenOwner=", " Optional Name of the token owner")
2830
# Registering arguments will automatically add their description to the help menu
2931
Script.registerArgument(["seGroupList: list of SEs or comma-separated SEs"])
3032

@@ -48,6 +50,8 @@ def main():
4850
mute = True
4951
if switch[0].lower() in ("s", "site"):
5052
site = switch[1]
53+
if switch[0] in ("t", "tokenOwner"):
54+
userName = switch[1]
5155

5256
# imports
5357
from DIRAC import gLogger
@@ -69,15 +73,16 @@ def main():
6973
ses = resolveSEGroup(ses)
7074
diracAdmin = DiracAdmin()
7175

72-
res = getProxyInfo()
73-
if not res["OK"]:
74-
gLogger.error("Failed to get proxy information", res["Message"])
75-
DIRAC.exit(2)
76-
77-
userName = res["Value"].get("username")
7876
if not userName:
79-
gLogger.error("Failed to get username for proxy")
80-
DIRAC.exit(2)
77+
res = getProxyInfo()
78+
if not res["OK"]:
79+
gLogger.error("Failed to get proxy information", res["Message"])
80+
DIRAC.exit(2)
81+
82+
userName = res["Value"].get("username")
83+
if not userName:
84+
gLogger.error("Failed to get username for proxy")
85+
DIRAC.exit(2)
8186

8287
if site:
8388
res = getSites()

src/DIRAC/DataManagementSystem/scripts/dirac_admin_ban_se.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def main():
1818
remove = True
1919
sites = []
2020
mute = False
21+
userName = ""
2122

2223
Script.registerSwitch("r", "BanRead", " Ban only reading from the storage element")
2324
Script.registerSwitch("w", "BanWrite", " Ban writing to the storage element")
@@ -28,6 +29,7 @@ def main():
2829
Script.registerSwitch(
2930
"S:", "Site=", " Ban all SEs associate to site (note that if writing is allowed, check is always allowed)"
3031
)
32+
Script.registerSwitch("t:", "tokenOwner=", " Optional Name of the token owner")
3133
# Registering arguments will automatically add their description to the help menu
3234
Script.registerArgument(["seGroupList: list of SEs or comma-separated SEs"])
3335

@@ -56,6 +58,8 @@ def main():
5658
mute = True
5759
if switch[0].lower() in ("s", "site"):
5860
sites = switch[1].split(",")
61+
if switch[0] in ("t", "tokenOwner"):
62+
userName = switch[1]
5963

6064
# from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI
6165
from DIRAC import gLogger
@@ -68,15 +72,16 @@ def main():
6872
ses = resolveSEGroup(ses)
6973
diracAdmin = DiracAdmin()
7074

71-
res = getProxyInfo()
72-
if not res["OK"]:
73-
gLogger.error("Failed to get proxy information", res["Message"])
74-
DIRAC.exit(2)
75-
76-
userName = res["Value"].get("username")
7775
if not userName:
78-
gLogger.error("Failed to get username for proxy")
79-
DIRAC.exit(2)
76+
res = getProxyInfo()
77+
if not res["OK"]:
78+
gLogger.error("Failed to get proxy information", res["Message"])
79+
DIRAC.exit(2)
80+
81+
userName = res["Value"].get("username")
82+
if not userName:
83+
gLogger.error("Failed to get username for proxy")
84+
DIRAC.exit(2)
8085

8186
for site in sites:
8287
res = DMSHelpers().getSEsForSite(site)

src/DIRAC/ResourceStatusSystem/scripts/dirac_rss_set_status.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
"""
77
from datetime import datetime, timedelta
88

9-
from DIRAC import S_OK
9+
from DIRAC import S_OK, gLogger
1010
from DIRAC import exit as DIRACExit
11-
from DIRAC import gLogger
1211
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
1312
from DIRAC.Core.Base.Script import Script
1413
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
@@ -29,6 +28,7 @@ def registerSwitches():
2928
("status=", "Status to be changed"),
3029
("reason=", "Reason to set the Status"),
3130
("VO=", "VO to change a status for. When omitted, status will be changed for all VOs"),
31+
("tokenOwner=", "Owner of the token"),
3232
)
3333

3434
for switch in switches:
@@ -136,6 +136,9 @@ def unpack(switchDict):
136136
switchDictClone["statusType"] = None
137137
switchDictSet.append(switchDictClone)
138138

139+
for sd in switchDictSet:
140+
sd.update({"tokenOwner": switchDict.get("tokenOwner")})
141+
139142
return switchDictSet
140143

141144

@@ -215,14 +218,16 @@ def run(switchDict):
215218
Main function of the script
216219
"""
217220

218-
tokenOwner = getTokenOwner()
219-
if not tokenOwner["OK"]:
220-
gLogger.error(tokenOwner["Message"])
221-
DIRACExit(1)
222-
tokenOwner = tokenOwner["Value"]
221+
tokenOwner = switchDict.get("tokenOwner")
222+
if tokenOwner is None:
223+
tokenOwner = getTokenOwner()
224+
if not tokenOwner["OK"]:
225+
gLogger.error(tokenOwner["Message"])
226+
DIRACExit(1)
227+
tokenOwner = tokenOwner["Value"]
223228

224229
gLogger.notice(f"TokenOwner is {tokenOwner}")
225-
230+
print(switchDict)
226231
result = setStatus(switchDict, tokenOwner)
227232
if not result["OK"]:
228233
gLogger.error(result["Message"])
@@ -236,7 +241,9 @@ def main():
236241
# Script initialization
237242
registerSwitches()
238243
switchDict = parseSwitches()
244+
print(switchDict)
239245
switchDictSets = unpack(switchDict)
246+
print(switchDictSets)
240247

241248
# Run script
242249
for switchDict in switchDictSets:

tests/Jenkins/dirac_ci.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,18 +383,18 @@ fullInstallDIRAC() {
383383

384384
# populate RSS
385385
echo "==> Populating RSS DB"
386-
dirac-rss-sync --element Site --defaultStatus Banned -o LogLevel=VERBOSE -o /DIRAC/Security/UseServerCertificate=True
387-
dirac-rss-sync --element Resource --defaultStatus Banned -o LogLevel=VERBOSE -o /DIRAC/Security/UseServerCertificate=True
386+
dirac-rss-sync --element Site --defaultStatus Banned -o LogLevel=VERBOSE -o /DIRAC/Security/UseServerCertificate=True
387+
dirac-rss-sync --element Resource --defaultStatus Banned -o LogLevel=VERBOSE -o /DIRAC/Security/UseServerCertificate=True
388388
# init RSS
389389
echo "==> Initializing status of sites and resources in RSS"
390-
dirac-rss-sync --init --defaultStatus Banned -o LogLevel=VERBOSE -o /DIRAC/Security/UseServerCertificate=True
390+
dirac-rss-sync --init --defaultStatus Banned -o LogLevel=VERBOSE -o /DIRAC/Security/UseServerCertificate=True
391391
# Setting by hand
392-
dirac-rss-set-status --element Resource --name ProductionSandboxSE --status Active --reason "Why not?" -o /DIRAC/Security/UseServerCertificate=True
393-
dirac-rss-set-status --element Resource --name jenkins.cern.ch --status Active --reason "Why not?" -o /DIRAC/Security/UseServerCertificate=True
394-
dirac-rss-set-status --element Resource --name JENKINS-FTS3 --status Active --reason "Why not?" -o /DIRAC/Security/UseServerCertificate=True
395-
dirac-rss-set-status --element Resource --name FileCatalog --status Active --reason "Why not?" -o /DIRAC/Security/UseServerCertificate=True
396-
dirac-rss-set-status --element Site --name DIRAC.Jenkins.ch --status Active --reason "Why not?" -o /DIRAC/Security/UseServerCertificate=True
397-
dirac-admin-allow-se SE-1 SE-2 S3-DIRECT S3-INDIRECT --All -o /DIRAC/Security/UseServerCertificate=True
392+
dirac-rss-set-status --element Resource --name ProductionSandboxSE --status Active --reason "Why not?" --tokenOwner DIRAC -o /DIRAC/Security/UseServerCertificate=True
393+
dirac-rss-set-status --element Resource --name jenkins.cern.ch --status Active --reason "Why not?" --tokenOwner DIRAC -o /DIRAC/Security/UseServerCertificate=True
394+
dirac-rss-set-status --element Resource --name JENKINS-FTS3 --status Active --reason "Why not?" --tokenOwner DIRAC -o /DIRAC/Security/UseServerCertificate=True
395+
dirac-rss-set-status --element Resource --name FileCatalog --status Active --reason "Why not?" --tokenOwner DIRAC -o /DIRAC/Security/UseServerCertificate=True
396+
dirac-rss-set-status --element Site --name DIRAC.Jenkins.ch --status Active --reason "Why not?" --tokenOwner DIRAC -o /DIRAC/Security/UseServerCertificate=True
397+
dirac-admin-allow-se SE-1 SE-2 S3-DIRECT S3-INDIRECT --All --tokenOwner DIRAC -o /DIRAC/Security/UseServerCertificate=True
398398

399399
#agents
400400
findAgents

tests/Jenkins/utilities.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ diracOptimizers(){
707707
local executors=$(cat executors | grep WorkloadManagementSystem | cut -d ' ' -f 2 | grep -v Base)
708708
for executor in $executors
709709
do
710-
echo "==> calling dirac-install-component WorkloadManagement/$executor"
710+
echo "==> calling dirac-install-component WorkloadManagement/$executor -o /DIRAC/Security/UseServerCertificate=True"
711711
if ! dirac-install-component "WorkloadManagement/$executor" -o /DIRAC/Security/UseServerCertificate=True "${DEBUG}"; then
712712
echo 'ERROR: dirac-install-component failed' >&2
713713
exit 1

0 commit comments

Comments
 (0)