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 support for listing R2 buckets #1050

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
9de6304
Should fix the R2 bucket create endpoint
Cyb3r-Jak3 Aug 11, 2022
3548abc
Add `config` to body of UpdateTunnelConfiguration
vazexqi Aug 16, 2022
87271db
Fix double unmarshalling
vazexqi Aug 16, 2022
fa904bd
Add some error type convenience functions for mocking and inspection
jburnham Aug 16, 2022
e0c94e5
List R2 buckets
rgcostea Aug 17, 2022
7a0f509
Add changelog notice
rgcostea Aug 17, 2022
01fbe8c
Add compatibility date and compatibility_flags to pages deployment co…
Cyb3r-Jak3 Aug 17, 2022
00d065b
Fix documentation
Cyb3r-Jak3 Aug 17, 2022
ea052b0
Fix lint
Cyb3r-Jak3 Aug 17, 2022
9664358
Clean up unused types
vazexqi Aug 17, 2022
27dc22c
zone_lockdown: add Priority to ZoneLockdownCreateParams and ZoneLockd…
jacobbednarz Aug 18, 2022
012bb8a
add CHANGELOG
jacobbednarz Aug 18, 2022
536be84
Merge pull request #1052 from jacobbednarz/add-priority-for-lockdown-…
jacobbednarz Aug 18, 2022
12b6d98
Update CHANGELOG.md for #1052
Aug 18, 2022
55b3317
Update CHANGELOG.md
jacobbednarz Aug 18, 2022
29d5787
add changelog entry
jburnham Aug 18, 2022
9fe6ef3
use errors as prefix
jburnham Aug 18, 2022
c6ddc20
Merge pull request #1047 from jburnham/easier-error-mocking
jacobbednarz Aug 18, 2022
ebd47ef
Update CHANGELOG.md for #1047
Aug 18, 2022
c48ca8c
Add changelog
vazexqi Aug 19, 2022
5c53b70
Merge branch 'master' into master
vazexqi Aug 19, 2022
87eb8f9
Update .changelog/1046.txt
vazexqi Aug 19, 2022
31436d7
Merge pull request #1046 from zuplo/master
jacobbednarz Aug 19, 2022
6b6ad04
Update CHANGELOG.md for #1046
Aug 19, 2022
fed21d7
Merge pull request #1051 from Cyb3r-Jak3/compatibily-in-pages-project
jacobbednarz Aug 19, 2022
ce1be2e
Update CHANGELOG.md for #1051
Aug 19, 2022
e39278e
add docs on public documentation requirement
jacobbednarz Aug 19, 2022
ebb2785
Merge pull request #1055 from jacobbednarz/clarify-api-stability-requ…
jacobbednarz Aug 19, 2022
2cb0c4d
Expose Blockpage.SuppressFooter field
NicholasAsimov Aug 18, 2022
b803b6a
add CHANGELOG entry
jacobbednarz Aug 21, 2022
23bde0b
fix `CreateR2BucketParameters` usage
jacobbednarz Aug 22, 2022
033c9d6
Merge pull request #1035 from Cyb3r-Jak3/r2-bucket-fix
jacobbednarz Aug 22, 2022
989cc31
Update CHANGELOG.md for #1035
Aug 22, 2022
5c68ab9
Merge pull request #1053 from NicholasAsimov/add-blockpage-field-supp…
jacobbednarz Aug 22, 2022
859a8a6
Update CHANGELOG.md for #1053
Aug 22, 2022
501323d
Update CHANGELOG.md
jacobbednarz Aug 22, 2022
05bd28f
tools: move `tools` to internal package and tighten up dependencies
jacobbednarz Aug 22, 2022
cdcc843
Merge pull request #1058 from jacobbednarz/cleaner-dev-deps
jacobbednarz Aug 22, 2022
f81aca1
add more dev deps
jacobbednarz Aug 22, 2022
bc05dd2
set working-dir
jacobbednarz Aug 23, 2022
f720f69
add api shield
Aug 23, 2022
6817ce8
add PUT for api shield
Aug 24, 2022
0496977
add changelog
Aug 24, 2022
5c92eb7
api shield: use ResourceContainer for identifiers
Aug 24, 2022
1407a1a
use update instead of Put
jafowler Aug 25, 2022
13aad94
change tests to use Update instead of Put
Aug 25, 2022
4bdba96
enabled -> enable
Cyb3r-Jak3 Aug 25, 2022
91746dd
Merge pull request #1060 from Cyb3r-Jak3/email-routing-enable-typo
jacobbednarz Aug 25, 2022
9da8f52
cleanup tests
jacobbednarz Aug 25, 2022
c0c5c42
Merge pull request #1059 from cloudflare/add-api-shield
jacobbednarz Aug 25, 2022
ecb8059
add setup-go
jacobbednarz Aug 25, 2022
441d5d8
Update CHANGELOG.md (Manual Trigger)
Aug 25, 2022
873a91b
Add support for multipart downloads for module-format Worker scripts …
sodabrew Aug 25, 2022
1224235
Update CHANGELOG.md for #1040
Aug 25, 2022
b2263a5
List R2 buckets
rgcostea Aug 17, 2022
1b1e1c2
Add changelog notice
rgcostea Aug 17, 2022
5e1b61a
Resolved merge conflicts
rgcostea Aug 26, 2022
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/1035.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
r2: fix create bucket endpoint
```
3 changes: 3 additions & 0 deletions .changelog/1040.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
workers: Support for multipart encoding for DownloadWorker on a module-format Worker script
```
3 changes: 3 additions & 0 deletions .changelog/1046.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
tunnel_configuration: Remove unnecessary double-unmarshalling due to changes in the API
```
3 changes: 3 additions & 0 deletions .changelog/1047.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
errors: add some error type convenience functions for mocking and inspection
```
3 changes: 3 additions & 0 deletions .changelog/1050.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
r2: Add in support for listing R2 buckets
```
3 changes: 3 additions & 0 deletions .changelog/1051.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
pages_project: Add compatibility date and compatibility_flags to pages deployment configs
```
3 changes: 3 additions & 0 deletions .changelog/1052.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
zonelockdown: add `Priority` to `ZoneLockdownCreateParams` and `ZoneLockdownUpdateParams`
```
3 changes: 3 additions & 0 deletions .changelog/1053.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
teams_account: add support for `suppress_footer`
```
3 changes: 3 additions & 0 deletions .changelog/1059.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
api_shield: add GET/PUT for API Shield Configuration
```
3 changes: 3 additions & 0 deletions .changelog/1060.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
email_routing_settings: change enable endpoint from `enabled` to `enable`
```
79 changes: 34 additions & 45 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
{
"name": "Go",
"build": {
"dockerfile": "Dockerfile"
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
"containerEnv": {
"GOPATH": "/go"
},
"remoteEnv": {
"GOPATH": "${containerEnv:GOPATH}"
},
"onCreateCommand": "go generate -tags tools tools/tools.go",
"customizations": {
"vscode": {
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"[go]": {
"editor.formatOnSave": true
},
"go.formatTool": "gofmt",
"go.formatFlags": [
"-w",
"-s"
],
"go.toolsManagement.autoUpdate": true,
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
],
"gopls": {
"ui.semanticTokens": true
},
"go.survey.prompt": false
},
"extensions": [
"golang.Go"
]
}
}
"name": "Go",
"build": {
"dockerfile": "Dockerfile"
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
"containerEnv": {
"GOPATH": "/go"
},
"remoteEnv": {
"GOPATH": "${containerEnv:GOPATH}"
},
"updateContentCommand": "go generate -tags tools internal/tools/tools.go",
"customizations": {
"vscode": {
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"[go]": {
"editor.formatOnSave": true
},
"go.formatTool": "gofmt",
"go.formatFlags": ["-w", "-s"],
"go.toolsManagement.autoUpdate": true,
"go.lintTool": "golangci-lint",
"go.lintFlags": ["--fast"],
"gopls": {
"ui.semanticTokens": true
},
"go.survey.prompt": false
},
"extensions": ["golang.Go"]
}
}
}
5 changes: 3 additions & 2 deletions .github/workflows/changelog-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ^1.17
- run: make tools
- run: go run tools/cmd/changelog-check/main.go ${{ github.event.pull_request.number }}
- run: go generate -tags tools internal/tools/tools.go
- run: go run cmd/changelog-check/main.go ${{ github.event.pull_request.number }}
working-directory: ./internal/tools
env:
GITHUB_OWNER: cloudflare
GITHUB_REPO: cloudflare-go
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/generate-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ jobs:
if: github.event.pull_request.merged || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: cd tools && go install github.com/hashicorp/go-changelog/cmd/changelog-build
- run: go generate -tags tools internal/tools/tools.go
- run: ./scripts/generate-changelog.sh
- run: |
if [[ `git status --porcelain` ]]; then
Expand Down
30 changes: 29 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
## 0.48.0 (Unreleased)
## 0.49.0 (Unreleased)

