Skip to content

Commit 7d9e841

Browse files
Rui YangCI Bot
authored andcommitted
fix lint errors
Signed-off-by: Rui Yang <ryang@pivotal.io>
1 parent 369ea71 commit 7d9e841

2 files changed

Lines changed: 46 additions & 48 deletions

File tree

connector/cf/cf.go

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import (
1414
"strings"
1515
"time"
1616

17+
"golang.org/x/oauth2"
18+
1719
"github.com/dexidp/dex/connector"
1820
"github.com/dexidp/dex/pkg/log"
19-
"golang.org/x/oauth2"
2021
)
2122

2223
type cfConnector struct {
@@ -45,7 +46,7 @@ type Config struct {
4546
}
4647

4748
type CCResponse struct {
48-
NextUrl string `json:"next_url"`
49+
NextURL string `json:"next_url"`
4950
Resources []Resource `json:"resources"`
5051
TotalResults int `json:"total_results"`
5152
}
@@ -56,24 +57,24 @@ type Resource struct {
5657
}
5758

5859
type Metadata struct {
59-
Guid string `json:"guid"`
60+
GUID string `json:"guid"`
6061
}
6162

6263
type Entity struct {
6364
Name string `json:"name"`
64-
OrganizationGuid string `json:"organization_guid"`
65+
OrganizationGUID string `json:"organization_guid"`
6566
}
6667

6768
type Space struct {
6869
Name string
69-
Guid string
70-
OrgGuid string
70+
GUID string
71+
OrgGUID string
7172
Role string
7273
}
7374

7475
type Org struct {
7576
Name string
76-
Guid string
77+
GUID string
7778
}
7879

7980
func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
@@ -103,7 +104,7 @@ func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error)
103104
defer apiResp.Body.Close()
104105

105106
if apiResp.StatusCode != http.StatusOK {
106-
err = errors.New(fmt.Sprintf("request failed with status %d", apiResp.StatusCode))
107+
err = fmt.Errorf("request failed with status %d", apiResp.StatusCode)
107108
logger.Errorf("failed-get-info-response-from-api", err)
108109
return nil, err
109110
}
@@ -120,8 +121,8 @@ func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error)
120121
}
121122

122123
if apiResp.StatusCode != http.StatusOK {
123-
err = errors.New(fmt.Sprintf("request failed with status %d", apiResp.StatusCode))
124-
logger.Errorf("failed-to-get-well-known-config-repsonse-from-api", err)
124+
err = fmt.Errorf("request failed with status %d", apiResp.StatusCode)
125+
logger.Errorf("failed-to-get-well-known-config-response-from-api", err)
125126
return nil, err
126127
}
127128

@@ -177,7 +178,6 @@ func newHTTPClient(rootCAs []string, insecureSkipVerify bool) (*http.Client, err
177178
}
178179

