Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/927 add env settings #4603

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 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
5 changes: 5 additions & 0 deletions changelogs/unreleased/927-add-env-settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: add the possibility to add extra settings to the env from outside of inmanta-core
issue-nr: 927
issue-repo: inmanta-lsm
change-type: minor
destination-branches: [master, iso5]
10 changes: 10 additions & 0 deletions src/inmanta/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,16 @@ async def get_next_version(self) -> int:
self.last_version = version
return version

async def register_setting(self, setting: Setting) -> None:
"""
Adds a new setting in this environment.
arnaudsjs marked this conversation as resolved.
Show resolved Hide resolved

:param setting: the setting that should be added to the existing settings
"""
if setting.name in self._settings:
raise KeyError()
self._settings[setting.name] = setting

@classmethod
async def get_list(
cls: Type[TBaseDocument],
Expand Down
45 changes: 45 additions & 0 deletions tests/server/test_env_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@

Contact: code@inmanta.com
"""
import uuid
from typing import Dict

import pytest

from inmanta import data
from inmanta.data import Setting, convert_boolean
from inmanta.util import get_compiler_version


Expand Down Expand Up @@ -314,3 +318,44 @@ async def test_default_value_purge_on_delete_setting(server, client):
result = await client.get_setting(tid=env_id, id=data.PURGE_ON_DELETE)
assert result.code == 200
assert result.result["value"] is False


async def test_environment_add_new_setting_parameter(server, client, environment):
new_setting: Setting = Setting(
name="a new boolean setting",
default=False,
typ="bool",
validator=convert_boolean,
doc="a new setting",
)
env = await data.Environment.get_by_id(uuid.UUID(environment))
await env.register_setting(new_setting)

result = await client.get_setting(tid=environment, id="a new boolean setting")
assert result.code == 200
assert result.result["value"] is False

result = await client.set_setting(tid=environment, id="a new boolean setting", value=True)
assert result.code == 200

result = await client.get_setting(tid=environment, id="a new boolean setting")
assert result.code == 200
assert result.result["value"] is True

result = await client.get_setting(tid=environment, id=data.AUTO_DEPLOY)
assert result.code == 200
assert result.result["value"] is False

existing_setting: Setting = Setting(
name=data.AUTO_DEPLOY,
default=False,
typ="bool",
validator=convert_boolean,
doc="a new setting",
)
with pytest.raises(KeyError):
await env.register_setting(existing_setting)

result = await client.get_setting(tid=environment, id=data.AUTO_DEPLOY)
assert result.code == 200
assert result.result["value"] is False