From 2d62c61af95ddff32a2c074dad1a64d26f2c17a1 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Thu, 6 Jul 2017 15:42:03 +0000 Subject: [PATCH 1/3] client: check for nil cache in constructor This introduce and explicit nil-check on the metadata store in `NewNotaryRepository()`, to match the docstring and to avoid further panics at runtime. It also clarify the default behavior in case of a nil remote store. Signed-off-by: Luca Bruno --- client/client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 2f799d30d..7cd0f9976 100644 --- a/client/client.go +++ b/client/client.go @@ -96,7 +96,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) { @@ -106,6 +107,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, From b3ce04b9748e644b5888bc4b9befde779fdc344d Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Thu, 6 Jul 2017 15:47:48 +0000 Subject: [PATCH 2/3] storage/http: specify default behavior upon nil Roundtripper Signed-off-by: Luca Bruno --- storage/httpstore.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/storage/httpstore.go b/storage/httpstore.go index 6b6be8f79..f2bb066eb 100644 --- a/storage/httpstore.go +++ b/storage/httpstore.go @@ -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 { From be88cdfb8136cfae16ae89630cc23810f663d62c Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Thu, 6 Jul 2017 15:48:25 +0000 Subject: [PATCH 3/3] client: specify default behavior upon nil Roundtripper Signed-off-by: Luca Bruno --- client/client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/client.go b/client/client.go index 7cd0f9976..8264de512 100644 --- a/client/client.go +++ b/client/client.go @@ -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) {