Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

feat: implement StoreWithFallbacks #46

Merged
merged 8 commits into from
Apr 20, 2023
Merged

feat: implement StoreWithFallbacks #46

merged 8 commits into from
Apr 20, 2023

Conversation

wangxiaoxuan273
Copy link
Collaborator

Resolves #35

Signed-off-by: wangxiaoxuan273 <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Apr 17, 2023

Codecov Report

Merging #46 (3678f50) into main (87a3ee4) will decrease coverage by 0.65%.
The diff coverage is 71.42%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main      #46      +/-   ##
==========================================
- Coverage   78.32%   77.67%   -0.65%     
==========================================
  Files           3        4       +1     
  Lines         203      224      +21     
==========================================
+ Hits          159      174      +15     
- Misses         33       37       +4     
- Partials       11       13       +2     
Impacted Files Coverage Δ
store.go 71.42% <71.42%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: wangxiaoxuan273 <[email protected]>
store_with_fallbacks.go Outdated Show resolved Hide resolved
store_with_fallbacks_test.go Outdated Show resolved Hide resolved
store_with_fallbacks_test.go Outdated Show resolved Hide resolved
Signed-off-by: wangxiaoxuan273 <[email protected]>
Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need better documentations for the behaviors.


// NewStoreWithFallbacks returns a new store based on the given stores.
// The second and the subsequent stores will be used as fallbacks for the first store.
func NewStoreWithFallbacks(store Store, fallbacks ...Store) Store {
Copy link
Member

@Wwwsylvia Wwwsylvia Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still struggling between

NewStoreWithFallbacks(store Store, fallbacks ...Store) Store

and

NewStoreWithFallbacks(stores ...Store) Store

Later we will have a docker store which is based on the docker configuration file at the default location. I'm wondering how we should use it together with StoreWithFallbacks.

If we go for option 1, the experience would be:

ns := NewNativeStore()
store := NewStoreWithFallbacks(ns, NewStoreFromDocker())

or

dockerStore := NewStoreFromDocker()
store := NewStoreWithFallbacks(dockerStore)

If we go for option 2, we should have the docker store to be the default store when no store is passed.
So

dockerStore := NewStoreFromDocker()
store := NewStoreWithFallbacks(dockerStore)

is equivalent to

store := NewStoreWithFallbacks()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I still prefer option 1.

@wangxiaoxuan273
Copy link
Collaborator Author

We may need better documentations for the behaviors.

Good advice. Added more detailed documentations for Get, Store and Delete.

Signed-off-by: wangxiaoxuan273 <[email protected]>
}

// NewStoreWithFallbacks returns a new store based on the given stores.
// The first store in the array is used as the primary store. The second
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first store in the array is used as the primary store

This looks a bit strange as this function does not accept an array of stores for the primary store.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the description about the array.

}

// Get retrieves credentials from the StoreWithFallbacks for the given server.
// It searches the array of stores for the credentials of serverAddress
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array of stores is invisible to users.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the description about the array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put everything in store.go instead of having a new file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved.

Comment on lines 24 to 27
// StoreWithFallbacks is a store that has multiple fallback stores.
// Please use the NewStoreWithFallbacks to create new instances of
// StoreWithFallbacks.
type StoreWithFallbacks struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to export this struct? Can we make it private?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it private.

Comment on lines 34 to 38
func NewStoreWithFallbacks(store Store, fallbacks ...Store) Store {
return &StoreWithFallbacks{
stores: append([]Store{store}, fallbacks...),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If len(fallbacks) == 0, should we just return store?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it.

Signed-off-by: wangxiaoxuan273 <[email protected]>
Signed-off-by: wangxiaoxuan273 <[email protected]>
store.go Outdated
Comment on lines 35 to 36
// Please use the NewStoreWithFallbacks to create new instances of
// storeWithFallbacks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

store.go Outdated
// The first store is used as the primary store. The second and the
// subsequent stores will be used as fallbacks for the first store.
func NewStoreWithFallbacks(store Store, fallbacks ...Store) Store {
if fallbacks == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if fallbacks == nil {
if len(fallbacks) == 0 {

fallbacks can be not-nil but empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

Comment on lines +54 to +55
// It searches the primary and the fallback stores for the credentials of serverAddress
// and returns when it finds the credentials in any of the stores.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if users can see these comments. We may need to move them to NewStoreWithFallbacks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved.

}

// Put saves credentials into the StoreWithFallbacks. It puts
// the credentials into the primary store.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved.

Signed-off-by: wangxiaoxuan273 <[email protected]>
Signed-off-by: wangxiaoxuan273 <[email protected]>
Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shizhMSFT shizhMSFT merged commit e6ef977 into oras-project:main Apr 20, 2023
@wangxiaoxuan273 wangxiaoxuan273 deleted the fallback branch April 20, 2023 09:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support creating store with fallbacks
4 participants