Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request mapping does not support HTTP methods other an POST, GET, PUT, DELETE #76

Closed
zcrisler opened this issue Jan 2, 2025 · 0 comments · Fixed by #77
Closed

Request mapping does not support HTTP methods other an POST, GET, PUT, DELETE #76

zcrisler opened this issue Jan 2, 2025 · 0 comments · Fixed by #77
Labels
bug Something isn't working

Comments

@zcrisler
Copy link

zcrisler commented Jan 2, 2025

What happened?

The remote REST API I need to interact with does not support PUT; however, it allows resource updates via PATCH. I specified method: PATCH for the corresponding action: UPDATE object in spec.forProvider.mappings[], but it was rejected at the Kube API server because the requests.http.crossplane.io CRD only supports POST, GET, PUT, or DELETE values.

How can we reproduce it?

Try to create a Request resource with a mapping that uses any method other than GET, POST, PUT, or DELETE. For example, just update examples/sample/request.yaml to use PATCH rather than PUT for the UPDATE action:

diff --git a/examples/sample/request.yaml b/examples/sample/request.yaml
index 82d4cfc..d0552de 100644
--- a/examples/sample/request.yaml
+++ b/examples/sample/request.yaml
@@ -47,8 +47,8 @@ spec:
         url: (.payload.baseUrl + "/" + (.response.body.id|tostring))

       # Scenario 3: Method specified, action not specified (PUT implies UPDATE)
-      - method: "PUT"
-        # action: UPDATE
+      - method: "PATCH"
+        action: UPDATE
         body: |
           {
             email: .payload.body.email,

The Kube API server will respond that the Request is invalid:

$ kubectl apply -f request.yaml
The Request "manage-user" is invalid: spec.forProvider.mappings[2].method: Unsupported value: "PATCH": supported values: "POST", "GET", "PUT", "DELETE"

What environment did it happen in?

Crossplane version: v1.18.1
Provider-http version: v1.0.6

Possible work around

While PR #62 added support for custom actions to fix issue #58, it did not update the corresponding kubebuilder:validation:Enum marker to support use cases that require other HTTP methods like PATCH or HEAD (e.g., observe changes via etag). Updating the marker to include PATCH appears to resolve my immediate issue, but I'm not entirely sure it addresses all possible concerns. Here are the changes I experimented with:

diff --git a/apis/request/v1alpha2/request_types.go b/apis/request/v1alpha2/request_types.go
index 591d248..7fc3ef2 100644
--- a/apis/request/v1alpha2/request_types.go
+++ b/apis/request/v1alpha2/request_types.go
@@ -67,7 +67,7 @@ type RequestParameters struct {

 type Mapping struct {
        // Either Method or Action must be specified. If both are omitted, the mapping will not be used.
-       // +kubebuilder:validation:Enum=POST;GET;PUT;DELETE
+       // +kubebuilder:validation:Enum=POST;GET;HEAD;PUT;PATCH;DELETE
        // Method specifies the HTTP method for the request.
        Method string `json:"method,omitempty"`

diff --git a/package/crds/http.crossplane.io_requests.yaml b/package/crds/http.crossplane.io_requests.yaml
index b511374..42ca085 100644
--- a/package/crds/http.crossplane.io_requests.yaml
+++ b/package/crds/http.crossplane.io_requests.yaml
@@ -543,7 +543,9 @@ spec:
                           enum:
                           - POST
                           - GET
+                          - HEAD
                           - PUT
+                          - PATCH
                           - DELETE
                           type: string
                         url:
@@ -926,7 +928,9 @@ spec:
                     enum:
                     - POST
                     - GET
+                    - HEAD
                     - PUT
+                    - PATCH
                     - DELETE
                     type: string
                   url:
@zcrisler zcrisler added the bug Something isn't working label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant