@@ -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
2223type cfConnector struct {
@@ -45,7 +46,7 @@ type Config struct {
4546}
4647
4748type 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
5859type Metadata struct {
59- Guid string `json:"guid"`
60+ GUID string `json:"guid"`
6061}
6162
6263type Entity struct {
6364 Name string `json:"name"`
64- OrganizationGuid string `json:"organization_guid"`
65+ OrganizationGUID string `json:"organization_guid"`
6566}
6667
6768type Space struct {
6869 Name string
69- Guid string
70- OrgGuid string
70+ GUID string
71+ OrgGUID string
7172 Role string
7273}
7374
7475type Org struct {
7576 Name string
76- Guid string
77+ GUID string
7778}
7879
7980func (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
179180func (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
269270func 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
308308func (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" ))
0 commit comments