Skip to content

Commit

Permalink
Eliminate the internal package
Browse files Browse the repository at this point in the history
  • Loading branch information
joefitzgerald committed Jun 7, 2018
1 parent 3186326 commit 2327512
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 164 deletions.
6 changes: 2 additions & 4 deletions clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"net/http"
"strings"

"github.com/cloudfoundry-community/go-uaa/internal/utils"
)

const clientsResource string = "/oauth/clients"
Expand Down Expand Up @@ -45,7 +43,7 @@ func errorMissingValue(value string) error {
}

func requireRedirectURIForGrantType(c *Client, grantType GrantType) error {
if utils.Contains(c.AuthorizedGrantTypes, string(grantType)) {
if contains(c.AuthorizedGrantTypes, string(grantType)) {
if len(c.RedirectURI) == 0 {
return errorMissingValueForGrantType("redirect_uri", grantType)
}
Expand All @@ -54,7 +52,7 @@ func requireRedirectURIForGrantType(c *Client, grantType GrantType) error {
}

func requireClientSecretForGrantType(c *Client, grantType GrantType) error {
if utils.Contains(c.AuthorizedGrantTypes, string(grantType)) {
if contains(c.AuthorizedGrantTypes, string(grantType)) {
if c.ClientSecret == "" {
return errorMissingValueForGrantType("client_secret", grantType)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/utils/contains.go → contains.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package utils
package uaa

func Contains(slice []string, toFind string) bool {
func contains(slice []string, toFind string) bool {
for _, a := range slice {
if a == toFind {
return true
Expand Down
22 changes: 22 additions & 0 deletions contains_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uaa

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("contains", func() {
list := []string{"do", "re", "mi"}

It("returns true if present", func() {
Expect(contains(list, "re")).To(BeTrue())
})

It("returns false if not present", func() {
Expect(contains(list, "fa")).To(BeFalse())
})

It("handles empty list", func() {
Expect(contains([]string{}, "fa")).To(BeFalse())
})
})
4 changes: 1 addition & 3 deletions curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"net/http/httputil"
"net/textproto"
"strings"

"github.com/cloudfoundry-community/go-uaa/internal/utils"
)

// CurlManager allows you to make arbitrary requests to the UAA API.
Expand All @@ -24,7 +22,7 @@ func (cm CurlManager) Curl(path, method, data string, headers []string) (resHead
target := cm.Config.GetActiveTarget()
context := target.GetActiveContext()

url, err := utils.BuildURL(target.BaseURL, path)
url, err := buildURL(target.BaseURL, path)
if err != nil {
return
}
Expand Down
1 change: 0 additions & 1 deletion curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/onsi/gomega/ghttp"

. "github.com/cloudfoundry-community/go-uaa"
. "github.com/cloudfoundry-community/go-uaa/internal/fixtures"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
37 changes: 36 additions & 1 deletion groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/onsi/gomega/ghttp"

. "github.com/cloudfoundry-community/go-uaa"
. "github.com/cloudfoundry-community/go-uaa/internal/fixtures"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand All @@ -26,6 +25,42 @@ var _ = Describe("Groups", func() {
gm = GroupManager{HTTPClient: &http.Client{}, Config: config}
})

CloudControllerReadGroupResponse := `{
"id" : "ea777017-883e-48ba-800a-637c71409b5e",
"meta" : {
"version" : 1,
"created" : "2017-01-15T16:54:15.677Z",
"lastModified" : "2017-08-15T16:54:15.677Z"
},
"displayName" : "cloud_controller.read",
"description" : "View details of your applications and services",
"members" : [ {
"origin" : "uaa",
"type" : "USER",
"value" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70"
} ],
"zoneID" : "uaa",
"schemas" : [ "urn:scim:schemas:core:1.0" ]
}`

UaaAdminGroupResponse := `{
"id" : "05a0c169-3592-4a45-b109-a16d9246e0ab",
"meta" : {
"version" : 1,
"created" : "2017-01-15T16:54:15.677Z",
"lastModified" : "2017-08-15T16:54:15.677Z"
},
"displayName" : "uaa.admin",
"description" : "Act as an administrator throughout the UAA",
"members" : [ {
"origin" : "uaa",
"type" : "USER",
"value" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70"
} ],
"zoneID" : "uaa",
"schemas" : [ "urn:scim:schemas:core:1.0" ]
}`

var groupListResponse = fmt.Sprintf(PaginatedResponseTmpl, UaaAdminGroupResponse, CloudControllerReadGroupResponse)

Describe("GroupManager#Get", func() {
Expand Down
4 changes: 1 addition & 3 deletions health.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package uaa

import (
"net/http"

"github.com/cloudfoundry-community/go-uaa/internal/utils"
)

// HealthStatus is either ok or an error.
Expand All @@ -18,7 +16,7 @@ const (

// Health gets the health of the UAA API.
func Health(target Target) (HealthStatus, error) {
url, err := utils.BuildURL(target.BaseURL, "healthz")
url, err := buildURL(target.BaseURL, "healthz")
if err != nil {
return "", err
}
Expand Down
14 changes: 6 additions & 8 deletions http_request_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"net/http"
"net/url"
"strconv"

"github.com/cloudfoundry-community/go-uaa/internal/utils"
)

// httpRequestFactory is a request builder.
Expand All @@ -29,7 +27,7 @@ type authenticatedRequestFactory struct{}

// Get creates a get request with the given target, path and query.
func (urf unauthenticatedRequestFactory) Get(target Target, path string, query string) (*http.Request, error) {
targetURL, err := utils.BuildURL(target.BaseURL, path)
targetURL, err := buildURL(target.BaseURL, path)
if err != nil {
return nil, err
}
Expand All @@ -46,7 +44,7 @@ func (urf unauthenticatedRequestFactory) Get(target Target, path string, query s

// Delete creates a delete request with the given target, path, and query.
func (urf unauthenticatedRequestFactory) Delete(target Target, path string, query string) (*http.Request, error) {
targetURL, err := utils.BuildURL(target.BaseURL, path)
targetURL, err := buildURL(target.BaseURL, path)
if err != nil {
return nil, err
}
Expand All @@ -63,7 +61,7 @@ func (urf unauthenticatedRequestFactory) Delete(target Target, path string, quer

// PostForm creates a post request with the given target, path, query, and data.
func (urf unauthenticatedRequestFactory) PostForm(target Target, path string, query string, data *url.Values) (*http.Request, error) {
targetURL, err := utils.BuildURL(target.BaseURL, path)
targetURL, err := buildURL(target.BaseURL, path)
if err != nil {
return nil, err
}
Expand All @@ -83,7 +81,7 @@ func (urf unauthenticatedRequestFactory) PostForm(target Target, path string, qu

// PostJSON creates a post request with the given target, path, query, and body.
func (urf unauthenticatedRequestFactory) PostJSON(target Target, path string, query string, body interface{}) (*http.Request, error) {
targetURL, err := utils.BuildURL(target.BaseURL, path)
targetURL, err := buildURL(target.BaseURL, path)
if err != nil {
return nil, err
}
Expand All @@ -108,7 +106,7 @@ func (urf unauthenticatedRequestFactory) PostJSON(target Target, path string, qu

// PutJSON creates a put request with the given target, path, query, and body.
func (urf unauthenticatedRequestFactory) PutJSON(target Target, path string, query string, body interface{}) (*http.Request, error) {
targetURL, err := utils.BuildURL(target.BaseURL, path)
targetURL, err := buildURL(target.BaseURL, path)
if err != nil {
return nil, err
}
Expand All @@ -133,7 +131,7 @@ func (urf unauthenticatedRequestFactory) PutJSON(target Target, path string, que

// PatchJSON creates a patch request with the given body
func (urf unauthenticatedRequestFactory) PatchJSON(target Target, path string, query string, body interface{}) (*http.Request, error) {
targetURL, err := utils.BuildURL(target.BaseURL, path)
targetURL, err := buildURL(target.BaseURL, path)
if err != nil {
return nil, err
}
Expand Down
37 changes: 0 additions & 37 deletions internal/fixtures/groups.go

This file was deleted.

11 changes: 0 additions & 11 deletions internal/utils/boolean_pointers.go

This file was deleted.

24 changes: 0 additions & 24 deletions internal/utils/contains_test.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/utils/stringifier.go

This file was deleted.

17 changes: 0 additions & 17 deletions internal/utils/stringifier_test.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/utils/styling.go

This file was deleted.

13 changes: 0 additions & 13 deletions internal/utils/utils_suite_test.go

This file was deleted.

6 changes: 3 additions & 3 deletions request_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"net/http"
"net/http/httputil"

"github.com/cloudfoundry-community/go-uaa/internal/utils"
"github.com/fatih/color"
)

func logResponse(response *http.Response) {
dumped, _ := httputil.DumpResponse(response, true)

if is2XX(response.StatusCode) {
fmt.Println(utils.Green(string(dumped)) + "\n")
fmt.Println(color.New(color.FgGreen).SprintFunc()(string(dumped)) + "\n")
} else {
fmt.Println(utils.Red(string(dumped)) + "\n")
fmt.Println(color.New(color.FgRed).SprintFunc()(string(dumped)) + "\n")
}
}

Expand Down
15 changes: 15 additions & 0 deletions stringifier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package uaa

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Stringifier", func() {
It("presents a string slice as a string", func() {
Expect(stringSliceStringifier([]string{"foo", "bar", "baz"})).To(Equal("[foo, bar, baz]"))
Expect(stringSliceStringifier([]string{"foo"})).To(Equal("[foo]"))
Expect(stringSliceStringifier([]string{})).To(Equal("[]"))
Expect(stringSliceStringifier([]string{" "})).To(Equal("[ ]"))
})
})
6 changes: 3 additions & 3 deletions internal/utils/url_helpers.go → url_helpers.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package utils
package uaa

import (
"net/url"
)

// BuildURL validates that the baseURL is valid and then sets the given path on
// buildURL validates that the baseURL is valid and then sets the given path on
// it.
func BuildURL(baseURL, path string) (*url.URL, error) {
func buildURL(baseURL, path string) (*url.URL, error) {
newURL, err := url.Parse(baseURL)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 2327512

Please sign in to comment.