Skip to content

Commit

Permalink
Merge pull request #1185 from lucab/ups/client-constructor
Browse files Browse the repository at this point in the history
client: improve constructor checks and docs
  • Loading branch information
riyazdf authored Jul 6, 2017
2 parents 7c74907 + be88cdf commit c251b85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type NotaryRepository struct {
// a file cache from the provided repository, local config information and a crypto service.
// It also retrieves the remote store associated to the base directory under where all the
// trust files will be stored and the specified GUN.
//
// In case of a nil RoundTripper, a default offline store is used instead.
func NewFileCachedNotaryRepository(baseDir string, gun data.GUN, baseURL string, rt http.RoundTripper,
retriever notary.PassRetriever, trustPinning trustpinning.TrustPinConfig) (
*NotaryRepository, error) {
Expand Down Expand Up @@ -96,7 +98,8 @@ func NewFileCachedNotaryRepository(baseDir string, gun data.GUN, baseURL string,
// It takes the base directory under where all the trust files will be stored
// (This is normally defaults to "~/.notary" or "~/.docker/trust" when enabling
// docker content trust).
// It expects an initialized remote store and cache.
// It expects an initialized cache. In case of a nil remote store, a default
// offline store is used.
func NewNotaryRepository(baseDir string, gun data.GUN, baseURL string, remoteStore store.RemoteStore, cache store.MetadataStore,
trustPinning trustpinning.TrustPinConfig, cryptoService signed.CryptoService, cl changelist.Changelist) (
*NotaryRepository, error) {
Expand All @@ -106,6 +109,10 @@ func NewNotaryRepository(baseDir string, gun data.GUN, baseURL string, remoteSto
remoteStore = store.OfflineStore{}
}

if cache == nil {
return nil, fmt.Errorf("got an invalid cache (nil metadata store)")
}

nRepo := &NotaryRepository{
gun: gun,
baseURL: baseURL,
Expand Down
4 changes: 3 additions & 1 deletion storage/httpstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ type HTTPStore struct {
roundTrip http.RoundTripper
}

// NewHTTPStore initializes a new store against a URL and a number of configuration options
// NewHTTPStore initializes a new store against a URL and a number of configuration options.
//
// In case of a nil `roundTrip`, a default offline store is used instead.
func NewHTTPStore(baseURL, metaPrefix, metaExtension, keyExtension string, roundTrip http.RoundTripper) (RemoteStore, error) {
base, err := url.Parse(baseURL)
if err != nil {
Expand Down

0 comments on commit c251b85

Please sign in to comment.