Skip to content

Commit

Permalink
Review comments #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars committed Jun 2, 2020
1 parent 628251b commit 3ca0df8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion credentials/tls/certprovider/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// materials by handling synchronization between the producer and consumers of
// the key material.
//
// Provider implementations must embed this type into themselves and:
// Provider implementations may choose to embed this type into themselves and:
// - Whenever they have new key material, they should invoke the Set() method.
// - When users of the provider call KeyMaterial(), it will be handled by the
// distributor which will return the most up-to-date key material furnished
Expand All @@ -56,6 +56,9 @@ func NewDistributor() *Distributor {
}

// Set updates the key material in the distributor with km.
//
// Provider implementations which use the distributor must not modify the
// contents of the KeyMaterial struct pointed to by km.
func (d *Distributor) Set(km *KeyMaterial) {
d.mu.Lock()
d.km = km
Expand Down
1 change: 1 addition & 0 deletions credentials/tls/certprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type StableConfig interface {
// instantiations as they deem fit.
type Provider interface {
// KeyMaterial returns the key material sourced by the provider.
// Callers are expected to use the returned value as read-only.
//
// Implementations must honor the deadline specified in ctx.
KeyMaterial(ctx context.Context, opts KeyMaterialOptions) (*KeyMaterial, error)
Expand Down
10 changes: 5 additions & 5 deletions credentials/tls/certprovider/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ func init() {
}
}

// Key contains data which uniquely identifies a provider instance.
type Key struct {
// StoreKey contains data which uniquely identifies a provider instance.
type StoreKey struct {
// Name is the registered name of the provider.
Name string
// Config is the configuration used by the provider instance.
Config StableConfig
}

// storeKey acts the key to the map of providers maintained by the store. Go
// maps need to be indexed by comparable types, so the above Key struct cannot
// be used since it contains an interface.
// maps need to be indexed by comparable types, so the above StoreKey struct
// cannot be used since it contains an interface.
type storeKey struct {
// name of the certificate provider.
name string
Expand Down Expand Up @@ -77,7 +77,7 @@ func GetStore() *Store {
// exists for key, its reference count is incremented before returning. If no
// provider exists for key, a new is created using the registered builder. If
// no registered builder is found, a nil provider is returned.
func (ps *Store) GetProvider(key Key) Provider {
func (ps *Store) GetProvider(key StoreKey) Provider {
ps.mu.Lock()
defer ps.mu.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion credentials/tls/certprovider/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func makeProvider(t *testing.T, name, config string) (Provider, *fakeProvider) {

// Pass the config to the store to fetch a provider.
store := GetStore()
key := Key{Name: name, Config: cfg}
key := StoreKey{Name: name, Config: cfg}
prov := store.GetProvider(key)
if prov == nil {
t.Fatalf("store.Get(%v) is nil", key)
Expand Down

0 comments on commit 3ca0df8

Please sign in to comment.