Skip to content

Commit

Permalink
feat: Enable register with environment names
Browse files Browse the repository at this point in the history
* Allow to register with environment names, not only environment
  IDs. it is possible to use username & password and
  activation keys & organization
* Modified few unit tests
  • Loading branch information
jirihnidek committed Dec 9, 2024
1 parent 55e250d commit 8a9bbeb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/rhsm/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,7 @@ def registerConsumer(
facts: Optional[dict] = None,
owner: str = None,
environments: str = None,
environment_names: str = None,
keys: str = None,
installed_products: list = None,
uuid: str = None,
Expand Down Expand Up @@ -1576,7 +1577,12 @@ def registerConsumer(
params["usage"] = usage
if service_level is not None:
params["serviceLevel"] = service_level
if environments is not None and self.has_capability(MULTI_ENV):
if environment_names is not None and self.has_capability(MULTI_ENV):
env_name_list = []
for env_name in environment_names.split(","):
env_name_list.append({"name": env_name})
params["environments"] = env_name_list
elif environments is not None and self.has_capability(MULTI_ENV):
env_list = []
for environment in environments.split(","):
env_list.append({"id": environment})
Expand Down
3 changes: 3 additions & 0 deletions src/rhsmlib/services/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def register(
org: Optional[str],
activation_keys: list = None,
environments: list = None,
environment_names: list = None,
force: bool = False,
name: str = None,
consumerid: str = None,
Expand Down Expand Up @@ -95,6 +96,7 @@ def register(
options = {
"activation_keys": activation_keys,
"environments": environments,
"environment_names": environment_names,
"force": force,
"name": name,
"consumerid": consumerid,
Expand Down Expand Up @@ -123,6 +125,7 @@ def register(
facts=facts_dict,
owner=org,
environments=environments,
environment_names=environment_names,
keys=options.get("activation_keys"),
installed_products=self.installed_mgr.format_for_server(),
content_tags=self.installed_mgr.tags,
Expand Down
4 changes: 4 additions & 0 deletions test/rhsmlib/services/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def test_register_normally(self, mock_persist_consumer, mock_write_cache):
facts={},
owner="org",
environments="environment",
environment_names=None,
keys=None,
installed_products=[],
jwt_token=None,
Expand Down Expand Up @@ -348,6 +349,7 @@ def _no_owner_cb(username):
facts={},
owner="snowwhite",
environments="environment",
environment_names=None,
keys=None,
installed_products=[],
jwt_token=None,
Expand Down Expand Up @@ -388,6 +390,7 @@ def test_register_with_activation_keys(self, mock_persist_consumer, mock_write_c
facts={},
owner="org",
environments=None,
environment_names=None,
keys=[1],
installed_products=[],
jwt_token=None,
Expand Down Expand Up @@ -473,6 +476,7 @@ def test_reads_syspurpose(self, mock_persist_consumer, mock_write_cache):
addons=["addon1"],
content_tags=[],
environments=None,
environment_names=None,
facts={},
installed_products=[],
jwt_token=None,
Expand Down

0 comments on commit 8a9bbeb

Please sign in to comment.