Skip to content

refactor(system): add system.secrets functions#57

Merged
cesarcoatl merged 2 commits into
8.3from
refactor/system/secrets
Jul 17, 2026
Merged

refactor(system): add system.secrets functions#57
cesarcoatl merged 2 commits into
8.3from
refactor/system/secrets

Conversation

@cesarcoatl

@cesarcoatl cesarcoatl commented Jul 17, 2026

Copy link
Copy Markdown
Member
  • createEmbeddedSecretConfig
  • createReferencedSecretConfig
  • readConfiguredSecretValue

Closes: #55

Summary by Sourcery

Introduce new system secrets configuration helpers and supporting exception type.

New Features:

  • Add helpers to create embedded and referenced SecretConfig objects from JSON or provider/secret names.
  • Add a helper to read a secret value from a SecretConfig JSON object.

Enhancements:

  • Export new system.secrets functions and update stubs for type hints and API surface.

- createEmbeddedSecretConfig
- createReferencedSecretConfig
- readConfiguredSecretValue

Closes: #55
@sourcery-ai

sourcery-ai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR adds new system.secrets helper functions for creating secret configurations and reading their values, and introduces a SecretException type in the gateway secrets package with corresponding stub updates.

File-Level Changes

Change Details Files
Add helper functions to construct secret configuration objects and read secrets from configuration JSON.
  • Export new helpers in system.secrets all list
  • Implement createEmbeddedSecretConfig with JSON validation and PyObject return stub
  • Implement createReferencedSecretConfig with provider/secret name validation and PyObject return stub
  • Implement readConfiguredSecretValue with JSON type validation and SecretException usage
src/system/secrets.py
stubs/stubs/system/secrets.pyi
Introduce a SecretException type in the gateway secrets package and wire it into Python type stubs.
  • Extend java.lang imports to include Exception and Throwable in gateway secrets package
  • Define SecretException class subclassing Exception with message and optional cause
  • Mirror SecretException definition in type stubs with appropriate typing imports
src/com/inductiveautomation/ignition/gateway/secrets/__init__.py
stubs/stubs/com/inductiveautomation/ignition/gateway/secrets/__init__.pyi

Assessment against linked issues

Issue Objective Addressed Explanation
#55 Add the system.secrets.createEmbeddedSecretConfig() scripting function, including its export and type stubs.
#55 Add the system.secrets.createReferencedSecretConfig() scripting function, including its export and type stubs.
#55 Add the system.secrets.readConfiguredSecretValue() scripting function, including its export and type stubs.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • The new helpers in system.secrets currently just return empty PyObject instances or a dummy Plaintext; consider aligning the implementations with the docstrings (e.g., using the provided JSON/provider/secret names) so the returned structures actually represent the described SecretConfig.
  • readConfiguredSecretValue mixes ValueError and SecretException for basic validation and has a typo in the error message; it would be clearer to use consistent exception types/messages for invalid JSON vs real secret access issues.
  • Docstrings for createEmbeddedSecretConfig/createReferencedSecretConfig describe returning dictionaries while the type hints and implementations use PyObject; consider reconciling the documented return type with the actual and stubbed types for clarity.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new helpers in system.secrets currently just return empty PyObject instances or a dummy Plaintext; consider aligning the implementations with the docstrings (e.g., using the provided JSON/provider/secret names) so the returned structures actually represent the described SecretConfig.
- readConfiguredSecretValue mixes `ValueError` and `SecretException` for basic validation and has a typo in the error message; it would be clearer to use consistent exception types/messages for invalid JSON vs real secret access issues.
- Docstrings for createEmbeddedSecretConfig/createReferencedSecretConfig describe returning dictionaries while the type hints and implementations use PyObject; consider reconciling the documented return type with the actual and stubbed types for clarity.

## Individual Comments

### Comment 1
<location path="src/system/secrets.py" line_range="164-165" />
<code_context>
+    """
+    if not secretConfig:
+        raise ValueError("There is no JSON.")
+    if not isinstance(secretConfig, dict):
+        raise SecretException("There is a problem eading the secret.")
+    return PyPlaintext(Plaintext())
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Type check makes any value returned from createEmbeddedSecretConfig/createReferencedSecretConfig fail, causing SecretException to always be raised.

readConfiguredSecretValue requires secretConfig to be a dict, but createEmbeddedSecretConfig and createReferencedSecretConfig currently return a bare PyObject. Any secretConfig produced by these helpers will therefore fail the isinstance(secretConfig, dict) check and always raise SecretException. Either align the helpers to return a dict/dict-like object, or relax the type check to validate the expected structure instead, so callers can successfully use the new API end-to-end.
</issue_to_address>

### Comment 2
<location path="src/system/secrets.py" line_range="165" />
<code_context>
+    if not secretConfig:
+        raise ValueError("There is no JSON.")
+    if not isinstance(secretConfig, dict):
+        raise SecretException("There is a problem eading the secret.")
+    return PyPlaintext(Plaintext())
+
</code_context>
<issue_to_address>
**nitpick (typo):** Fix the typo in the SecretException message.

The exception message contains a typo: "eading" should be "reading" to keep error logs and handling clear.

Suggested implementation:

```python
        raise SecretException("There is a problem reading the secret.")

```

I only see part of the function in the snippet. Make sure this `SecretException` line appears directly after the `if not isinstance(secretConfig, dict):` check in `src/system/secrets.py`, and that no other occurrences of the typo ("eading the secret.") remain elsewhere in the file.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/system/secrets.py Outdated
Comment on lines +164 to +165
if not isinstance(secretConfig, dict):
raise SecretException("There is a problem eading the secret.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Type check makes any value returned from createEmbeddedSecretConfig/createReferencedSecretConfig fail, causing SecretException to always be raised.

readConfiguredSecretValue requires secretConfig to be a dict, but createEmbeddedSecretConfig and createReferencedSecretConfig currently return a bare PyObject. Any secretConfig produced by these helpers will therefore fail the isinstance(secretConfig, dict) check and always raise SecretException. Either align the helpers to return a dict/dict-like object, or relax the type check to validate the expected structure instead, so callers can successfully use the new API end-to-end.

Comment thread src/system/secrets.py Outdated
@cesarcoatl
cesarcoatl merged commit b2296a2 into 8.3 Jul 17, 2026
5 checks passed
@cesarcoatl
cesarcoatl deleted the refactor/system/secrets branch July 17, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add 8.3.8 scripting functions - system.secrets

1 participant