blob: dfb23a6f3869574d966c3a2497004449692df43c [file] [log] [blame]
package main
import (
"flag"
"net"
"net/http"
"code.hackerspace.pl/hscloud/go/mirko"
"github.com/golang/glog"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
var (
flagListenPublic = ":8080"
flagObjectEndpoint = "object.ceph-waw3.hswaw.net"
flagObjectAccessKey = ""
flagObjectSecretKey = ""
flagObjectBucket = ""
flagObjectPrefix = "cache/"
)
func main() {
flag.StringVar(&flagListenPublic, "listen_public", flagListenPublic, "Address to listen on for Bazel HTTP caching protocol clients")
flag.StringVar(&flagObjectEndpoint, "object_endpoint", flagObjectEndpoint, "Object Storage endpoint name")
flag.StringVar(&flagObjectAccessKey, "object_access_key", flagObjectEndpoint, "Object Storage AccessKey")
flag.StringVar(&flagObjectSecretKey, "object_secret_key", flagObjectEndpoint, "Object Storage SecretKey")
flag.StringVar(&flagObjectBucket, "object_bucket", flagObjectBucket, "Object Storage bucket name")
flag.StringVar(&flagObjectPrefix, "object_prefix", flagObjectPrefix, "Object Storage prefix for paths")
flag.Parse()
if flagObjectBucket == "" {
glog.Exitf("object_bucket must be set")
}
m := mirko.New()
if err := m.Listen(); err != nil {
glog.Exitf("Listen(): %v", err)
}
minioClient, err := minio.New(flagObjectEndpoint, &minio.Options{
Creds: credentials.NewStaticV4(flagObjectAccessKey, flagObjectSecretKey, ""),
Secure: true,
})
if err != nil {
glog.Exitf("Failed to initialize Object Storage client: %v", err)
}
s := newService(minioClient, flagObjectBucket, flagObjectPrefix)
httpListen, err := net.Listen("tcp", flagListenPublic)
if err != nil {
glog.Exitf("net.Listen: %v", err)
}
httpServer := &http.Server{
Addr: flagListenPublic,
Handler: s.publicHandler,
}
errs := make(chan error, 0)
go func() {
glog.Infof("Public listening on %s", flagListenPublic)
errs <- httpServer.Serve(httpListen)
}()
if err := m.Serve(); err != nil {
glog.Exitf("Serve(): %v", err)
}
select {
case <-m.Done():
case err := <-errs:
glog.Exitf("Serve(): %v", err)
}
}