-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
102 lines (81 loc) · 3.32 KB
/
main.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"log"
"net/http"
"os"
"strings"
"github.com/gorilla/mux"
"github.com/namsral/flag"
"github.com/ayufan/debian-repository/internal/apache_log"
"github.com/ayufan/debian-repository/internal/deb"
"github.com/ayufan/debian-repository/internal/deb_cache"
"github.com/ayufan/debian-repository/internal/deb_key"
"github.com/ayufan/debian-repository/internal/github_client"
)
var signingKey *deb_key.Key
func createRoutes() *mux.Router {
r := mux.NewRouter()
r.HandleFunc("/settings/cache/clear", clearHandler).Methods("GET", "POST")
r.HandleFunc("/", mainHandler).Methods("GET")
r.HandleFunc("/orgs/{owner}", indexHandler).Methods("GET")
r.HandleFunc("/orgs/{owner}/", indexHandler).Methods("GET")
r.HandleFunc("/orgs/{owner}/archive.key", archiveKeyHandler).Methods("GET")
r.HandleFunc("/orgs/{owner}/dists/{suite}/{file:.*}", fileHandler).Methods("GET")
r.HandleFunc("/orgs/{owner}/{component}", distributionIndexHandler).Methods("GET")
r.HandleFunc("/orgs/{owner}/{component}/", distributionIndexHandler).Methods("GET")
r.HandleFunc("/orgs/{owner}/{component}/pool/{repo}/{tag_name}/{file_name}", downloadHandler).Methods("GET", "HEAD")
r.HandleFunc("/orgs/{owner}/{component}/{file:.*}", fileHandler).Methods("GET")
// support dists/
r.HandleFunc("/{owner}/{repo}", indexHandler).Methods("GET")
r.HandleFunc("/{owner}/{repo}/", indexHandler).Methods("GET")
r.HandleFunc("/{owner}/{repo}/archive.key", archiveKeyHandler).Methods("GET")
r.HandleFunc("/{owner}/{repo}/dists/{suite}/{file:.*}", fileHandler).Methods("GET")
r.HandleFunc("/{owner}/{repo}/pool/{tag_name}/{file_name}", downloadHandler).Methods("GET", "HEAD")
r.HandleFunc("/{owner}/{repo}/{component}", distributionIndexHandler).Methods("GET")
r.HandleFunc("/{owner}/{repo}/{component}/", distributionIndexHandler).Methods("GET")
r.HandleFunc("/{owner}/{repo}/{component}/pool/{tag_name}/{file_name}", downloadHandler).Methods("GET", "HEAD")
r.HandleFunc("/{owner}/{repo}/{component}/{file:.*}", fileHandler).Methods("GET")
return r
}
func main() {
var err error
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
flag.Parse()
if *parseDeb != "" {
deb, err := deb.ReadFromFile(*parseDeb)
if err != nil {
log.Fatalln(err)
}
log.Println(string(deb.Control))
return
}
githubAPI = github_client.New(os.Getenv("GITHUB_TOKEN"), *requestCacheExpiration)
packagesCache = deb_cache.New(*packageLruCache)
signingKey, err = deb_key.New(os.Getenv("GPG_KEY"))
if err != nil {
log.Fatalln(err)
}
deb.Suites = strings.Split(*suites, ",")
if len(deb.Suites) == 0 {
log.Println("Allowed suites: none")
} else {
log.Println("Allowed suites:", strings.Join(deb.Suites, ", "))
}
deb.Architectures = strings.Split(*architectures, ",")
if len(deb.Architectures) == 0 {
log.Println("Default architectures: none")
} else {
log.Println("Default architectures:", strings.Join(deb.Architectures, ", "))
}
allowedOwners = strings.Split(os.Getenv("ALLOWED_ORGS"), ",")
if len(allowedOwners) == 0 {
log.Println("Allowed owners: none")
} else {
log.Println("Allowed owners:", strings.Join(allowedOwners, ", "))
}
routes := createRoutes()
loggingHandler := apache_log.NewApacheLoggingHandler(routes, os.Stdout)
http.Handle("/", loggingHandler)
log.Println("Starting web-server on", *httpAddr, "...")
log.Fatal(http.ListenAndServe(*httpAddr, nil))
}