MCPcopy Index your code
hub / github.com/cloudfoundry/cli / ClientExists

Method ClientExists

cf/api/clients.go:31–54  ·  view source on GitHub ↗
(clientID string)

Source from the content-addressed store, hash-verified

29}
30
31func (repo CloudControllerClientRepository) ClientExists(clientID string) (exists bool, apiErr error) {
32 exists = false
33 uaaEndpoint, apiErr := repo.getAuthEndpoint()
34 if apiErr != nil {
35 return exists, apiErr
36 }
37
38 path := fmt.Sprintf("%s/oauth/clients/%s", uaaEndpoint, clientID)
39
40 uaaResponse := new(resources.UAAUserResources)
41 apiErr = repo.uaaGateway.GetResource(path, uaaResponse)
42 if apiErr != nil {
43 if errType, ok := apiErr.(errors.HTTPError); ok {
44 switch errType.StatusCode() {
45 case http.StatusNotFound:
46 return false, errors.NewModelNotFoundError("Client", clientID)
47 case http.StatusForbidden:
48 return false, errors.NewAccessDeniedError()
49 }
50 }
51 return false, apiErr
52 }
53 return true, nil
54}
55
56func (repo CloudControllerClientRepository) getAuthEndpoint() (string, error) {
57 uaaEndpoint := repo.config.UaaEndpoint()

Callers

nothing calls this directly

Calls 5

getAuthEndpointMethod · 0.95
NewModelNotFoundErrorFunction · 0.92
NewAccessDeniedErrorFunction · 0.92
GetResourceMethod · 0.80
StatusCodeMethod · 0.65

Tested by

no test coverage detected