Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: improve constructor checks and docs #1185

Merged
merged 3 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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