Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional, Union

from java.io import Closeable
from java.lang import Object
from java.lang import Exception, Object, Throwable
from java.nio.charset import Charset


Expand Down Expand Up @@ -35,3 +35,9 @@ def getAsString(self):
def getBytes(self):
# type: () -> bytearray
pass


class SecretException(Exception):
def __init__(self, message, cause=None):
# type: (str, Optional[Throwable]) -> None
super(SecretException, self).__init__(message, cause)
72 changes: 71 additions & 1 deletion src/system/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
from __future__ import print_function

__all__ = [
"createEmbeddedSecretConfig",
"createReferencedSecretConfig",
"decrypt",
"encrypt",
"getProviders",
"getSecrets",
"readConfiguredSecretValue",
"readSecretValue",
]

Expand All @@ -21,7 +24,52 @@
SecretMeta,
SecretProviderMeta,
)
from com.inductiveautomation.ignition.gateway.secrets import Plaintext
from com.inductiveautomation.ignition.gateway.secrets import Plaintext, SecretException
from org.python.core import PyObject


def createEmbeddedSecretConfig(json):
# type: (Any) -> PyObject
"""Creates a new Embedded SecretConfig instance given the JSON
representation of the encrypted data.

Args:
json: The JSON object containing the encrypted secret.

Returns:
A Dictionary containing the JSON representation of an Embedded
SecretConfig instance containing the encrypted secret.

Raises:
ValueError: Throws a ValueError if there is no JSON.
"""
if not json:
raise ValueError("No JSON provided for creating an Embedded SecretConfig.")
return PyObject()


def createReferencedSecretConfig(providerName, secretName):
# type: (Union[str, unicode], Union[str, unicode]) -> PyObject
"""Creates a new Referenced SecretConfig instance given the name of
the secret provider and the name of the secret stored in the
provider.

Args:
providerName: The name of the Secret Provider to reference.
secretName: The name of the secret to reference.

Returns:
PyObject: A Dictionary containing the JSON representation of a
Referenced SecretConfig instance with the provider and
secret names.

Raises:
ValueError: Throws a ValueError if the providerName or
secretName parameters do not have any values.
"""
if not providerName or not secretName:
raise ValueError("Both providerName and secretName must be provided.")
return PyObject()


def decrypt(json):
Expand Down Expand Up @@ -96,6 +144,28 @@ def getSecrets(providerName):
return [SecretMeta("SecretName")]


def readConfiguredSecretValue(secretConfig):
# type: (Any) -> PyPlaintext
"""Reads the value of a secret configured by its SecretConfig.

Args:
secretConfig: The JSON object containing the SecretConfig.

Returns:
A PyPlaintext instance containing the specified secret.

Raises:
ValueError: Throws a ValueError if there is no JSON.
SecretException: Throws a SecretException if there is a problem
reading the secret.
"""
if not secretConfig:
raise ValueError("There is no JSON.")
if not isinstance(secretConfig, dict):
raise SecretException("There is a problem reading the secret.")
return PyPlaintext(Plaintext())


def readSecretValue(providerName, secretName):
# type: (Union[str, unicode], Union[str, unicode]) -> PyPlaintext
"""Reads the plaintext value of a secret given the name of the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Optional, Union

from java.io import Closeable
from java.lang import Object
from java.lang import Exception, Object
from java.lang import Throwable as Throwable
from java.nio.charset import Charset as Charset

class Plaintext(Object, Closeable):
Expand All @@ -16,3 +17,6 @@ class Plaintext(Object, Closeable):
) -> Plaintext: ...
def getAsString(self) -> Union[str, unicode]: ...
def getBytes(self) -> bytearray: ...

class SecretException(Exception):
def __init__(self, message: str, cause: Optional[Throwable] = ...) -> None: ...
6 changes: 6 additions & 0 deletions stubs/stubs/system/secrets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ from com.inductiveautomation.ignition.common.secrets import (
SecretMeta,
SecretProviderMeta,
)
from org.python.core import PyObject

def createEmbeddedSecretConfig(json: Any) -> PyObject: ...
def createReferencedSecretConfig(
providerName: Union[str, unicode], secretName: Union[str, unicode]
) -> PyObject: ...
def decrypt(json: Any) -> PyPlaintext: ...
def encrypt(*args: Any) -> Dict[Union[str, unicode], Any]: ...
def getProviders() -> List[SecretProviderMeta]: ...
def getSecrets(providerName: Union[str, unicode]) -> List[SecretMeta]: ...
def readConfiguredSecretValue(secretConfig: Any) -> PyPlaintext: ...
def readSecretValue(
providerName: Union[str, unicode], secretName: Union[str, unicode]
) -> PyPlaintext: ...