1
0
Fork 0
mirror of https://github.com/imjasonh/kontain.me synced 2026-07-18 23:03:06 +00:00

add cmd/mirror, revert cmd/api changes

This commit is contained in:
Jason Hall 2020-09-16 21:48:15 -04:00
parent 57955884c2
commit 340ca89f5a
9 changed files with 256 additions and 31 deletions

View file

@ -4,6 +4,8 @@ import (
"encoding/json"
"errors"
"net/http"
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
)
var (
@ -14,6 +16,11 @@ var (
func Error(w http.ResponseWriter, err error) {
code := "INTERNAL_ERROR"
httpCode := http.StatusInternalServerError
if terr, ok := err.(*transport.Error); ok {
http.Error(w, "", terr.StatusCode)
json.NewEncoder(w).Encode(terr.Errors)
return
}
if err == ErrNotFound {
code = "MANIFEST_UNKNOWN"

View file

@ -21,6 +21,16 @@ func Blob(w http.ResponseWriter, r *http.Request, digest string) {
http.Redirect(w, r, url, http.StatusSeeOther)
}
func BlobExists(h v1.Hash) error {
ctx := context.Background() // TODO
client, err := storage.NewClient(ctx)
if err != nil {
return fmt.Errorf("NewClient: %v", err)
}
_, err = client.Bucket(bucket).Object(fmt.Sprintf("blobs/%s", h)).Attrs(ctx)
return err
}
func writeBlob(h v1.Hash, rc io.ReadCloser, contentType string) error {
ctx := context.Background() // TODO
client, err := storage.NewClient(ctx)
@ -56,7 +66,7 @@ func writeBlob(h v1.Hash, rc io.ReadCloser, contentType string) error {
return nil
}
// ServeManifest writes config and layer blobs for the image, then serves the
// Manifest writes config and layer blobs for the image, then serves the
// manifest contents pointing to those blobs.
func Manifest(w http.ResponseWriter, r *http.Request, img v1.Image) {
// Write config blob for later serving.