From 0f7a56dd2be537c2ca3f4da7c6396ff5e1e312b0 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Fri, 12 Apr 2024 02:23:59 +1200 Subject: [PATCH] feat(config): support `type:secret` in config.options (#1623) The `config.options` section of `charmcraft.yaml` supports, from Juju 3.1, a type `secret` (this is currently missing from the documentation, but the Juju team are addressing that now). This adds support for that, so that Charmcraft 2.5 can be used to pack charms that make use of this functionality. --- charmcraft/models/config.py | 4 ++-- tests/test_models.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/charmcraft/models/config.py b/charmcraft/models/config.py index 550d2fd17..464f1618b 100644 --- a/charmcraft/models/config.py +++ b/charmcraft/models/config.py @@ -50,10 +50,10 @@ def validate_actions(cls, options): if "type" not in option: raise ValueError(f"'{name}' is missing a type") - if option["type"] not in ["string", "int", "float", "boolean"]: + if option["type"] not in ["string", "int", "float", "boolean", "secret"]: raise ValueError( f"'{option}' has an invalid type '{option['type']}', " - "must be one of: string, int, float, boolean" + "must be one of: string, int, float, boolean, secret" ) return options diff --git a/tests/test_models.py b/tests/test_models.py index 90ee8446d..2eda78678 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1135,6 +1135,8 @@ def test_load_config_in_charmcraft_yaml(tmp_path, prepare_charmcraft_yaml): test-bool: default: true type: boolean + test-secret: + type: secret """ ) ) @@ -1146,6 +1148,7 @@ def test_load_config_in_charmcraft_yaml(tmp_path, prepare_charmcraft_yaml): "test-string": {"description": "test-2", "type": "string"}, "test-float": {"default": 1.23, "type": "float"}, "test-bool": {"default": True, "type": "boolean"}, + "test-secret": {"type": "secret"}, }, } @@ -1179,6 +1182,8 @@ def test_load_config_in_config_yaml(tmp_path, prepare_charmcraft_yaml, prepare_c test-bool: default: true type: boolean + test-secret: + type: secret """ ), ) @@ -1190,6 +1195,7 @@ def test_load_config_in_config_yaml(tmp_path, prepare_charmcraft_yaml, prepare_c "test-string": {"description": "test-2", "type": "string"}, "test-float": {"default": 1.23, "type": "float"}, "test-bool": {"default": True, "type": "boolean"}, + "test-secret": {"type": "secret"}, }, } @@ -1248,6 +1254,8 @@ def test_load_bad_config_in_charmcraft_yaml(tmp_path, prepare_charmcraft_yaml): test-bool: default: true type: boolean + test-secret: + type: secret """ ) )