Skip to content

Commit

Permalink
Setting cachedVersion in a single place
Browse files Browse the repository at this point in the history
Signed-off-by: Victoria Henry <vhenry@pivotal.io>
  • Loading branch information
mdelillo authored and TisVictress committed Nov 13, 2018
1 parent 7fbf154 commit bfbb05b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
20 changes: 1 addition & 19 deletions credhub/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"

"code.cloudfoundry.org/credhub-cli/credhub/permissions"
"github.com/hashicorp/go-version"
)

type permissionsResponse struct {
Expand Down Expand Up @@ -85,7 +84,7 @@ func (ch *CredHub) addV2Permission(path string, actor string, ops []string) (*ht
}

func (ch *CredHub) AddPermission(path string, actor string, ops []string) (*permissions.Permission, error) {
serverVersion, err := ch.getServerVersion()
serverVersion, err := ch.ServerVersion()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -117,20 +116,3 @@ func (ch *CredHub) AddPermission(path string, actor string, ops []string) (*perm

return &response, nil
}

func (ch *CredHub) getServerVersion() (*version.Version, error) {
if ch.cachedServerVersion == "" {
serverVersion, err := ch.ServerVersion()
if err != nil {
return nil, err
}
ch.cachedServerVersion = serverVersion.String()
}

serverVersion, err := version.NewVersion(ch.cachedServerVersion)
if err != nil {
return nil, err
}

return serverVersion, nil
}
3 changes: 3 additions & 0 deletions credhub/server_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func (ch *CredHub) ServerVersion() (*version.Version, error) {
return nil, err
}
}

ch.cachedServerVersion = v

return version.NewVersion(v)
}

Expand Down
11 changes: 1 addition & 10 deletions credhub/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"code.cloudfoundry.org/credhub-cli/credhub/credentials"
"code.cloudfoundry.org/credhub-cli/credhub/credentials/values"
"github.com/hashicorp/go-version"
)

// SetValue sets a value credential with a user-provided value.
Expand Down Expand Up @@ -81,15 +80,7 @@ func (ch *CredHub) setCredential(name, credType string, value interface{}, cred
requestBody["type"] = credType
requestBody["value"] = value

if ch.cachedServerVersion == "" {
serverVersion, err := ch.ServerVersion()
if err != nil {
return err
}
ch.cachedServerVersion = serverVersion.String()
}

serverVersion, err := version.NewVersion(ch.cachedServerVersion)
serverVersion, err := ch.ServerVersion()
if err != nil {
return err
}
Expand Down

0 comments on commit bfbb05b

Please sign in to comment.