github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/api/password/password.go (about) 1 package password 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/cloudfoundry/cli/cf/configuration/core_config" 8 "github.com/cloudfoundry/cli/cf/errors" 9 . "github.com/cloudfoundry/cli/cf/i18n" 10 "github.com/cloudfoundry/cli/cf/net" 11 ) 12 13 type PasswordRepository interface { 14 UpdatePassword(old string, new string) error 15 } 16 17 type CloudControllerPasswordRepository struct { 18 config core_config.Reader 19 gateway net.Gateway 20 } 21 22 func NewCloudControllerPasswordRepository(config core_config.Reader, gateway net.Gateway) (repo CloudControllerPasswordRepository) { 23 repo.config = config 24 repo.gateway = gateway 25 return 26 } 27 28 func (repo CloudControllerPasswordRepository) UpdatePassword(old string, new string) error { 29 uaaEndpoint := repo.config.UaaEndpoint() 30 if uaaEndpoint == "" { 31 return errors.New(T("UAA endpoint missing from config file")) 32 } 33 34 url := fmt.Sprintf("/Users/%s/password", repo.config.UserGuid()) 35 body := fmt.Sprintf(`{"password":"%s","oldPassword":"%s"}`, new, old) 36 37 return repo.gateway.UpdateResource(uaaEndpoint, url, strings.NewReader(body)) 38 }