ENHANCEMENTS:

* api_shield: add GET/PUT for API Shield Configuration ([#1059](https://github.com/cloudflare/cloudflare-go/issues/1059))
* workers: Support for multipart encoding for DownloadWorker on a module-format Worker script ([#1040](https://github.com/cloudflare/cloudflare-go/issues/1040))

BUG FIXES:

* email_routing_settings: change enable endpoint from `enabled` to `enable` ([#1060](https://github.com/cloudflare/cloudflare-go/issues/1060))

## 0.48.0 (August 22nd, 2022)

ENHANCEMENTS:

* errors: add some error type convenience functions for mocking and inspection ([#1047](https://github.com/cloudflare/cloudflare-go/issues/1047))
* pages_project: Add compatibility date and compatibility_flags to pages deployment configs ([#1051](https://github.com/cloudflare/cloudflare-go/issues/1051))
* teams_account: add support for `suppress_footer` ([#1053](https://github.com/cloudflare/cloudflare-go/issues/1053))

BUG FIXES:

* r2: fix create bucket endpoint ([#1035](https://github.com/cloudflare/cloudflare-go/issues/1035))
* tunnel_configuration: Remove unnecessary double-unmarshalling due to changes in the API ([#1046](https://github.com/cloudflare/cloudflare-go/issues/1046))

## 0.47.1 (August 18th, 2022)

BUG FIXES:

* zonelockdown: add `Priority` to `ZoneLockdownCreateParams` and `ZoneLockdownUpdateParams` ([#1052](https://github.com/cloudflare/cloudflare-go/issues/1052))

## 0.47.0 (August 17th, 2022)

Expand Down
70 changes: 70 additions & 0 deletions api_shield.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
)

// AuthIdCharacteristics a single option from
// configuration?properties=auth_id_characteristics.
type AuthIdCharacteristics struct {
Type string `json:"type"`
Name string `json:"name"`
}

// APIShield is all the available options under
// configuration?properties=auth_id_characteristics.
type APIShield struct {
AuthIdCharacteristics []AuthIdCharacteristics `json:"auth_id_characteristics"`
}

// APIShieldResponse represents the response from the api_gateway/configuration endpoint.
type APIShieldResponse struct {
Result APIShield `json:"result"`
Response
ResultInfo `json:"result_info"`
}

type UpdateAPIShieldParams struct {
AuthIdCharacteristics []AuthIdCharacteristics `json:"auth_id_characteristics"`
}

// GetAPIShieldConfiguration gets a zone API shield configuration.
//
// API documentation: https://api.cloudflare.com/#api-shield-settings-retrieve-information-about-specific-configuration-properties
func (api *API) GetAPIShieldConfiguration(ctx context.Context, rc *ResourceContainer) (APIShield, ResultInfo, error) {
uri := fmt.Sprintf("/zones/%s/api_gateway/configuration?properties=auth_id_characteristics", rc.Identifier)

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

return asResponse.Result, asResponse.ResultInfo, nil
}

// UpdateAPIShieldConfiguration sets a zone API shield configuration.
//
// API documentation: https://api.cloudflare.com/#api-shield-settings-set-configuration-properties
func (api *API) UpdateAPIShieldConfiguration(ctx context.Context, rc *ResourceContainer, params UpdateAPIShieldParams) (Response, error) {
uri := fmt.Sprintf("/zones/%s/api_gateway/configuration", rc.Identifier)

res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params)
if err != nil {
return Response{}, err
}
var asResponse Response
err = json.Unmarshal(res, &asResponse)
if err != nil {
return Response{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}

return asResponse, nil
}
84 changes: 84 additions & 0 deletions api_shield_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package cloudflare

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

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

func TestGetAPIShield(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": {
"auth_id_characteristics": [
{
"type": "header",
"name": "test-header"
},
{
"type": "cookie",
"name": "test-cookie"
}
]
}
}
`)
}

mux.HandleFunc("/zones/"+testZoneID+"/api_gateway/configuration", handler)

var authChars []AuthIdCharacteristics
authChars = append(authChars, AuthIdCharacteristics{Type: "header", Name: "test-header"})
authChars = append(authChars, AuthIdCharacteristics{Type: "cookie", Name: "test-cookie"})

want := APIShield{
AuthIdCharacteristics: authChars,
}

actual, _, err := client.GetAPIShieldConfiguration(context.Background(), ZoneIdentifier(testZoneID))

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

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

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

mux.HandleFunc("/zones/"+testZoneID+"/api_gateway/configuration", handler)

apiShieldData := UpdateAPIShieldParams{AuthIdCharacteristics: []AuthIdCharacteristics{{Type: "header", Name: "different-header"}, {Type: "cookie", Name: "different-cookie"}}}

want := Response{Success: true, Errors: []ResponseInfo{}, Messages: []ResponseInfo{}}

actual, err := client.UpdateAPIShieldConfiguration(context.Background(), ZoneIdentifier(testZoneID), apiShieldData)

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}
}
6 changes: 2 additions & 4 deletions argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"fmt"
"net/http"
"time"

"errors"
)

var validSettingValues = []string{"on", "off"}
Expand Down Expand Up @@ -52,7 +50,7 @@ func (api *API) ArgoSmartRouting(ctx context.Context, zoneID string) (ArgoFeatur
// API reference: https://api.cloudflare.com/#argo-smart-routing-patch-argo-smart-routing-setting
func (api *API) UpdateArgoSmartRouting(ctx context.Context, zoneID, settingValue string) (ArgoFeatureSetting, error) {
if !contains(validSettingValues, settingValue) {
return ArgoFeatureSetting{}, errors.New(fmt.Sprintf("invalid setting value '%s'. must be 'on' or 'off'", settingValue))
return ArgoFeatureSetting{}, fmt.Errorf("invalid setting value '%s'. must be 'on' or 'off'", settingValue)
}

uri := fmt.Sprintf("/zones/%s/argo/smart_routing", zoneID)
Expand Down Expand Up @@ -94,7 +92,7 @@ func (api *API) ArgoTieredCaching(ctx context.Context, zoneID string) (ArgoFeatu
// API reference: TBA.
func (api *API) UpdateArgoTieredCaching(ctx context.Context, zoneID, settingValue string) (ArgoFeatureSetting, error) {
if !contains(validSettingValues, settingValue) {
return ArgoFeatureSetting{}, errors.New(fmt.Sprintf("invalid setting value '%s'. must be 'on' or 'off'", settingValue))
return ArgoFeatureSetting{}, fmt.Errorf("invalid setting value '%s'. must be 'on' or 'off'", settingValue)
}

uri := fmt.Sprintf("/zones/%s/argo/tiered_caching", zoneID)
Expand Down
Loading