MCPcopy
hub / github.com/cloudfoundry/cli / Create

Method Create

cf/api/users.go:161–198  ·  view source on GitHub ↗
(username, password string)

Source from the content-addressed store, hash-verified

159}
160
161func (repo CloudControllerUserRepository) Create(username, password string) (err error) {
162 uaaEndpoint, err := repo.getAuthEndpoint()
163 if err != nil {
164 return
165 }
166
167 path := "/Users"
168 body, err := json.Marshal(resources.NewUAAUserResource(username, password))
169
170 if err != nil {
171 return
172 }
173
174 createUserResponse := &resources.UAAUserFields{}
175 err = repo.uaaGateway.CreateResource(uaaEndpoint, path, bytes.NewReader(body), createUserResponse)
176 switch httpErr := err.(type) {
177 case nil:
178 case errors.HTTPError:
179 if httpErr.StatusCode() == http.StatusConflict {
180 err = errors.NewModelAlreadyExistsError("user", username)
181 return
182 }
183 return
184 default:
185 return
186 }
187
188 path = "/v2/users"
189 body, err = json.Marshal(resources.Metadata{
190 GUID: createUserResponse.ID,
191 })
192
193 if err != nil {
194 return
195 }
196
197 return repo.ccGateway.CreateResource(repo.config.APIEndpoint(), path, bytes.NewReader(body))
198}
199
200func (repo CloudControllerUserRepository) Delete(userGUID string) (apiErr error) {
201 path := fmt.Sprintf("/v2/users/%s", userGUID)

Callers

nothing calls this directly

Calls 6

getAuthEndpointMethod · 0.95
NewUAAUserResourceFunction · 0.92
CreateResourceMethod · 0.80
StatusCodeMethod · 0.65
APIEndpointMethod · 0.65

Tested by

no test coverage detected