2023-05-17 11:34:29 -04:00
|
|
|
//go:build cgo
|
|
|
|
|
2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-06-30 05:14:26 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2024-02-08 09:20:01 -05:00
|
|
|
"log/slog"
|
|
|
|
"os"
|
2022-06-30 05:14:26 -04:00
|
|
|
|
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"
|
2022-06-30 05:14:26 -04:00
|
|
|
"libvirt.org/go/libvirt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
bindPort := flag.String("port", "8080", "Port to bind to")
|
2022-09-26 09:52:31 -04:00
|
|
|
targetNetwork := flag.String("network", "constellation-network", "Name of the network in QEMU to use")
|
2022-10-05 03:11:30 -04:00
|
|
|
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")
|
2022-06-30 05:14:26 -04:00
|
|
|
flag.Parse()
|
|
|
|
|
2024-02-08 09:20:01 -05:00
|
|
|
log := logger.NewJSONLogger(slog.LevelInfo)
|
2022-06-30 05:14:26 -04:00
|
|
|
|
2022-10-05 03:11:30 -04:00
|
|
|
conn, err := libvirt.NewConnect(*libvirtURI)
|
2022-06-30 05:14:26 -04:00
|
|
|
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)
|
2022-06-30 05:14:26 -04:00
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
2022-11-26 13:44:34 -05:00
|
|
|
serv := server.New(log, *targetNetwork, *initSecretHash, &virtwrapper.Connect{Conn: conn})
|
2022-06-30 05:14:26 -04:00
|
|
|
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)
|
2022-06-30 05:14:26 -04:00
|
|
|
}
|
|
|
|
}
|