Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions automation/argo_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def create_user(
tenant_name: str,
username: str,
role: str,
component: str
):
"""Http call to web-api to create a user"""
logger.debug(
Expand All @@ -31,6 +32,7 @@ def create_user(
"name": username,
"email": self.config.argo_ops_email,
"roles": [role],
"component": component
}

url = f"https://{self.config.web_api_endpoint}/api/v2/admin/tenants/{tenant_id}/users"
Expand Down Expand Up @@ -128,12 +130,12 @@ def create_ops_profile(
f"tenant: {tenant_name} ({tenant_id}) - web-api ops profile created"
)

def get_username(
self, tenant_id: str, tenant_name: str, username: str
def get_component_user(
self, tenant_id: str, tenant_name: str, component: str
) -> Optional[Dict]:
"""Http call to web-api to check if a username exists"""
"""Http call to web-api to check if a component user exists"""
logger.debug(
f"tenant: {tenant_name} ({tenant_id}) - web-api checking username: {username}..."
f"tenant: {tenant_name} ({tenant_id}) - web-api checking user for component: {component}..."
)

url = f"https://{self.config.web_api_endpoint}/api/v2/admin/tenants/{tenant_id}/users"
Expand All @@ -146,7 +148,7 @@ def get_username(

users = response.json().get("data")
if users:
return next((user for user in users if user["name"] == username), None)
return next((user for user in users if user.get("component") == component), None)
return None

def get_user(self, tenant_id: str, tenant_name: str, user_id: str):
Expand Down
24 changes: 12 additions & 12 deletions automation/init_compute_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ def init_compute_engine(
poem_username = f"argo_poem_admin_{tenant_name}"
poem_viewer_username = f"argo_poem_viewer_{tenant_name}"

# map users and roles and create them
user_roles = [
(engine_username, "admin"),
(monbox_username, "admin"),
(probe_username, "viewer"),
(ui_username, "admin_ui"),
(poem_username, "admin"),
(poem_viewer_username, "viewer"),
# map users roles and components
users_roles_comps = [
(engine_username, "admin", "engine"),
(monbox_username, "admin", "monbox"),
(probe_username, "viewer", "probe"),
(ui_username, "admin_ui", "ui"),
(poem_username, "admin", "poem-admin"),
(poem_viewer_username, "viewer", "poem-viewer"),
]

engine_user_key = None

for username, role in user_roles:
for username, role, component in users_roles_comps:

logger.info(f"engine tenant {tenant_name} - creating user: {username}")
# check if user exists already
user = web_api.get_username(tenant_id, tenant_name, username)
# check if user for specific component exists
user = web_api.get_component_user(tenant_id, tenant_name, username)
if user:
# user exists
logger.info(f"engine tenant {tenant_name} - user: {username} exists!")
Expand All @@ -48,7 +48,7 @@ def init_compute_engine(

else:
# create the user
user = web_api.create_user(tenant_id, tenant_name, username, role)
user = web_api.create_user(tenant_id, tenant_name, username, role, component)
if user and username == engine_username:
engine_user_key = user.get("api_key")

Expand Down
4 changes: 4 additions & 0 deletions automation/init_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def init_mongo(

# types of indexing
index_desc_dateint_id = [("date_integer", DESCENDING), ("id", ASCENDING)]
index_desc_dateint_name = [("date_integer", DESCENDING), ("name", ASCENDING)]
index_dateint_report = [("date_integer", ASCENDING), ("report", ASCENDING)]
index_dateint_host = [("date_integer", ASCENDING), ("host", ASCENDING)]
index_report_dateint = [("report", ASCENDING), ("date_integer", ASCENDING)]
Expand All @@ -45,6 +46,9 @@ def init_mongo(
("status_services", index_report_dateint),
("threshold_profiles", index_desc_dateint_id),
("weights", index_desc_dateint_id),
("topology_endpoints",index_desc_dateint_id),
("topology_groups",index_desc_dateint_id),
("topology_service_types",index_desc_dateint_name)
]

for collection_name, index_type in indexes:
Expand Down
Loading