forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.go
37 lines (30 loc) · 1.04 KB
/
password.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package api
import (
"cf/configuration"
"cf/net"
"fmt"
"strings"
)
type PasswordRepository interface {
UpdatePassword(old string, new string) net.ApiResponse
}
type CloudControllerPasswordRepository struct {
config *configuration.Configuration
gateway net.Gateway
endpointRepo EndpointRepository
}
func NewCloudControllerPasswordRepository(config *configuration.Configuration, gateway net.Gateway, endpointRepo EndpointRepository) (repo CloudControllerPasswordRepository) {
repo.config = config
repo.gateway = gateway
repo.endpointRepo = endpointRepo
return
}
func (repo CloudControllerPasswordRepository) UpdatePassword(old string, new string) (apiResponse net.ApiResponse) {
uaaEndpoint, apiResponse := repo.endpointRepo.GetUAAEndpoint()
if apiResponse.IsNotSuccessful() {
return
}
path := fmt.Sprintf("%s/Users/%s/password", uaaEndpoint, repo.config.UserGuid())
body := fmt.Sprintf(`{"password":"%s","oldPassword":"%s"}`, new, old)
return repo.gateway.UpdateResource(path, repo.config.AccessToken, strings.NewReader(body))
}