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.
@@ -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,
