udistribution
Go library providing a client to interface with storage drivers of distribution/distribution without a listening HTTP server.
Develop in gitpod
Goal:
- Given a config and/or environment variables conforming to available configurations
- a client interface can be initialized to access functions enabling access to methods in distribution api spec without a listening registry HTTP Server by exposing ServeHTTP method.
Making it easier for Go programs to consume APIs on a needed basis without a listening server. This approach maybe more secure in an environment where it is not practical to obtain TLS certificates from a trusted certificate authorities, such as an unpredictable hostname/ip address.
Current functionality:
- Modifies distribution/distribution to
- Initialize client with config string and/or environment variables
- ServeHTTP method can be accessed after initialization
- Implement a function to register new transport type to "github.com/containers/image/v5/transports"
- Consumes distribution/distribution using exposed ServeHTTP method
- End to end test which demonstrates how the transport type is registered and can be used to access distribution/distribution
Getting Started
Usage example as seen in test
ut, err := udistribution.NewTransportFromNewConfig("", os.Environ())
defer ut.Deregister()
if err != nil {
t.Errorf("failed to create transport with environment variables: %v", err)
}
srcRef, err := docker.ParseReference("//alpine")
if err != nil {
t.Errorf("failed to parse reference: %v", err)
}
destRef, err := ut.ParseReference("//alpine")
if err != nil {
t.Errorf("failed to parse reference: %v", err)
}
pc, err := getPolicyContext()
if err != nil {
t.Errorf("failed to get policy context: %v", err)
}
ctx, err := getDefaultContext()
if err != nil {
t.Errorf("failed to get default context: %v", err)
}
_, err = copy.Image(context.Background(), pc, destRef, srcRef, ©.Options{
SourceCtx: ctx,
DestinationCtx: ctx,
})
if err != nil {
t.Errorf("%v", errors.Wrapf(err, "failed to copy image"))
}
First you call NewClient
with a config string and environment variables.
Then you call the client's ServeHTTP
method with a desired HTTP request.
You can use httptest.NewRecorder
to record the response.
Alternatively, you may use alltransports.ParseImageName(ref) when transport name ut.Name()://
is in the reference instead of using ut.ParseReference
Known issues:
Prometheus metrics config must be disabled.
NOTICE:
- This library contains some parts from distribution/distribution which is licensed under the Apache License 2.0.
- Some parts has been modified to accommodate usage in this library.
- A copy of the original distribution/distribution license is included in the repository at LICENSE