-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (54 loc) · 1.74 KB
/
main.go
File metadata and controls
68 lines (54 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"crypto"
"flag"
"fmt"
"log"
"net/http"
"os"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/gcrane"
"github.com/google/go-containerregistry/pkg/logs"
"github.com/jonjohnsonjr/dagdotdev/internal/explore"
sha256simd "github.com/minio/sha256-simd"
)
var auth = flag.Bool("auth", false, "use docker credentials")
var verbose = flag.Bool("v", false, "verbose logs")
func init() {
crypto.RegisterHash(crypto.SHA256, sha256simd.New)
}
func main() {
flag.Parse()
logs.Trace.SetOutput(os.Stderr)
logs.Trace.SetFlags(log.Lshortfile | log.Ldate | log.Ltime | log.Lmicroseconds)
if *verbose {
logs.Debug.SetOutput(os.Stderr)
logs.Debug.SetFlags(log.Lshortfile | log.Ldate | log.Ltime | log.Lmicroseconds)
}
log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime | log.Lmicroseconds)
userAgent := os.Getenv("USERAGENT")
if userAgent == "" {
log.Print("please oh please set USERAGENT to something useful so registry operators can debug the weird things we do")
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Printf("listening on %s", port)
opt := []explore.Option{explore.WithUserAgent(userAgent)}
kcs := []authn.Keychain{}
if cgid := os.Getenv("CHAINGUARD_IDENTITY"); cgid != "" {
cgauth, err := explore.NewChainguardMultiKeychain(cgid, "https://issuer.enforce.dev", "cgr.dev")
if err != nil {
log.Fatalf("error creating OCI auth keychain: %v", err)
}
kcs = append(kcs, cgauth)
}
if *auth || os.Getenv("AUTH") == "keychain" {
kcs = append(kcs, gcrane.Keychain)
}
if len(kcs) != 0 {
opt = append(opt, explore.WithKeychain(authn.NewMultiKeychain(kcs...)))
}
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), explore.New(opt...)))
}