Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 7091072

Browse files
authored
role handling (#351)
1 parent 11bbb8a commit 7091072

File tree

2 files changed

+8
-62
lines changed

2 files changed

+8
-62
lines changed

libs/python/btp_cli.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import time
1616
import requests
1717
import json
18-
from libs.python.helperRolesAndUsers import assignUsersToEnvironments, assignUsersToGlobalAndSubaccount, getSubaccountAdmins, assignUsersToRoleCollectionsForServices, assignUsersToCustomRoleCollections
18+
from libs.python.helperRolesAndUsers import assignUsersToEnvironments, assignUsersToGlobalAndSubaccount, assignUsersToRoleCollectionsForServices, assignUsersToCustomRoleCollections
1919

2020
from libs.python.helperServices import BTPSERVICE, BTPSERVICEEncoder, getServiceParameterDefinition, readAllServicesFromUsecaseFile
2121
from libs.python.helperLog import initLogger
@@ -319,7 +319,10 @@ def create_subaccount(self):
319319
log.success("using subaccount name >" + subaccount + "<")
320320
log.success("using subaccount domain >" + subdomain + "<")
321321

322-
subaccountadmins = getSubaccountAdmins(self)
322+
# We add the owner of the execution as subaccount admin
323+
# The remaining list of subaccount admins is added via user groups and role collections
324+
subaccountadmins = '["' + self.myemail + '"]'
325+
323326
globalAccount = self.globalaccount
324327

325328
log.header("Create sub account >" + subaccount +

libs/python/helperRolesAndUsers.py

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
from libs.python.helperCommandExecution import runCommandAndGetJsonResult, runShellCommandFlex, runShellCommand
2-
# from libs.python.helperGeneric import save_collected_metadata
32
from libs.python.helperJson import getJsonFromFile
4-
# import re
5-
# import os
6-
# import sys
73
import logging
84

95
log = logging.getLogger(__name__)
@@ -26,54 +22,10 @@ def getMembersForRolecollection(btpUsecase, rolecollection):
2622
return users
2723

2824

29-
def getMembersForRolecollectionTypeAndLevel(btpUsecase, type, level):
30-
rolecollections = btpUsecase.definedRoleCollections
31-
32-
checkType = type is not None
33-
checkLevel = level is not None
34-
35-
users = []
36-
users.append(btpUsecase.myemail)
37-
if rolecollections:
38-
for rolecollection in rolecollections:
39-
thisType = rolecollection.get("type")
40-
thisLevel = rolecollection.get("level")
41-
addMembers = False
42-
if checkLevel is True and thisLevel == level:
43-
addMembers = True
44-
if checkType is True and thisType == type:
45-
addMembers = True
46-
if checkType is False and checkLevel is False:
47-
addMembers = True
48-
if addMembers is True:
49-
members = getMembersForRolecollection(
50-
btpUsecase, rolecollection)
51-
for member in members:
52-
users.append(member)
53-
users = list(dict.fromkeys(users))
54-
return users
55-
56-
57-
def getSubaccountAdmins(btpUsecase):
58-
result = "["
59-
60-
users = getMembersForRolecollectionTypeAndLevel(
61-
btpUsecase, "account", None)
62-
if users:
63-
for user in users:
64-
if user == users[-1]:
65-
result += '"' + user + '"]'
66-
else:
67-
result += '"' + user + '" , '
68-
else:
69-
result = "[]"
70-
71-
return result
72-
73-
7425
def getRoleCollectionsOfServices(btpUsecase):
7526
# Use case file can be remote, so we need to provide authentication information
76-
usecase = getJsonFromFile(btpUsecase.usecasefile, btpUsecase.externalConfigAuthMethod, btpUsecase.externalConfigUserName, btpUsecase.externalConfigPassword, btpUsecase.externalConfigToken)
27+
usecase = getJsonFromFile(btpUsecase.usecasefile, btpUsecase.externalConfigAuthMethod,
28+
btpUsecase.externalConfigUserName, btpUsecase.externalConfigPassword, btpUsecase.externalConfigToken)
7729
items = []
7830
if usecase.get("services") is not None:
7931
for service in usecase.get("services"):
@@ -148,15 +100,6 @@ def assignUsergroupsToRoleCollection(btpUsecase, rolecollection):
148100
"Checkout the default parameters file and the other released use cases to understand how to do it.")
149101

150102

151-
def getSelfDefinedRoleCollections(btpUsecase):
152-
items = []
153-
if btpUsecase.definedRoleCollections:
154-
for rolecollection in btpUsecase.definedRoleCollections:
155-
items.append(rolecollection)
156-
157-
return items
158-
159-
160103
def getRoleCollectionsOfTypeAndLevel(btpUsecase, type, level):
161104
rolecollections = btpUsecase.definedRoleCollections
162105
checkType = type is not None
@@ -384,4 +327,4 @@ def determineIdpForRoleCollection(btpUsecase, rolecollection):
384327
# A role collection specific IdP is configured - overrules the default IdP
385328
idp = rolecollection.get("idp")
386329

387-
return idp
330+
return idp

0 commit comments

Comments
 (0)