Skip to content

Commit

Permalink
Merge branch 'master' into page_shield
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz authored Dec 6, 2023
2 parents c76a77b + 569dfef commit 89b3e59
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/1445.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
access_group: Add support for email lists
```
3 changes: 3 additions & 0 deletions .changelog/1460.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:dependency
deps: bumps actions/setup-go from 4 to 5
```
2 changes: 1 addition & 1 deletion .github/workflows/changelog-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: 'internal/tools/go.mod'
- run: go generate -tags tools internal/tools/tools.go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'internal/tools/go.mod'
- run: go generate -tags tools internal/tools/tools.go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
go-version: ["1.19", "1.20", "1.21"]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
Expand Down
4 changes: 4 additions & 0 deletions .golintci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ linters:

output:
format: colored-line-number

linters-settings:
goconst:
ignore-tests: true
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## 0.84.0 (Unreleased)

ENHANCEMENTS:

* access_group: Add support for email lists ([#1445](https://github.com/cloudflare/cloudflare-go/issues/1445))

DEPENDENCIES:

* deps: bumps actions/setup-go from 4 to 5 ([#1460](https://github.com/cloudflare/cloudflare-go/issues/1460))

## 0.83.0 (December 6th, 2023)

ENHANCEMENTS:
Expand Down
9 changes: 9 additions & 0 deletions access_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ type AccessGroupEmail struct {
} `json:"email"`
}

// AccessGroupEmailList is used for managing access based on the email
// list. For example, restrict access to users with the email addresses
// in the email list with the ID `1234567890abcdef1234567890abcdef`.
type AccessGroupEmailList struct {
EmailList struct {
ID string `json:"id"`
} `json:"email_list"`
}

// AccessGroupEmailDomain is used for managing access based on an email
// domain such as `example.com` instead of individual addresses.
type AccessGroupEmailDomain struct {
Expand Down
63 changes: 63 additions & 0 deletions access_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ var (
map[string]interface{}{"ip_list": map[string]interface{}{"id": "989d98642c564d2e855e9661899b7252"}},
},
}

expectedAccessGroupEmailList = AccessGroup{
ID: "a99d98642c564d2e855e9661899b7252",
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Name: "Allow devs",
Include: []interface{}{
map[string]interface{}{"email_list": map[string]interface{}{"id": "8a9d98642c564d2e855e9661899b7252"}},
},
}
)

func TestAccessGroups(t *testing.T) {
Expand Down Expand Up @@ -406,3 +416,56 @@ func TestCreateIPListAccessGroup(t *testing.T) {
assert.Equal(t, expectedAccessGroupIpList, actual)
}
}

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

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
w.Header().Set("content-type", "application/json")

fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "a99d98642c564d2e855e9661899b7252",
"created_at": "2014-01-01T05:20:00.12345Z",
"updated_at": "2014-01-01T05:20:00.12345Z",
"name": "Allow devs",
"include": [
{
"email_list": {
"id": "8a9d98642c564d2e855e9661899b7252"
}
}
]
}
}
`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/access/groups", handler)

accessGroup := CreateAccessGroupParams{
Name: "Allow devs by email_list",
Include: []interface{}{
AccessGroupEmailList{struct {
ID string `json:"id"`
}{ID: "989d98642c564d2e855e9661899b7252"}},
},
}

actual, err := client.CreateAccessGroup(context.Background(), testAccountRC, accessGroup)
if assert.NoError(t, err) {
assert.Equal(t, expectedAccessGroupEmailList, actual)
}

mux.HandleFunc("/zones/"+testZoneID+"/access/groups", handler)

actual, err = client.CreateAccessGroup(context.Background(), testZoneRC, accessGroup)
if assert.NoError(t, err) {
assert.Equal(t, expectedAccessGroupEmailList, actual)
}
}

0 comments on commit 89b3e59

Please sign in to comment.