forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.go
40 lines (31 loc) · 1.02 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
38
39
40
package password
import (
"fmt"
"strings"
"github.com/cloudfoundry/cli/cf/configuration/coreconfig"
"github.com/cloudfoundry/cli/cf/errors"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/net"
)
//go:generate counterfeiter . Repository
type Repository interface {
UpdatePassword(old string, new string) error
}
type CloudControllerRepository struct {
config coreconfig.Reader
gateway net.Gateway
}
func NewCloudControllerRepository(config coreconfig.Reader, gateway net.Gateway) (repo CloudControllerRepository) {
repo.config = config
repo.gateway = gateway
return
}
func (repo CloudControllerRepository) UpdatePassword(old string, new string) error {
uaaEndpoint := repo.config.UaaEndpoint()
if uaaEndpoint == "" {
return errors.New(T("UAA endpoint missing from config file"))
}
url := fmt.Sprintf("/Users/%s/password", repo.config.UserGUID())
body := fmt.Sprintf(`{"password":"%s","oldPassword":"%s"}`, new, old)
return repo.gateway.UpdateResource(uaaEndpoint, url, strings.NewReader(body))
}