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

Update branch #1370

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions .changelog/1264.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```release-note:breaking-change
pages_deployment: add support for auto pagination
```

```release-note:enchancement
pages_deployment: add Force to DeletePagesDeploymentParams
```

```release-note:breaking-change
pages_deployment: change DeletePagesDeploymentParams to contain all parameters
```

```release-note:breaking-change
pages_project: rename PagesProject to GetPagesProject
```

```release-note:breaking-change
pages_project: change to use ResourceContainer for account ID
```
3 changes: 3 additions & 0 deletions .changelog/1328.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:dependency
deps: bumps golang.org/x/net from 0.11.0 to 0.12.0
```
3 changes: 3 additions & 0 deletions .changelog/1329.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
certificate_packs: Add Delegation Records
```
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## 0.73.0 (Unreleased)

BREAKING CHANGES:

* pages_deployment: add support for auto pagination ([#1264](https://github.com/cloudflare/cloudflare-go/issues/1264))
* pages_deployment: change DeletePagesDeploymentParams to contain all parameters ([#1264](https://github.com/cloudflare/cloudflare-go/issues/1264))
* pages_project: change to use ResourceContainer for account ID ([#1264](https://github.com/cloudflare/cloudflare-go/issues/1264))
* pages_project: rename PagesProject to GetPagesProject ([#1264](https://github.com/cloudflare/cloudflare-go/issues/1264))

DEPENDENCIES:

* deps: bumps golang.org/x/net from 0.11.0 to 0.12.0 ([#1328](https://github.com/cloudflare/cloudflare-go/issues/1328))

## 0.72.0 (July 5th, 2023)

BREAKING CHANGES:
Expand Down
1 change: 1 addition & 0 deletions certificate_packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type CertificatePack struct {
ValidityDays int `json:"validity_days"`
CertificateAuthority string `json:"certificate_authority"`
CloudflareBranding bool `json:"cloudflare_branding"`
DelegationRecords []SSLDelegationRecord `json:"dcv_delegation_records,omitempty"`
}

// CertificatePackRequest is used for requesting a new certificate.
Expand Down
82 changes: 74 additions & 8 deletions certificate_packs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ var (
ValidityDays: 90,
CertificateAuthority: "lets_encrypt",
}

pendingCertificatePackRecords = CertificatePack{
ID: "64289572-8b22-4cd4-af3c-3fef28ef5dae",
Type: "advanced",
Hosts: []string{"example.com"},
Certificates: []CertificatePackCertificate{},
PrimaryCertificate: "0",
Status: "pending_validation",
ValidationRecords: []SSLValidationRecord{SSLValidationRecord{CnameTarget: "", CnameName: "", TxtName: "_acme-challenge.example.com", TxtValue: "QkyhZpLUAD4r3Fn9urywnXzeIeZ_ZG68MxJgBY32NmU", HTTPUrl: "", HTTPBody: "", Emails: []string(nil)}},
ValidationErrors: []SSLValidationError(nil),
ValidationMethod: "txt",
ValidityDays: 90,
CertificateAuthority: "lets_encrypt",
CloudflareBranding: false,
DelegationRecords: []SSLDelegationRecord{SSLDelegationRecord{CnameTarget: "example.com.0f461ad6a17edc91.dcv.cloudflare.com", CnameName: "_acme-challenge.example.com"}},
}
)

func TestListCertificatePacks(t *testing.T) {
Expand Down Expand Up @@ -267,14 +283,14 @@ func TestDeleteCertificatePack(t *testing.T) {
assert.Equal(t, http.MethodDelete, r.Method, "Expected method 'DELETE', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "3822ff90-ea29-44df-9e55-21300bb9419b"
}
}
`)
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "3822ff90-ea29-44df-9e55-21300bb9419b"
}
}
`)
}

mux.HandleFunc("/zones/"+testZoneID+"/ssl/certificate_packs/3822ff90-ea29-44df-9e55-21300bb9419b", handler)
Expand All @@ -283,3 +299,53 @@ func TestDeleteCertificatePack(t *testing.T) {

assert.NoError(t, err)
}

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

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": {
"id": "64289572-8b22-4cd4-af3c-3fef28ef5dae",
"type": "advanced",
"hosts": [
"example.com"
],
"primary_certificate": "0",
"status": "pending_validation",
"certificates": [],
"created_on": "2023-06-21T13:48:39.114782Z",
"validity_days": 90,
"validation_method": "txt",
"validation_records": [
{
"status": "pending",
"txt_name": "_acme-challenge.example.com",
"txt_value": "QkyhZpLUAD4r3Fn9urywnXzeIeZ_ZG68MxJgBY32NmU"
}
],
"dcv_delegation_records": [
{
"cname": "_acme-challenge.example.com",
"cname_target": "example.com.0f461ad6a17edc91.dcv.cloudflare.com"
}
],
"certificate_authority": "lets_encrypt"
}
}`)
}

mux.HandleFunc("/zones/"+testZoneID+"/ssl/certificate_packs/3822ff90-ea29-44df-9e55-21300bb9419a", handler)

actual, err := client.CertificatePack(context.Background(), testZoneID, "3822ff90-ea29-44df-9e55-21300bb9419a")

if assert.NoError(t, err) {
assert.Equal(t, pendingCertificatePackRecords, actual)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ require (
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/text v0.10.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
)
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
74 changes: 45 additions & 29 deletions pages_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,16 @@ type pagesDeploymentResponse struct {
Result PagesProjectDeployment `json:"result"`
}

type pagesDeploymentStageLogsResponse struct {
Response
Result PagesDeploymentStageLogs `json:"result"`
ResultInfo `json:"result_info"`
}

type pagesDeploymentLogsResponse struct {
Response
Result PagesDeploymentLogs `json:"result"`
ResultInfo `json:"result_info"`
}

type ListPagesDeploymentsParams struct {
ProjectName string
ProjectName string `url:"-"`

PaginationOptions
ResultInfo
}

type GetPagesDeploymentInfoParams struct {
Expand All @@ -101,12 +95,14 @@ type GetPagesDeploymentLogsParams struct {
}

type DeletePagesDeploymentParams struct {
ProjectName string
DeploymentID string
ProjectName string `url:"-"`
DeploymentID string `url:"-"`
Force bool `url:"force,omitempty"`
}

type CreatePagesDeploymentParams struct {
ProjectName string
ProjectName string `json:"-"`
Branch string `json:"branch,omitempty"`
}

type RetryPagesDeploymentParams struct {
Expand All @@ -122,33 +118,53 @@ type RollbackPagesDeploymentParams struct {
var (
ErrMissingProjectName = errors.New("required missing project name")
ErrMissingDeploymentID = errors.New("required missing deployment ID")
ErrMissingStageName = errors.New("required missing stage name")
)

// ListPagesDeployments returns all deployments for a Pages project.
//
// API reference: https://api.cloudflare.com/#pages-deployment-get-deployments
func (api *API) ListPagesDeployments(ctx context.Context, rc *ResourceContainer, params ListPagesDeploymentsParams) ([]PagesProjectDeployment, ResultInfo, error) {
func (api *API) ListPagesDeployments(ctx context.Context, rc *ResourceContainer, params ListPagesDeploymentsParams) ([]PagesProjectDeployment, *ResultInfo, error) {
if rc.Identifier == "" {
return []PagesProjectDeployment{}, ResultInfo{}, ErrMissingAccountID
return []PagesProjectDeployment{}, &ResultInfo{}, ErrMissingAccountID
}

if params.ProjectName == "" {
return []PagesProjectDeployment{}, ResultInfo{}, ErrMissingProjectName
return []PagesProjectDeployment{}, &ResultInfo{}, ErrMissingProjectName
}

uri := buildURI(fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments", rc.Identifier, params.ProjectName), params.PaginationOptions)
autoPaginate := true
if params.PerPage >= 1 || params.Page >= 1 {
autoPaginate = false
}

res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []PagesProjectDeployment{}, ResultInfo{}, err
if params.PerPage < 1 {
params.PerPage = 25
}
var r pagesDeploymentListResponse
err = json.Unmarshal(res, &r)
if err != nil {
return []PagesProjectDeployment{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err)

if params.Page < 1 {
params.Page = 1
}
return r.Result, r.ResultInfo, nil

var deployments []PagesProjectDeployment
var r pagesDeploymentListResponse

for {
uri := buildURI(fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments", rc.Identifier, params.ProjectName), params)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []PagesProjectDeployment{}, &ResultInfo{}, err
}
err = json.Unmarshal(res, &r)
if err != nil {
return []PagesProjectDeployment{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
deployments = append(deployments, r.Result...)
params.ResultInfo = r.ResultInfo.Next()
if params.Done() || !autoPaginate {
break
}
}
return deployments, &r.ResultInfo, nil
}

// GetPagesDeploymentInfo returns a deployment for a Pages project.
Expand Down Expand Up @@ -217,20 +233,20 @@ func (api *API) GetPagesDeploymentLogs(ctx context.Context, rc *ResourceContaine
// DeletePagesDeployment deletes a Pages deployment.
//
// API reference: https://api.cloudflare.com/#pages-deployment-delete-deployment
func (api *API) DeletePagesDeployment(ctx context.Context, rc *ResourceContainer, projectName, deploymentID string) error {
func (api *API) DeletePagesDeployment(ctx context.Context, rc *ResourceContainer, params DeletePagesDeploymentParams) error {
if rc.Identifier == "" {
return ErrMissingAccountID
}

if projectName == "" {
if params.ProjectName == "" {
return ErrMissingProjectName
}

if deploymentID == "" {
if params.DeploymentID == "" {
return ErrMissingDeploymentID
}

uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments/%s", rc.Identifier, projectName, deploymentID)
uri := buildURI(fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments/%s", rc.Identifier, params.ProjectName, params.DeploymentID), params)

_, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)
if err != nil {
Expand All @@ -253,7 +269,7 @@ func (api *API) CreatePagesDeployment(ctx context.Context, rc *ResourceContainer

uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments", rc.Identifier, params.ProjectName)

res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil)
res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params)
if err != nil {
return PagesProjectDeployment{}, err
}
Expand Down
Loading
Loading