forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.go
38 lines (30 loc) · 1.03 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
package password
import (
"fmt"
"strings"
"github.com/cloudfoundry/cli/cf/configuration/core_config"
"github.com/cloudfoundry/cli/cf/errors"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/net"
)
type PasswordRepository interface {
UpdatePassword(old string, new string) error
}
type CloudControllerPasswordRepository struct {
config core_config.Reader
gateway net.Gateway
}
func NewCloudControllerPasswordRepository(config core_config.Reader, gateway net.Gateway) (repo CloudControllerPasswordRepository) {
repo.config = config
repo.gateway = gateway
return
}
func (repo CloudControllerPasswordRepository) 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))
}