constellation/hack/qemu-metadata-api/main.go

44 lines
1.2 KiB
Go
Raw Normal View History

//go:build cgo
/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package main
import (
"flag"
2024-02-08 09:20:01 -05:00
"log/slog"
"os"
2022-09-21 07:47:57 -04:00
"github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/server"
"github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/virtwrapper"
"github.com/edgelesssys/constellation/v2/internal/logger"
"libvirt.org/go/libvirt"
)
func main() {
bindPort := flag.String("port", "8080", "Port to bind to")
targetNetwork := flag.String("network", "constellation-network", "Name of the network in QEMU to use")
libvirtURI := flag.String("libvirt-uri", "qemu:///system", "URI of the libvirt connection")
2022-11-26 13:44:34 -05:00
initSecretHash := flag.String("initsecrethash", "", "brcypt hash of the init secret")
flag.Parse()
2024-02-08 09:20:01 -05:00
log := logger.NewJSONLogger(slog.LevelInfo)
conn, err := libvirt.NewConnect(*libvirtURI)
if err != nil {
2024-02-08 09:20:01 -05:00
log.With(slog.Any("error", err)).Error("Failed to connect to libvirt")
os.Exit(1)
}
defer conn.Close()
2022-11-26 13:44:34 -05:00
serv := server.New(log, *targetNetwork, *initSecretHash, &virtwrapper.Connect{Conn: conn})
if err := serv.ListenAndServe(*bindPort); err != nil {
2024-02-08 09:20:01 -05:00
log.With(slog.Any("error", err)).Error("Failed to serve")
os.Exit(1)
}
}