Replies: 5 comments 6 replies
-
Thanks for putting these all together! For the
It will be more flexible to use an |
Beta Was this translation helpful? Give feedback.
-
I think 4 and 5 are functionally overlapped, and one upvote for 5. |
Beta Was this translation helpful? Give feedback.
-
for 1, and 2, I'm just curious that if the original splitted methods might be used independently in the future. And if we always use them together, why did we design those splitted methods initially? |
Beta Was this translation helpful? Give feedback.
-
I would suggest having a |
Beta Was this translation helpful? Give feedback.
-
UpdatesBased on the offline discussions, we will have the following utility methods: 1. Utility method for getting content// or better name
type ResolveFetcher interface {
content.Resolver
content.Fetcher
}
func GetContent(ctx context.Context, target ResolveFetcher, reference string) (ocispec.Descriptor, []byte, error) Usage: ctx := context.Background()
target, err := remote.NewRepository("myregistry.com/myrepo") // or any other targets
checkErr(err)
// TODO: possible auth configuration
// get manifest
desc, data, err := oras.GetContent(ctx, target, "latest")
checkErr(err)
// get blob
desc, data, err = oras.GetContent(ctx, target.Blobs(), "sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9")
checkErr(err) 2. Utility method for putting contentfunc PutContent(ctx context.Context, storage content.Storage, content []byte, mediaType string) (ocispec.Descriptor, error)
func TagContent(ctx context.Context, target Target, content []byte, mediaType string, reference string) (ocispec.Descriptor, error) Usage: ctx := context.Background()
target, err := remote.NewRepository("myregistry.com/myrepo") // or any other targets
checkErr(err)
// TODO: possible auth configuration
// push blob
data := []byte("test blob")
desc, err := oras.PutContent(ctx, target.Blobs(), data, ocispec.MediaTypeImageLayer)
// push and tag manifest
data = []byte("test manifest")
desc, err = oras.TagContent(ctx, target, data, ocispec.MediaTypeImageManifest, "latest")
checkErr(err) 3. Utility method for specifying static credentialfunc StaticCredential(registry string, cred Credential) func(ctx context.Context, reg string) (Credential, error) {
return func(_ context.Context, reg string) (Credential, error) {
if reg == registry {
return cred, nil
}
return EmptyCredential, nil
}
} Usage: ref := "myregistry.com/myrepo"
repo, err := remote.NewRepository(ref)
checkErr(err)
repo.Client = &auth.Client{
Credential: auth.StaticCredential("myregistry.com", auth.Credential{
Username: "username",
Password: "password",
}),
}
|
Beta Was this translation helpful? Give feedback.
-
Related issue: #102
Thoughts on simplified UX
During the
oras-go
V2 iteration, we have received several feedbacks from some developer users about the usability of the library. For instance:A typical usage is like below:
This function is unsafe because it will always return the same credential for any registries.
To resolve these pain points and make
oras-go
handier, we can consider adding the following utility methods:1. Utility method for getting content
We may combine
Resolve
,Fetch
, reading and verifying into a single method.The API may look like:
The usage may look like:
2. Utility method for putting content
We may combine descriptor generation,
Push
andTag
into a single method.The API may look like:
The usage may look like:
We can have another method or we can leverage the same method for pushing blobs without tagging it, depending on the implementation.
3. Utility method for specifying static credentials
Currently, in order to perform basic auth, users need to provide the client.Credential method like this (See BasicAuth example):
We may simplify this experience by providing some straightforward methods like:
The usage may look like:
4. Utility methods for converting descriptor
We may consider exposing the internal ArtifactToOCI and OCIToArtifact methods as they are simple and commonly-used.
5. Utility methods for generating basic descriptors
We may also consider providing some utility methods for generating basic descriptors, for example:
The usage may look like:
Please leave a comment if you have any thoughts, thanks!
Beta Was this translation helpful? Give feedback.
All reactions