-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dharper/APISHI-2353
- Loading branch information
Showing
6 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:dependency | ||
deps: bumps goreleaser/goreleaser-action from 4.6.0 to 5.0.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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"` | ||
} | ||
|
||
type GetDCVDelegationParams struct{} | ||
|
||
// GetDCVDelegation gets a zone DCV Delegation UUID. | ||
// | ||
// API documentation: https://developers.cloudflare.com/api/operations/dcv-delegation-uuid-get | ||
func (api *API) GetDCVDelegation(ctx context.Context, rc *ResourceContainer, params GetDCVDelegationParams) (DCVDelegation, ResultInfo, error) { | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), GetDCVDelegationParams{}) | ||
|
||
if assert.NoError(t, err) { | ||
assert.Equal(t, want, actual) | ||
} | ||
} |