Skip to content

Commit bf238b2

Browse files
P3) (Optoro) Allow variable to be secret in the UI, but gettable in functions, and prevent secret variables from being made non-secret (#42)
* secret -> secrecy - updated python client * comment fixed
1 parent d02bae3 commit bf238b2

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

polyapi/typedefs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ class SpecificationDto(TypedDict):
4040
language: str
4141

4242

43+
# Enum for variable secrecy levels
44+
Secrecy = Literal['SECRET', 'OBSCURED', 'NONE']
45+
46+
4347
class VariableSpecification(TypedDict):
4448
environmentId: str
4549
value: Any
4650
valueType: PropertyType
47-
secret: bool
51+
secrecy: Secrecy
4852

4953

5054
class VariableSpecDto(TypedDict):

polyapi/variables.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from typing import List
33

44
from polyapi.schema import map_primitive_types
5-
from polyapi.typedefs import PropertyType, VariableSpecDto
5+
from polyapi.typedefs import PropertyType, VariableSpecDto, Secrecy
66
from polyapi.utils import add_import_to_init, init_the_init
77

88

9-
# GET is only included if the variable is not a secret
9+
# GET is only included if the variable is not SECRET
1010
GET_TEMPLATE = """
1111
@staticmethod
1212
def get() -> {variable_type}:
@@ -76,9 +76,10 @@ def generate_variables(variables: List[VariableSpecDto]):
7676

7777
def render_variable(variable: VariableSpecDto):
7878
variable_type = _get_variable_type(variable["variable"]["valueType"])
79+
# Only include get() method if secrecy is not SECRET
7980
get_method = (
8081
""
81-
if variable["variable"]["secret"]
82+
if variable["variable"]["secrecy"] == "SECRET"
8283
else GET_TEMPLATE.format(
8384
variable_id=variable["id"], variable_type=variable_type
8485
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
33

44
[project]
55
name = "polyapi-python"
6-
version = "0.3.5.dev1"
6+
version = "0.3.6.dev0"
77
description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
88
authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
99
dependencies = [

tests/test_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"variable": {
1414
"environmentId": "123818231",
15-
"secret": False,
15+
"secrecy": "NONE",
1616
"valueType": {
1717
"kind": "primitive",
1818
"type": "string"

0 commit comments

Comments
 (0)