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

Add GET for DCV Delegation UUID endpoint #1384

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .changelog/1384.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dcv_delegation: add GET for DCV Delegation UUID
```
39 changes: 39 additions & 0 deletions dcv_delegation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cloudflare

import (
"context"
"fmt"
"net/http"

"github.com/goccy/go-json"
)

type DCVDelegation struct {
UUID string `json:"uuid"`
}

// DCVDelegationResponse represents the response from the dcv_delegation/uuid endpoint.
type DCVDelegationResponse struct {
Result DCVDelegation `json:"result"`
Response
ResultInfo `json:"result_info"`
}
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved

// GetDCVDelegation gets a zone DCV Delegation UUID
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
//
// TODO: Add API documentation

Check failure on line 24 in dcv_delegation.go

View workflow job for this annotation

GitHub Actions / lint

Comment should end in a period (godot)
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
func (api *API) GetDCVDelegation(ctx context.Context, rc *ResourceContainer) (DCVDelegation, ResultInfo, error) {
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
uri := fmt.Sprintf("/zones/%s/dcv_delegation/uuid", rc.Identifier)

res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return DCVDelegation{}, ResultInfo{}, err
}
var dcvResponse DCVDelegationResponse
err = json.Unmarshal(res, &dcvResponse)
if err != nil {
return DCVDelegation{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}

return dcvResponse.Result, dcvResponse.ResultInfo, nil
}
43 changes: 43 additions & 0 deletions dcv_delegation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cloudflare

import (
"context"
"fmt"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetDCVDelegation(t *testing.T) {
setup()
defer teardown()

testUuid := "b9ab465427f949ed"

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success" : true,
"errors": [],
"messages": [],
"result": {
"uuid": "%s"
}
}
`, testUuid)
}

mux.HandleFunc("/zones/"+testZoneID+"/dcv_delegation/uuid", handler)

want := DCVDelegation{
UUID: testUuid,
}

actual, _, err := client.GetDCVDelegation(context.Background(), ZoneIdentifier(testZoneID))
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}
}
Loading