From cbd0a52c81ffdd2da0b7429b0a89b8688092a9d1 Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Wed, 4 Nov 2020 16:01:56 +0800
Subject: [PATCH] chore(controller-sdk-go):replace whitelist with allowlist

---
 README.md                                     |  6 +--
 .../whitelist.go => allowlist/allowlist.go    | 42 +++++++++----------
 .../allowlist_test.go                         | 38 ++++++++---------
 api/appsettings.go                            |  6 +--
 appsettings/appsettings_test.go               | 18 ++++----
 5 files changed, 55 insertions(+), 55 deletions(-)
 rename whitelist/whitelist.go => allowlist/allowlist.go (50%)
 rename whitelist/whitelist_test.go => allowlist/allowlist_test.go (77%)

diff --git a/README.md b/README.md
index 1b0609a..ec487c1 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
 # Controller Go SDK
-[![Build Status](https://travis-ci.org/drycc/controller-sdk-go.svg?branch=master)](https://travis-ci.org/drycc/controller-sdk-go/)
-[![codecov](https://codecov.io/gh/drycc/controller-sdk-go/branch/master/graph/badge.svg)](https://codecov.io/gh/drycc/controller-sdk-go)
+[![Build Status](https://travis-ci.org/drycc/controller-sdk-go.svg?branch=main)](https://travis-ci.org/drycc/controller-sdk-go/)
+[![codecov](https://codecov.io/gh/drycc/controller-sdk-go/branch/main/graph/badge.svg)](https://codecov.io/gh/drycc/controller-sdk-go)
 [![Go Report Card](https://goreportcard.com/badge/github.com/drycc/controller-sdk-go)](https://goreportcard.com/report/github.com/drycc/controller-sdk-go)
-[![codebeat badge](https://codebeat.co/badges/3ae3560d-eebf-4b36-bbf3-780d2b2e26fd)](https://codebeat.co/projects/github-com-drycc-controller-sdk-go-master)
+[![codebeat badge](https://codebeat.co/badges/79dde330-50c5-45db-a1ef-cb6c48af5f5f)](https://codebeat.co/projects/github-com-drycc-controller-sdk-go-main)
 [![GoDoc](https://godoc.org/github.com/drycc/controller-sdk-go?status.svg)](https://godoc.org/github.com/drycc/controller-sdk-go)
 
 This is the Go SDK for interacting with the [Drycc Controller](https://github.com/drycc/controller).
diff --git a/whitelist/whitelist.go b/allowlist/allowlist.go
similarity index 50%
rename from whitelist/whitelist.go
rename to allowlist/allowlist.go
index 01c13b4..d646a1e 100644
--- a/whitelist/whitelist.go
+++ b/allowlist/allowlist.go
@@ -1,5 +1,5 @@
-// Package whitelist provides methods for managing an app's whitelisted IP's.
-package whitelist
+// Package allowlist provides methods for managing an app's allowlisted IP's.
+package allowlist
 
 import (
 	"encoding/json"
@@ -9,51 +9,51 @@ import (
 	"github.com/drycc/controller-sdk-go/api"
 )
 
-// List IP's whitelisted for an app.
-func List(c *drycc.Client, appID string) (api.Whitelist, error) {
-	u := fmt.Sprintf("/v2/apps/%s/whitelist/", appID)
+// List IP's allowlisted for an app.
+func List(c *drycc.Client, appID string) (api.Allowlist, error) {
+	u := fmt.Sprintf("/v2/apps/%s/allowlist/", appID)
 	res, reqErr := c.Request("GET", u, nil)
 	if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
-		return api.Whitelist{}, reqErr
+		return api.Allowlist{}, reqErr
 	}
 	defer res.Body.Close()
 
-	whitelist := api.Whitelist{}
-	if err := json.NewDecoder(res.Body).Decode(&whitelist); err != nil {
-		return api.Whitelist{}, err
+	allowlist := api.Allowlist{}
+	if err := json.NewDecoder(res.Body).Decode(&allowlist); err != nil {
+		return api.Allowlist{}, err
 	}
 
-	return whitelist, reqErr
+	return allowlist, reqErr
 }
 
-// Add adds addresses to an app's whitelist.
-func Add(c *drycc.Client, appID string, addresses []string) (api.Whitelist, error) {
-	u := fmt.Sprintf("/v2/apps/%s/whitelist/", appID)
+// Add adds addresses to an app's allowlist.
+func Add(c *drycc.Client, appID string, addresses []string) (api.Allowlist, error) {
+	u := fmt.Sprintf("/v2/apps/%s/allowlist/", appID)
 
-	req := api.Whitelist{Addresses: addresses}
+	req := api.Allowlist{Addresses: addresses}
 	body, err := json.Marshal(req)
 	if err != nil {
-		return api.Whitelist{}, err
+		return api.Allowlist{}, err
 	}
 	res, reqErr := c.Request("POST", u, body)
 	if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
-		return api.Whitelist{}, reqErr
+		return api.Allowlist{}, reqErr
 	}
 	defer res.Body.Close()
 
-	d := api.Whitelist{}
+	d := api.Allowlist{}
 	if err = json.NewDecoder(res.Body).Decode(&d); err != nil {
-		return api.Whitelist{}, err
+		return api.Allowlist{}, err
 	}
 
 	return d, reqErr
 }
 
-// Delete removes addresses from an app's whitelist.
+// Delete removes addresses from an app's allowlist.
 func Delete(c *drycc.Client, appID string, addresses []string) error {
-	u := fmt.Sprintf("/v2/apps/%s/whitelist/", appID)
+	u := fmt.Sprintf("/v2/apps/%s/allowlist/", appID)
 
-	req := api.Whitelist{Addresses: addresses}
+	req := api.Allowlist{Addresses: addresses}
 	body, err := json.Marshal(req)
 	if err != nil {
 		return err
diff --git a/whitelist/whitelist_test.go b/allowlist/allowlist_test.go
similarity index 77%
rename from whitelist/whitelist_test.go
rename to allowlist/allowlist_test.go
index e98bf7a..e8ceedf 100644
--- a/whitelist/whitelist_test.go
+++ b/allowlist/allowlist_test.go
@@ -1,4 +1,4 @@
-package whitelist
+package allowlist
 
 import (
 	"fmt"
@@ -12,24 +12,24 @@ import (
 	"github.com/drycc/controller-sdk-go/api"
 )
 
-const whitelistFixture string = `
+const allowlistFixture string = `
 {
     "addresses": ["1.2.3.4", "0.0.0.0/0"]
 }`
 
-const whitelistCreateExpected string = `{"addresses":["1.2.3.4","0.0.0.0/0"]}`
+const allowlistCreateExpected string = `{"addresses":["1.2.3.4","0.0.0.0/0"]}`
 
 type fakeHTTPServer struct{}
 
 func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
 	res.Header().Add("DRYCC_API_VERSION", drycc.APIVersion)
 
-	if req.URL.Path == "/v2/apps/example-go/whitelist/" && req.Method == "GET" {
-		res.Write([]byte(whitelistFixture))
+	if req.URL.Path == "/v2/apps/example-go/allowlist/" && req.Method == "GET" {
+		res.Write([]byte(allowlistFixture))
 		return
 	}
 
-	if req.URL.Path == "/v2/apps/example-go/whitelist/" && req.Method == "POST" {
+	if req.URL.Path == "/v2/apps/example-go/allowlist/" && req.Method == "POST" {
 		body, err := ioutil.ReadAll(req.Body)
 
 		if err != nil {
@@ -38,31 +38,31 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
 			res.Write(nil)
 		}
 
-		if string(body) != whitelistCreateExpected {
-			fmt.Printf("Expected '%s', Got '%s'\n", whitelistCreateExpected, body)
+		if string(body) != allowlistCreateExpected {
+			fmt.Printf("Expected '%s', Got '%s'\n", allowlistCreateExpected, body)
 			res.WriteHeader(http.StatusInternalServerError)
 			res.Write(nil)
 			return
 		}
 
 		res.WriteHeader(http.StatusCreated)
-		res.Write([]byte(whitelistFixture))
+		res.Write([]byte(allowlistFixture))
 		return
 	}
 
-	if req.URL.Path == "/v2/apps/example-go/whitelist/" && req.Method == "DELETE" {
+	if req.URL.Path == "/v2/apps/example-go/allowlist/" && req.Method == "DELETE" {
 		res.WriteHeader(http.StatusNoContent)
-		res.Write([]byte(whitelistFixture))
+		res.Write([]byte(allowlistFixture))
 		return
 	}
 
-	if req.URL.Path == "/v2/apps/invalidjson-test/whitelist/" && req.Method == "POST" {
+	if req.URL.Path == "/v2/apps/invalidjson-test/allowlist/" && req.Method == "POST" {
 		res.WriteHeader(http.StatusCreated)
 		res.Write([]byte(`"addresses": "test"`))
 		return
 	}
 
-	if req.URL.Path == "/v2/apps/invalidjson-test/whitelist/" && req.Method == "GET" {
+	if req.URL.Path == "/v2/apps/invalidjson-test/allowlist/" && req.Method == "GET" {
 		res.Write([]byte(`"addresses": "test"`))
 		return
 	}
@@ -72,10 +72,10 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
 	res.Write(nil)
 }
 
-func TestWhitelistList(t *testing.T) {
+func TestAllowlistList(t *testing.T) {
 	t.Parallel()
 
-	expected := api.Whitelist{
+	expected := api.Allowlist{
 		Addresses: []string{"1.2.3.4", "0.0.0.0/0"},
 	}
 
@@ -99,10 +99,10 @@ func TestWhitelistList(t *testing.T) {
 	}
 }
 
-func TestWhitelistAdd(t *testing.T) {
+func TestAllowlistAdd(t *testing.T) {
 	t.Parallel()
 
-	expected := api.Whitelist{
+	expected := api.Allowlist{
 		Addresses: []string{"1.2.3.4", "0.0.0.0/0"},
 	}
 
@@ -126,7 +126,7 @@ func TestWhitelistAdd(t *testing.T) {
 	}
 }
 
-func TestWhitelistRemove(t *testing.T) {
+func TestAllowlistRemove(t *testing.T) {
 	t.Parallel()
 
 	handler := fakeHTTPServer{}
@@ -156,7 +156,7 @@ func TestAppSettingsInvalidJson(t *testing.T) {
 	}
 
 	_, err = List(drycc, "invalidjson-test")
-	expected := "json: cannot unmarshal string into Go value of type api.Whitelist"
+	expected := "json: cannot unmarshal string into Go value of type api.Allowlist"
 	if err == nil || !reflect.DeepEqual(expected, err.Error()) {
 		t.Errorf("Expected %v, Got %v", expected, err)
 	}
diff --git a/api/appsettings.go b/api/appsettings.go
index 6bb44d5..d9e17c6 100644
--- a/api/appsettings.go
+++ b/api/appsettings.go
@@ -20,7 +20,7 @@ type AppSettings struct {
 	UUID string `json:"uuid,omitempty"`
 	// Routable determines if the application should be exposed by the router.
 	Routable  *bool                 `json:"routable,omitempty"`
-	Whitelist []string              `json:"whitelist,omitempty"`
+	Allowlist []string              `json:"allowlist,omitempty"`
 	Autoscale map[string]*Autoscale `json:"autoscale,omitempty"`
 	Label     Labels                `json:"label,omitempty"`
 }
@@ -31,8 +31,8 @@ func NewRoutable() *bool {
 	return &b
 }
 
-// Whitelist is the structure of POST /v2/app/<app id>/whitelist/.
-type Whitelist struct {
+// Allowlist is the structure of POST /v2/app/<app id>/allowlist/.
+type Allowlist struct {
 	Addresses []string `json:"addresses"`
 }
 
diff --git a/appsettings/appsettings_test.go b/appsettings/appsettings_test.go
index 1de1bea..5aafae3 100644
--- a/appsettings/appsettings_test.go
+++ b/appsettings/appsettings_test.go
@@ -17,7 +17,7 @@ const appSettingsFixture string = `
     "owner": "test",
     "app": "example-go",
     "routable": true,
-    "whitelist": ["1.2.3.4", "0.0.0.0/0"],
+    "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"},
     "created": "2014-01-01T00:00:00UTC",
@@ -31,7 +31,7 @@ const appSettingsUnsetFixture string = `
     "owner": "test",
     "app": "unset-test",
     "routable": true,
-    "whitelist": ["1.2.3.4", "0.0.0.0/0"],
+    "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"},
     "created": "2014-01-01T00:00:00UTC",
@@ -40,8 +40,8 @@ const appSettingsUnsetFixture string = `
 }
 `
 
-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"}}`
-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"}}`
+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"}}`
+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"}}`
 
 type fakeHTTPServer struct{}
 
@@ -116,7 +116,7 @@ func TestAppSettingsSet(t *testing.T) {
 		Owner:     "test",
 		App:       "example-go",
 		Routable:  api.NewRoutable(),
-		Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
@@ -135,7 +135,7 @@ func TestAppSettingsSet(t *testing.T) {
 
 	appSettingsVars := api.AppSettings{
 		Routable:  api.NewRoutable(),
-		Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
@@ -176,7 +176,7 @@ func TestAppSettingsUnset(t *testing.T) {
 		Owner:     "test",
 		App:       "unset-test",
 		Routable:  api.NewRoutable(),
-		Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
@@ -195,7 +195,7 @@ func TestAppSettingsUnset(t *testing.T) {
 
 	appSettingsVars := api.AppSettings{
 		Routable:  api.NewRoutable(),
-		Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
@@ -236,7 +236,7 @@ func TestAppSettingsList(t *testing.T) {
 		Owner:     "test",
 		App:       "example-go",
 		Routable:  api.NewRoutable(),
-		Whitelist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
