Skip to content

feat: adds http put support to cel expressions#53

Open
gaganhr94 wants to merge 1 commit into
kyverno:mainfrom
gaganhr94:feat/http-put-support
Open

feat: adds http put support to cel expressions#53
gaganhr94 wants to merge 1 commit into
kyverno:mainfrom
gaganhr94:feat/http-put-support

Conversation

@gaganhr94

Copy link
Copy Markdown
Contributor

Explanation

This PR adds HTTP PUT method support to the Kyverno SDK CEL HTTP library. Currently, the library only supports GET and POST operations. The PUT method is essential for updating existing resources on remote HTTP endpoints and is a fundamental part of RESTful API interactions. This enhancement allows users to make PUT requests with custom headers and request bodies from within CEL expressions, enabling full resource update capabilities in policy expressions.

Related issue

Fixes kyverno/kyverno#15470

Proposed Changes

The PUT implementation mirrors the existing POST method pattern to maintain consistency across the codebase. These changes will add support to the put method (say, for example http.Put() being used in the CEL expressions)

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

Further Comments

@codecov-commenter

codecov-commenter commented Mar 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.08333% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.47%. Comparing base (376d911) to head (8f29b4a).

Files with missing lines Patch % Lines
extensions/cel/libs/http/http.go 50.00% 3 Missing and 3 partials ⚠️
extensions/cel/libs/http/impl.go 75.00% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
+ Coverage   70.35%   70.47%   +0.12%     
==========================================
  Files          80       80              
  Lines        2540     2588      +48     
==========================================
+ Hits         1787     1824      +37     
- Misses        602      607       +5     
- Partials      151      157       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaganhr94

Copy link
Copy Markdown
Contributor Author

Hi @eddycharly @fjogeleit can you please review this PR when you get a chance. The issue attached with the PR has more details about why I thought about this particular feature. Thanks !

Signed-off-by: Gagan H R <hrgagan4@gmail.com>
Copilot AI review requested due to automatic review settings April 25, 2026 10:51
@gaganhr94 gaganhr94 force-pushed the feat/http-put-support branch from a3235fd to 8f29b4a Compare April 25, 2026 10:51
@gaganhr94

Copy link
Copy Markdown
Contributor Author

Hi @eddycharly @fjogeleit can you please review this PR when you get a chance. It adds support for the PUT call, an addition to the existing GET and POST calls supported by the CEL expressions in kyverno

Copilot AI 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.

Pull request overview

Adds HTTP PUT support to the Kyverno SDK CEL HTTP library so policy CEL expressions can update resources via REST-style endpoints, aligning feature parity with existing GET/POST support.

Changes:

  • Extends the HTTP context and runtime implementation to execute PUT requests with optional headers and request body.
  • Registers CEL function overloads for Put / put on the http context.
  • Adds unit tests covering PUT request execution, headers, and error handling.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
extensions/cel/libs/http/types.go Extends the public HTTP context interface to include Put.
extensions/cel/libs/http/lib.go Registers CEL overloads for Put/put alongside existing Get/Post.
extensions/cel/libs/http/impl.go Adds CEL bindings that route http.Put(...) calls to the underlying context implementation.
extensions/cel/libs/http/http.go Implements the PUT request behavior in contextImpl.
extensions/cel/libs/http/impl_test.go Adds tests for PUT request execution, headers, and client-arg validation errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 9 to 13
type ContextInterface interface {
Get(url string, headers map[string]string) (any, error)
Post(url string, data any, headers map[string]string) (any, error)
Put(url string, data any, headers map[string]string) (any, error)
Client(caBundle string) (ContextInterface, error)

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

Adding Put to the exported ContextInterface is a Go breaking change for any downstream implementation passed into Lib(...). To avoid forcing all consumers to update, consider keeping ContextInterface as-is and adding a Put method on the Context wrapper (delegating via a type assertion), or introducing a separate extended interface (e.g., ContextInterfaceWithPut) and returning a clear runtime error when Put isn’t supported.

Copilot uses AI. Check for mistakes.
Comment on lines +322 to +325
body, err := buildRequestData(data)
if err != nil {
return nil, fmt.Errorf("failed to encode request data: %w", err)
}

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

Put() now uses buildRequestData(), but buildRequestData’s internal error text still says "failed to encode HTTP POST data ...". If encoding fails on a PUT request, the returned error chain will misleadingly mention POST; consider making buildRequestData’s error message method-agnostic (or pass the HTTP method into it).

Copilot uses AI. Check for mistakes.
)
assert.NoError(t, err)
assert.NotNil(t, env)
ast, issues := env.Compile(`http.Put("http://localhost:8080", { "key": dyn("value"), "foo": dyn(2) })`)

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

Existing tests for this library exercise the lowercase function names (e.g., http.get/http.post) which are version-gated, but this new test only compiles the PascalCase variant (http.Put). Add coverage for http.put as well (or switch to it) to ensure the version-gated overload is actually exercised.

Suggested change
ast, issues := env.Compile(`http.Put("http://localhost:8080", { "key": dyn("value"), "foo": dyn(2) })`)
ast, issues := env.Compile(`http.put("http://localhost:8080", { "key": dyn("value"), "foo": dyn(2) })`)

Copilot uses AI. Check for mistakes.
Comment on lines +800 to +804
assert.NotNil(t, env)
ast, issues := env.Compile(`http.Put("http://localhost:8080", {"key": "value"}, {"Authorization": "Bearer token"})`)
fmt.Println(issues.String())
assert.Nil(t, issues)
assert.NotNil(t, ast)

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

This test also only covers the PascalCase overload (http.Put). To keep consistency with the rest of the suite and verify the version-gated camelCase overload, add a corresponding compile/eval test for http.put.

Copilot uses AI. Check for mistakes.
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.

[Feature] Add HTTP PUT method support to CEL HTTP library

4 participants