Skip to content

Commit

Permalink
feat(loadFromVCAPServices): Service configuration factory.
Browse files Browse the repository at this point in the history
Remove ConfigureService call from the BaseService constructor function.
Add a name field to the service interface.
Create a list of service entries and check for the service name within them before checking the keys to the service entry lists.
Update unit test to check that loadFromVCAPServices is looking for service credentials from the VCAP in the correct order.
loadFromVCAPServices checks for service names in keys of service entry lists before checking keys to service entry lists.

BREAKING CHANGE: NewBaseService constructor changes. `displayname`, and `serviceName` removed from construction function signature, since they are no longer used.
  • Loading branch information
mgrattray authored Nov 6, 2019
1 parent 1b6cc79 commit 87ac493
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 106 deletions.
2 changes: 1 addition & 1 deletion core/authenticator_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestGetAuthenticatorFromEnvironment2(t *testing.T) {
}

func TestGetAuthenticatorFromEnvironment3(t *testing.T) {
setTestVCAP()
setTestVCAP(t)

authenticator, err := GetAuthenticatorFromEnvironment("service-1")
assert.Nil(t, err)
Expand Down
8 changes: 2 additions & 6 deletions core/base_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type BaseService struct {

// NewBaseService : This function will construct a new instance of the BaseService struct, while
// performing validation on input parameters and service options.
func NewBaseService(options *ServiceOptions, serviceName, displayName string) (*BaseService, error) {
func NewBaseService(options *ServiceOptions) (*BaseService, error) {
if HasBadFirstOrLastChar(options.URL) {
return nil, fmt.Errorf(ERRORMSG_PROP_INVALID, "URL")
}
Expand All @@ -88,14 +88,10 @@ func NewBaseService(options *ServiceOptions, serviceName, displayName string) (*
// Set a default value for the User-Agent http header.
service.SetUserAgent(service.buildUserAgent())

err := service.ConfigureService(serviceName)
if err != nil {
return nil, err
}

return &service, nil
}

// ConfigureService configures the BaseService using external properties.
func (service *BaseService) ConfigureService(serviceName string) error {
// Try to load service properties from external config.
serviceProps, err := getServiceProperties(serviceName)
Expand Down
Loading

0 comments on commit 87ac493

Please sign in to comment.