Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rverdile committed Nov 21, 2024
1 parent 0cd4904 commit d6c64aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
20 changes: 10 additions & 10 deletions src/rhsmlib/dbus/objects/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@

log = logging.getLogger(__name__)

ENVIRONMENTS_KEYS_TO_FILTER: List[str] = [
"contentPrefix",
"created",
"environmentContent",
"owner",
"updated",
]


class RegisterDBusImplementation(base_object.BaseImplementation):
def __init__(self):
Expand Down Expand Up @@ -191,18 +199,10 @@ def get_environments(self, options: dict) -> List[dict]:
uep: UEPConnection = self.build_uep(options, basic_auth_method=True)
environment_service: EnvironmentService = EnvironmentService(uep)

environments = environment_service.list(options["org_id"], typed_environments=True)

keys_to_remove: List[str] = [
"created",
"updated",
"contentPrefix",
"owner",
"environmentContent",
]
environments = environment_service.list(options["org_id"])

for environment in environments:
for key in keys_to_remove:
for key in ENVIRONMENTS_KEYS_TO_FILTER:
environment.pop(key, None)
if ("type" not in environment) or (environment["type"] is None):
environment["type"] = ""
Expand Down
17 changes: 5 additions & 12 deletions src/rhsmlib/services/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017 Red Hat, Inc.
# Copyright (c) 2024 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
Expand All @@ -23,30 +23,23 @@

class EnvironmentService:
"""
Class for listing environments
Class for using environments
"""

def __init__(self, cp: UEPConnection) -> None:
"""
Initialization of EnvironmentService instance
:param cp: instance of connection?
:param cp: connection to Candlepin
"""
self.plugin_manager = inj.require(inj.PLUGIN_MANAGER)
self.cp = cp

def list(self, org_id: str, typed_environments: bool = True) -> List[dict]:
def list(self, org_id: str) -> List[dict]:
"""
Method for listing environments
:param org_id: organization to list environments for
:param typed_environments: Whether output should include typed environments
:return: List of environments.
"""
list_all = False
if typed_environments:
list_all = self.cp.has_capability("typed_environments")
if not list_all:
log.debug("candlepin does not have typed_environments capability")

list_all = self.cp.has_capability("typed_environments")
environments = self.cp.getEnvironmentList(org_id, list_all=list_all)

return environments
8 changes: 1 addition & 7 deletions test/rhsmlib/services/test_environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017 Red Hat, Inc.
# Copyright (c) 2024 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
Expand Down Expand Up @@ -75,9 +75,3 @@ def test_list_environments(self):

result = environment.EnvironmentService(self.mock_cp).list("org")
self.assertEqual(ENVIRONMENTS_JSON, result)

def test_list_environments_without_typed_environments(self):
self.mock_cp.getEnvironmentList.return_value = ENVIRONMENTS_JSON

result = environment.EnvironmentService(self.mock_cp).list("org", typed_environments=False)
self.assertEqual(ENVIRONMENTS_JSON, result)

0 comments on commit d6c64aa

Please sign in to comment.