179180
func (c *cfConnector) LoginURL(scopes connector.Scopes, callbackURL, state string) (string, error) {
180-
181181
if c.redirectURI != callbackURL {
182182
return "", fmt.Errorf("expected callback URL %q did not match the URL in the config %q", callbackURL, c.redirectURI)
183183
}
@@ -193,57 +193,58 @@ func (c *cfConnector) LoginURL(scopes connector.Scopes, callbackURL, state strin
193193
return oauth2Config.AuthCodeURL(state), nil
194194
}
195195

196-
func fetchRoleSpaces(baseUrl, path, role string, client *http.Client) ([]Space, error) {
196+
func fetchRoleSpaces(baseURL, path, role string, client *http.Client) ([]Space, error) {
197197
var spaces []Space
198198

199-
resources, err := fetchResources(baseUrl, path, client)
199+
resources, err := fetchResources(baseURL, path, client)
200200
if err != nil {
201201
return nil, fmt.Errorf("failed to fetch resources: %v", err)
202202
}
203203

204204
for _, resource := range resources {
205205
spaces = append(spaces, Space{
206206
Name: resource.Entity.Name,
207-
Guid: resource.Metadata.Guid,
208-
OrgGuid: resource.Entity.OrganizationGuid,
207+
GUID: resource.Metadata.GUID,
208+
OrgGUID: resource.Entity.OrganizationGUID,
209209
Role: role,
210210
})
211211
}
212212

213213
return spaces, nil
214214
}
215215

216-
func fetchOrgs(baseUrl, path string, client *http.Client) ([]Org, error) {
216+
func fetchOrgs(baseURL, path string, client *http.Client) ([]Org, error) {
217217
var orgs []Org
218218

219-
resources, err := fetchResources(baseUrl, path, client)
219+
resources, err := fetchResources(baseURL, path, client)
220220
if err != nil {
221221
return nil, fmt.Errorf("failed to fetch resources: %v", err)
222222
}
223223

224224
for _, resource := range resources {
225225
orgs = append(orgs, Org{
226226
Name: resource.Entity.Name,
227-
Guid: resource.Metadata.Guid,
227+
GUID: resource.Metadata.GUID,
228228
})
229229
}
230230

231231
return orgs, nil
232232
}
233233

234-
func fetchResources(baseUrl, path string, client *http.Client) ([]Resource, error) {
234+
func fetchResources(baseURL, path string, client *http.Client) ([]Resource, error) {
235235
var (
236236
resources []Resource
237237
url string
238238
)
239239

240240
for {
241-
url = fmt.Sprintf("%s%s", baseUrl, path)
241+
url = fmt.Sprintf("%s%s", baseURL, path)
242242

243243
resp, err := client.Get(url)
244244
if err != nil {
245245
return nil, fmt.Errorf("failed to execute request: %v", err)
246246
}
247+
defer resp.Body.Close()
247248

248249
if resp.StatusCode != http.StatusOK {
249250
return nil, fmt.Errorf("unsuccessful status code %d", resp.StatusCode)
@@ -257,7 +258,7 @@ func fetchResources(baseUrl, path string, client *http.Client) ([]Resource, erro
257258

258259
resources = append(resources, response.Resources...)
259260

260-
path = response.NextUrl
261+
path = response.NextURL
261262
if path == "" {
262263
break
263264
}
@@ -267,25 +268,24 @@ func fetchResources(baseUrl, path string, client *http.Client) ([]Resource, erro
267268
}
268269

269270
func getGroupsClaims(orgs []Org, spaces []Space) []string {
270-
271271
var (
272272
orgMap = map[string]string{}
273273
orgSpaces = map[string][]Space{}
274274
groupsClaims = map[string]bool{}
275275
)
276276

277277
for _, org := range orgs {
278-
orgMap[org.Guid] = org.Name
278+
orgMap[org.GUID] = org.Name
279279
orgSpaces[org.Name] = []Space{}
280-
groupsClaims[org.Guid] = true
280+
groupsClaims[org.GUID] = true
281281
groupsClaims[org.Name] = true
282282
}
283283

284284
for _, space := range spaces {
285-
orgName := orgMap[space.OrgGuid]
285+
orgName := orgMap[space.OrgGUID]
286286
orgSpaces[orgName] = append(orgSpaces[orgName], space)
287-
groupsClaims[space.Guid] = true
288-
groupsClaims[fmt.Sprintf("%s:%s", space.Guid, space.Role)] = true
287+
groupsClaims[space.GUID] = true
288+
groupsClaims[fmt.Sprintf("%s:%s", space.GUID, space.Role)] = true
289289
}
290290

291291
for orgName, spaces := range orgSpaces {
@@ -296,7 +296,7 @@ func getGroupsClaims(orgs []Org, spaces []Space) []string {
296296
}
297297

298298
var groups []string
299-
for group, _ := range groupsClaims {
299+
for group := range groupsClaims {
300300
groups = append(groups, group)
301301
}
302302

@@ -306,7 +306,6 @@ func getGroupsClaims(orgs []Org, spaces []Space) []string {
306306
}
307307

308308
func (c *cfConnector) HandleCallback(s connector.Scopes, r *http.Request) (identity connector.Identity, err error) {
309-
310309
q := r.URL.Query()
311310
if errType := q.Get("error"); errType != "" {
312311
return identity, errors.New(q.Get("error_description"))

connector/cf/cf_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/dexidp/dex/connector"
1413
"github.com/sirupsen/logrus"
14+
15+
"github.com/dexidp/dex/connector"
1516
)
1617

1718
func TestOpen(t *testing.T) {
@@ -26,7 +27,6 @@ func TestOpen(t *testing.T) {
2627
}
2728

2829
func TestHandleCallback(t *testing.T) {
29-
3030
testServer := testSetup()
3131
defer testServer.Close()
3232

@@ -97,9 +97,9 @@ func TestHandleCallback(t *testing.T) {
9797
})
9898
}
9999

100-
func testSpaceHandler(reqUrl, spaceApiEndpoint string) (result map[string]interface{}) {
101-
fullUrl := fmt.Sprintf("%s?order-direction=asc&page=2&results-per-page=50", spaceApiEndpoint)
102-
if strings.Contains(reqUrl, fullUrl) {
100+
func testSpaceHandler(reqURL, spaceAPIEndpoint string) (result map[string]interface{}) {
101+
fullURL := fmt.Sprintf("%s?order-direction=asc&page=2&results-per-page=50", spaceAPIEndpoint)
102+
if strings.Contains(reqURL, fullURL) {
103103
result = map[string]interface{}{
104104
"resources": []map[string]interface{}{
105105
{
@@ -109,9 +109,9 @@ func testSpaceHandler(reqUrl, spaceApiEndpoint string) (result map[string]interf
109109
},
110110
}
111111
} else {
112-
nextUrl := fmt.Sprintf("/v2/users/12345/%s?order-direction=asc&page=2&results-per-page=50", spaceApiEndpoint)
112+
nextURL := fmt.Sprintf("/v2/users/12345/%s?order-direction=asc&page=2&results-per-page=50", spaceAPIEndpoint)
113113
result = map[string]interface{}{
114-
"next_url": nextUrl,
114+
"next_url": nextURL,
115115
"resources": []map[string]interface{}{
116116
{
117117
"metadata": map[string]string{"guid": "some-space-guid-1"},
@@ -123,8 +123,8 @@ func testSpaceHandler(reqUrl, spaceApiEndpoint string) (result map[string]interf
123123
return result
124124
}
125125

126-
func testOrgHandler(reqUrl string) (result map[string]interface{}) {
127-
if strings.Contains(reqUrl, "organizations?order-direction=asc&page=2&results-per-page=50") {
126+
func testOrgHandler(reqURL string) (result map[string]interface{}) {
127+
if strings.Contains(reqURL, "organizations?order-direction=asc&page=2&results-per-page=50") {
128128
result = map[string]interface{}{
129129
"resources": []map[string]interface{}{
130130
{
@@ -197,21 +197,21 @@ func testSetup() *httptest.Server {
197197
mux.HandleFunc("/v2/users/", func(w http.ResponseWriter, r *http.Request) {
198198
var result map[string]interface{}
199199

200-
reqUrl := r.URL.String()
201-
if strings.Contains(reqUrl, "/spaces") {
202-
result = testSpaceHandler(reqUrl, "spaces")
200+
reqURL := r.URL.String()
201+
if strings.Contains(reqURL, "/spaces") {
202+
result = testSpaceHandler(reqURL, "spaces")
203203
}
204204

205-
if strings.Contains(reqUrl, "/audited_spaces") {
206-
result = testSpaceHandler(reqUrl, "audited_spaces")
205+
if strings.Contains(reqURL, "/audited_spaces") {
206+
result = testSpaceHandler(reqURL, "audited_spaces")
207207
}
208208

209-
if strings.Contains(reqUrl, "/managed_spaces") {
210-
result = testSpaceHandler(reqUrl, "managed_spaces")
209+
if strings.Contains(reqURL, "/managed_spaces") {
210+
result = testSpaceHandler(reqURL, "managed_spaces")
211211
}
212212

213-
if strings.Contains(reqUrl, "organizations") {
214-
result = testOrgHandler(reqUrl)
213+
if strings.Contains(reqURL, "organizations") {
214+
result = testOrgHandler(reqURL)
215215
}
216216

217217
json.NewEncoder(w).Encode(result)
@@ -221,7 +221,6 @@ func testSetup() *httptest.Server {
221221
}
222222

223223
func newConnector(t *testing.T, serverURL string) *cfConnector {
224-
225224
callBackURL := fmt.Sprintf("%s/callback", serverURL)
226225

227226
testConfig := Config{

0 commit comments

Comments
 (0)