Use reference package internally
Most places in the registry were using string types to refer to repository names. This changes them to use reference.Named, so the type system can enforce validation of the naming rules. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
caa2001e1f
commit
4441333912
35 changed files with 323 additions and 246 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/docker/distribution"
|
||||
"github.com/docker/distribution/context"
|
||||
"github.com/docker/distribution/digest"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/distribution/uuid"
|
||||
)
|
||||
|
||||
|
@ -22,8 +23,8 @@ var _ Listener = &bridge{}
|
|||
|
||||
// URLBuilder defines a subset of url builder to be used by the event listener.
|
||||
type URLBuilder interface {
|
||||
BuildManifestURL(name, tag string) (string, error)
|
||||
BuildBlobURL(name string, dgst digest.Digest) (string, error)
|
||||
BuildManifestURL(name reference.Named, tag string) (string, error)
|
||||
BuildBlobURL(name reference.Named, dgst digest.Digest) (string, error)
|
||||
}
|
||||
|
||||
// NewBridge returns a notification listener that writes records to sink,
|
||||
|
@ -52,40 +53,40 @@ func NewRequestRecord(id string, r *http.Request) RequestRecord {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *bridge) ManifestPushed(repo string, sm distribution.Manifest) error {
|
||||
func (b *bridge) ManifestPushed(repo reference.Named, sm distribution.Manifest) error {
|
||||
return b.createManifestEventAndWrite(EventActionPush, repo, sm)
|
||||
}
|
||||
|
||||
func (b *bridge) ManifestPulled(repo string, sm distribution.Manifest) error {
|
||||
func (b *bridge) ManifestPulled(repo reference.Named, sm distribution.Manifest) error {
|
||||
return b.createManifestEventAndWrite(EventActionPull, repo, sm)
|
||||
}
|
||||
|
||||
func (b *bridge) ManifestDeleted(repo string, sm distribution.Manifest) error {
|
||||
func (b *bridge) ManifestDeleted(repo reference.Named, sm distribution.Manifest) error {
|
||||
return b.createManifestEventAndWrite(EventActionDelete, repo, sm)
|
||||
}
|
||||
|
||||
func (b *bridge) BlobPushed(repo string, desc distribution.Descriptor) error {
|
||||
func (b *bridge) BlobPushed(repo reference.Named, desc distribution.Descriptor) error {
|
||||
return b.createBlobEventAndWrite(EventActionPush, repo, desc)
|
||||
}
|
||||
|
||||
func (b *bridge) BlobPulled(repo string, desc distribution.Descriptor) error {
|
||||
func (b *bridge) BlobPulled(repo reference.Named, desc distribution.Descriptor) error {
|
||||
return b.createBlobEventAndWrite(EventActionPull, repo, desc)
|
||||
}
|
||||
|
||||
func (b *bridge) BlobMounted(repo string, desc distribution.Descriptor, fromRepo string) error {
|
||||
func (b *bridge) BlobMounted(repo reference.Named, desc distribution.Descriptor, fromRepo reference.Named) error {
|
||||
event, err := b.createBlobEvent(EventActionMount, repo, desc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
event.Target.FromRepository = fromRepo
|
||||
event.Target.FromRepository = fromRepo.Name()
|
||||
return b.sink.Write(*event)
|
||||
}
|
||||
|
||||
func (b *bridge) BlobDeleted(repo string, desc distribution.Descriptor) error {
|
||||
func (b *bridge) BlobDeleted(repo reference.Named, desc distribution.Descriptor) error {
|
||||
return b.createBlobEventAndWrite(EventActionDelete, repo, desc)
|
||||
}
|
||||
|
||||
func (b *bridge) createManifestEventAndWrite(action string, repo string, sm distribution.Manifest) error {
|
||||
func (b *bridge) createManifestEventAndWrite(action string, repo reference.Named, sm distribution.Manifest) error {
|
||||
manifestEvent, err := b.createManifestEvent(action, repo, sm)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -94,9 +95,9 @@ func (b *bridge) createManifestEventAndWrite(action string, repo string, sm dist
|
|||
return b.sink.Write(*manifestEvent)
|
||||
}
|
||||
|
||||
func (b *bridge) createManifestEvent(action string, repo string, sm distribution.Manifest) (*Event, error) {
|
||||
func (b *bridge) createManifestEvent(action string, repo reference.Named, sm distribution.Manifest) (*Event, error) {
|
||||
event := b.createEvent(action)
|
||||
event.Target.Repository = repo
|
||||
event.Target.Repository = repo.Name()
|
||||
|
||||
mt, p, err := sm.Payload()
|
||||
if err != nil {
|
||||
|
@ -122,7 +123,7 @@ func (b *bridge) createManifestEvent(action string, repo string, sm distribution
|
|||
return event, nil
|
||||
}
|
||||
|
||||
func (b *bridge) createBlobEventAndWrite(action string, repo string, desc distribution.Descriptor) error {
|
||||
func (b *bridge) createBlobEventAndWrite(action string, repo reference.Named, desc distribution.Descriptor) error {
|
||||
event, err := b.createBlobEvent(action, repo, desc)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -131,11 +132,11 @@ func (b *bridge) createBlobEventAndWrite(action string, repo string, desc distri
|
|||
return b.sink.Write(*event)
|
||||
}
|
||||
|
||||
func (b *bridge) createBlobEvent(action string, repo string, desc distribution.Descriptor) (*Event, error) {
|
||||
func (b *bridge) createBlobEvent(action string, repo reference.Named, desc distribution.Descriptor) (*Event, error) {
|
||||
event := b.createEvent(action)
|
||||
event.Target.Descriptor = desc
|
||||
event.Target.Length = desc.Size
|
||||
event.Target.Repository = repo
|
||||
event.Target.Repository = repo.Name()
|
||||
|
||||
var err error
|
||||
event.Target.URL, err = b.ub.BuildBlobURL(repo, desc.Digest)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue