Skip to content

[confcom] Remove the dependency on OPA#9464

Merged
necusjz merged 4 commits intoAzure:mainfrom
DomAyre:remove-opa
Dec 11, 2025
Merged

[confcom] Remove the dependency on OPA#9464
necusjz merged 4 commits intoAzure:mainfrom
DomAyre:remove-opa

Conversation

@DomAyre
Copy link
Copy Markdown
Contributor

@DomAyre DomAyre commented Dec 10, 2025

Why

We currently have code which uses the OPA binary to parse policy, this is much more than we strictly need to parse simple rego policies. Fewer dependencies is always better

How

  • Rewrite policy_deserialize() to directly parse policies
  • Remove the opa.py lib
  • Update setup.py to not pull

This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install wheel==0.30.0 required)
  • My extension version conforms to the Extension version schema

Copilot AI review requested due to automatic review settings December 10, 2025 16:00
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Dec 10, 2025

️✔️Azure CLI Extensions Breaking Change Test
️✔️Non Breaking Changes

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Dec 10, 2025

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown
Contributor

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@github-actions
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request removes the dependency on the OPA (Open Policy Agent) binary by rewriting the policy_deserialize() function to directly parse Rego policy files using Python's standard library instead of invoking the external OPA binary. This simplification reduces external dependencies and improves the package installation process.

  • Implemented custom Rego policy parser in policy_deserialize() using regex and JSON parsing
  • Removed azext_confcom/lib/opa.py and all OPA-related code
  • Bumped extension version from 1.4.4 to 1.4.5

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/confcom/setup.py Removed OPA import and download call; bumped version to 1.4.5
src/confcom/azext_confcom/lib/serialization.py Replaced OPA-based parsing with custom line-by-line parser using regex and bracket/brace counting
src/confcom/azext_confcom/lib/opa.py Deleted entire file containing OPA binary download and execution logic
src/confcom/HISTORY.rst Added version 1.4.5 entry documenting OPA dependency removal

Comment on lines +86 to +90
for char in line:
if char in ['{', '[', '(']:
delta += 1
elif char in ['}', ']', ')']:
delta -= 1
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The _brace_delta function counts all braces, brackets, and parentheses in the line, including those inside JSON string literals. This will cause incorrect depth tracking when string values contain these characters.

For example, if a JSON field contains "pattern": "prefix(tail", the opening parenthesis would incorrectly increment the depth counter, causing the parser to continue reading lines even after the JSON structure is complete, potentially including unrelated lines in the expression.

To fix this, track whether you're currently inside a quoted string and skip delimiter counting while inside strings. Consider using a state machine or a more robust JSON-aware parser for multi-line expressions. Example approach:

def _brace_delta(line: str) -> int:
    delta = 0
    in_string = False
    escape_next = False
    for char in line:
        if escape_next:
            escape_next = False
            continue
        if char == '\\':
            escape_next = True
            continue
        if char == '"':
            in_string = not in_string
            continue
        if not in_string:
            if char in ['{', '[', '(']:
                delta += 1
            elif char in ['}', ']', ')']:
                delta -= 1
    return delta
Suggested change
for char in line:
if char in ['{', '[', '(']:
delta += 1
elif char in ['}', ']', ')']:
delta -= 1
in_string = False
escape_next = False
for char in line:
if escape_next:
escape_next = False
continue
if char == '\\':
escape_next = True
continue
if char == '"':
in_string = not in_string
continue
if not in_string:
if char in ['{', '[', '(']:
delta += 1
elif char in ['}', ']', ')']:
delta -= 1

Copilot uses AI. Check for mistakes.
@necusjz necusjz merged commit 084bac7 into Azure:main Dec 11, 2025
24 checks passed
@azclibot
Copy link
Copy Markdown
Collaborator

[Release] Update index.json for extension [ confcom ] : https://dev.azure.com/msazure/One/_build/results?buildId=146293397&view=results

DhritiJindal27 pushed a commit to DhritiJindal27/azure-cli-extensions that referenced this pull request Dec 18, 2025
* Remove the depedency on OPA

* Bump version

* Organise imports
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.

5 participants