Skip to content

Commit cbd0a52

Browse files
author
lijianguo
committed
chore(controller-sdk-go):replace whitelist with allowlist
1 parent cb8f4f5 commit cbd0a52

5 files changed

Lines changed: 55 additions & 55 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Controller Go SDK
2-
[![Build Status](https://travis-ci.org/drycc/controller-sdk-go.svg?branch=master)](https://travis-ci.org/drycc/controller-sdk-go/)
3-
[![codecov](https://codecov.io/gh/drycc/controller-sdk-go/branch/master/graph/badge.svg)](https://codecov.io/gh/drycc/controller-sdk-go)
2+
[![Build Status](https://travis-ci.org/drycc/controller-sdk-go.svg?branch=main)](https://travis-ci.org/drycc/controller-sdk-go/)
3+
[![codecov](https://codecov.io/gh/drycc/controller-sdk-go/branch/main/graph/badge.svg)](https://codecov.io/gh/drycc/controller-sdk-go)
44
[![Go Report Card](https://goreportcard.com/badge/github.com/drycc/controller-sdk-go)](https://goreportcard.com/report/github.com/drycc/controller-sdk-go)
5-
[![codebeat badge](https://codebeat.co/badges/3ae3560d-eebf-4b36-bbf3-780d2b2e26fd)](https://codebeat.co/projects/github-com-drycc-controller-sdk-go-master)
5+
[![codebeat badge](https://codebeat.co/badges/79dde330-50c5-45db-a1ef-cb6c48af5f5f)](https://codebeat.co/projects/github-com-drycc-controller-sdk-go-main)
66
[![GoDoc](https://godoc.org/github.com/drycc/controller-sdk-go?status.svg)](https://godoc.org/github.com/drycc/controller-sdk-go)
77

88
This is the Go SDK for interacting with the [Drycc Controller](https://github.com/drycc/controller).
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Package whitelist provides methods for managing an app's whitelisted IP's.
2-
package whitelist
1+
// Package allowlist provides methods for managing an app's allowlisted IP's.
2+
package allowlist
33

44
import (
55
"encoding/json"
@@ -9,51 +9,51 @@ import (
99
"github.com/drycc/controller-sdk-go/api"
1010
)
1111

12-
// List IP's whitelisted for an app.
13-
func List(c *drycc.Client, appID string) (api.Whitelist, error) {
14-
u := fmt.Sprintf("/v2/apps/%s/whitelist/", appID)
12+
// List IP's allowlisted for an app.
13+
func List(c *drycc.Client, appID string) (api.Allowlist, error) {
14+
u := fmt.Sprintf("/v2/apps/%s/allowlist/", appID)
1515
res, reqErr := c.Request("GET", u, nil)
1616
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
17-
return api.Whitelist{}, reqErr
17+
return api.Allowlist{}, reqErr
1818
}
1919
defer res.Body.Close()
2020

21-
whitelist := api.Whitelist{}
22-
if err := json.NewDecoder(res.Body).Decode(&whitelist); err != nil {
23-
return api.Whitelist{}, err
21+
allowlist := api.Allowlist{}
22+
if err := json.NewDecoder(res.Body).Decode(&allowlist); err != nil {
23+
return api.Allowlist{}, err
2424
}
2525

26-
return whitelist, reqErr
26+
return allowlist, reqErr
2727
}
2828

29-
// Add adds addresses to an app's whitelist.
30-
func Add(c *drycc.Client, appID string, addresses []string) (api.Whitelist, error) {
31-
u := fmt.Sprintf("/v2/apps/%s/whitelist/", appID)
29+
// Add adds addresses to an app's allowlist.
30+
func Add(c *drycc.Client, appID string, addresses []string) (api.Allowlist, error) {
31+
u := fmt.Sprintf("/v2/apps/%s/allowlist/", appID)
3232

33-
req := api.Whitelist{Addresses: addresses}
33+
req := api.Allowlist{Addresses: addresses}
3434
body, err := json.Marshal(req)
3535
if err != nil {
36-
return api.Whitelist{}, err
36+
return api.Allowlist{}, err
3737
}
3838
res, reqErr := c.Request("POST", u, body)
3939
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
40-
return api.Whitelist{}, reqErr
40+
return api.Allowlist{}, reqErr
4141
}
4242
defer res.Body.Close()
4343

44-
d := api.Whitelist{}
44+
d := api.Allowlist{}
4545
if err = json.NewDecoder(res.Body).Decode(&d); err != nil {
46-
return api.Whitelist{}, err
46+
return api.Allowlist{}, err
4747
}
4848

4949
return d, reqErr
5050
}
5151

52-
// Delete removes addresses from an app's whitelist.
52+
// Delete removes addresses from an app's allowlist.
5353
func Delete(c *drycc.Client, appID string, addresses []string) error {
54-
u := fmt.Sprintf("/v2/apps/%s/whitelist/", appID)
54+
u := fmt.Sprintf("/v2/apps/%s/allowlist/", appID)
5555

56-
req := api.Whitelist{Addresses: addresses}
56+
req := api.Allowlist{Addresses: addresses}
5757
body, err := json.Marshal(req)
5858
if err != nil {
5959
return err
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package whitelist
1+
package allowlist
22

33
import (
44
"fmt"
@@ -12,24 +12,24 @@ import (
1212
"github.com/drycc/controller-sdk-go/api"
1313
)
1414

15-
const whitelistFixture string = `
15+
const allowlistFixture string = `
1616
{
1717
"addresses": ["1.2.3.4", "0.0.0.0/0"]
1818
}`
1919

20-
const whitelistCreateExpected string = `{"addresses":["1.2.3.4","0.0.0.0/0"]}`
20+
const allowlistCreateExpected string = `{"addresses":["1.2.3.4","0.0.0.0/0"]}`
2121

2222
type fakeHTTPServer struct{}
2323

2424
func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
2525
res.Header().Add("DRYCC_API_VERSION", drycc.APIVersion)
2626

27-
if req.URL.Path == "/v2/apps/example-go/whitelist/" && req.Method == "GET" {
28-
res.Write([]byte(whitelistFixture))
27+
if req.URL.Path == "/v2/apps/example-go/allowlist/" && req.Method == "GET" {
28+
res.Write([]byte(allowlistFixture))
2929
return
3030
}
3131

32-
if req.URL.Path == "/v2/apps/example-go/whitelist/" && req.Method == "POST" {
32+
if req.URL.Path == "/v2/apps/example-go/allowlist/" && req.Method == "POST" {
3333
body, err := ioutil.ReadAll(req.Body)
3434

3535
if err != nil {
@@ -38,31 +38,31 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
3838
res.Write(nil)
3939
}
4040

41-
if string(body) != whitelistCreateExpected {
42-
fmt.Printf("Expected '%s', Got '%s'\n", whitelistCreateExpected, body)
41+
if string(body) != allowlistCreateExpected {
42+
fmt.Printf("Expected '%s', Got '%s'\n", allowlistCreateExpected, body)
4343
res.WriteHeader(http.StatusInternalServerError)
4444
res.Write(nil)
4545
return
4646
}
4747

4848
res.WriteHeader(http.StatusCreated)
49-
res.Write([]byte(whitelistFixture))
49+
res.Write([]byte(allowlistFixture))
5050
return
5151
}
5252

53-
if req.URL.Path == "/v2/apps/example-go/whitelist/" && req.Method == "DELETE" {
53+
if req.URL.Path == "/v2/apps/example-go/allowlist/" && req.Method == "DELETE" {
5454
res.WriteHeader(http.StatusNoContent)
55-
res.Write([]byte(whitelistFixture))
55+
res.Write([]byte(allowlistFixture))
5656
return
5757
}
5858

59-
if req.URL.Path == "/v2/apps/invalidjson-test/whitelist/" && req.Method == "POST" {
59+
if req.URL.Path == "/v2/apps/invalidjson-test/allowlist/" && req.Method == "POST" {
6060
res.WriteHeader(http.StatusCreated)
6161
res.Write([]byte(`"addresses": "test"`))
6262
return
6363
}
6464

65-
if req.URL.Path == "/v2/apps/invalidjson-test/whitelist/" && req.Method == "GET" {
65+
if req.URL.Path == "/v2/apps/invalidjson-test/allowlist/" && req.Method == "GET" {
6666
res.Write([]byte(`"addresses": "test"`))
6767
return
6868
}
@@ -72,10 +72,10 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
7272
res.Write(nil)
7373
}
7474

75-
func TestWhitelistList(t *testing.T) {
75+
func TestAllowlistList(t *testing.T) {
7676
t.Parallel()
7777

78-
expected := api.Whitelist{
78+
expected := api.Allowlist{
7979
Addresses: []string{"1.2.3.4", "0.0.0.0/0"},
8080
}
8181

@@ -99,10 +99,10 @@ func TestWhitelistList(t *testing.T) {
9999
}
100100
}
101101

102-
func TestWhitelistAdd(t *testing.T) {
102+
func TestAllowlistAdd(t *testing.T) {
103103
t.Parallel()
104104

105-
expected := api.Whitelist{
105+
expected := api.Allowlist{
106106
Addresses: []string{"1.2.3.4", "0.0.0.0/0"},
107107
}
108108

@@ -126,7 +126,7 @@ func TestWhitelistAdd(t *testing.T) {
126126
}
127127
}
128128

129-
func TestWhitelistRemove(t *testing.T) {
129+
func TestAllowlistRemove(t *testing.T) {
130130
t.Parallel()
131131

132132
handler := fakeHTTPServer{}
@@ -156,7 +156,7 @@ func TestAppSettingsInvalidJson(t *testing.T) {
156156
}
157157

158158
_, err = List(drycc, "invalidjson-test")
159-
expected := "json: cannot unmarshal string into Go value of type api.Whitelist"
159+
expected := "json: cannot unmarshal string into Go value of type api.Allowlist"
160160
if err == nil || !reflect.DeepEqual(expected, err.Error()) {
161161
t.Errorf("Expected %v, Got %v", expected, err)
162162
}

api/appsettings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type AppSettings struct {
2020
UUID string `json:"uuid,omitempty"`
2121
// Routable determines if the application should be exposed by the router.
2222
Routable *bool `json:"routable,omitempty"`
23-
Whitelist []string `json:"whitelist,omitempty"`
23+
Allowlist []string `json:"allowlist,omitempty"`
2424
Autoscale map[string]*Autoscale `json:"autoscale,omitempty"`
2525
Label Labels `json:"label,omitempty"`
2626
}
@@ -31,8 +31,8 @@ func NewRoutable() *bool {
3131
return &b
3232
}
3333

34-
// Whitelist is the structure of POST /v2/app/<app id>/whitelist/.
35-
type Whitelist struct {
34+
// Allowlist is the structure of POST /v2/app/<app id>/allowlist/.
35+
type Allowlist struct {
3636
Addresses []string `json:"addresses"`
3737
}
3838

appsettings/appsettings_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const appSettingsFixture string = `
1717
"owner": "test",
1818
"app": "example-go",
1919
"routable": true,
20-
"whitelist": ["1.2.3.4", "0.0.0.0/0"],
20+
"allowlist": ["1.2.3.4", "0.0.0.0/0"],
2121
"autoscale": {"cmd": {"min": 3, "max": 8, "cpu_percent": 40}},
2222
"label": {"git_repo": "https://github.com/drycc/controller-sdk-go", "team" : "drycc"},
2323
"created": "2014-01-01T00:00:00UTC",
@@ -31,7 +31,7 @@ const appSettingsUnsetFixture string = `
3131
"owner": "test",
3232
"app": "unset-test",
3333
"routable": true,
34-
"whitelist": ["1.2.3.4", "0.0.0.0/0"],
34+
"allowlist": ["1.2.3.4", "0.0.0.0/0"],
3535
"autoscale": {"cmd": {"min": 3, "max": 8, "cpu_percent": 40}},
3636
"label": {"git_repo": "https://github.com/drycc/controller-sdk-go", "team" : "drycc"},
3737
"created": "2014-01-01T00:00:00UTC",
@@ -40,8 +40,8 @@ const appSettingsUnsetFixture string = `
4040
}
4141
`
4242

43-
const appSettingsSetExpected string = `{"routable":true,"whitelist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/drycc/controller-sdk-go","team":"drycc"}}`
44-
const appSettingsUnsetExpected string = `{"routable":true,"whitelist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/drycc/controller-sdk-go","team":"drycc"}}`
43+
const appSettingsSetExpected string = `{"routable":true,"allowlist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/drycc/controller-sdk-go","team":"drycc"}}`
44+
const appSettingsUnsetExpected string = `{"routable":true,"allowlist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/drycc/controller-sdk-go","team":"drycc"}}`
4545

4646
type fakeHTTPServer struct{}
4747

@@ -116,7 +116,7 @@ func TestAppSettingsSet(t *testing.T) {
116116
Owner: "test",
117117
App: "example-go",
118118
Routable: api.NewRoutable(),
119-
Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
119+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
120120
Autoscale: map[string]*api.Autoscale{
121121
"cmd": {
122122
Min: 3,
@@ -135,7 +135,7 @@ func TestAppSettingsSet(t *testing.T) {
135135

136136
appSettingsVars := api.AppSettings{
137137
Routable: api.NewRoutable(),
138-
Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
138+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
139139
Autoscale: map[string]*api.Autoscale{
140140
"cmd": {
141141
Min: 3,
@@ -176,7 +176,7 @@ func TestAppSettingsUnset(t *testing.T) {
176176
Owner: "test",
177177
App: "unset-test",
178178
Routable: api.NewRoutable(),
179-
Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
179+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
180180
Autoscale: map[string]*api.Autoscale{
181181
"cmd": {
182182
Min: 3,
@@ -195,7 +195,7 @@ func TestAppSettingsUnset(t *testing.T) {
195195

196196
appSettingsVars := api.AppSettings{
197197
Routable: api.NewRoutable(),
198-
Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
198+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
199199
Autoscale: map[string]*api.Autoscale{
200200
"cmd": {
201201
Min: 3,
@@ -236,7 +236,7 @@ func TestAppSettingsList(t *testing.T) {
236236
Owner: "test",
237237
App: "example-go",
238238
Routable: api.NewRoutable(),
239-
Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
239+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
240240
Autoscale: map[string]*api.Autoscale{
241241
"cmd": {
242242
Min: 3,

0 commit comments

Comments
 (0)