50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package pods
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/containers/podman/v4/pkg/bindings/containers"
|
|
"github.com/containers/podman/v4/pkg/bindings/images"
|
|
"github.com/containers/podman/v4/pkg/specgen"
|
|
|
|
"git.jmbit.de/filegate/filegate/db"
|
|
"git.jmbit.de/filegate/filegate/files"
|
|
)
|
|
|
|
type AnalysisContainer struct {
|
|
UUID string
|
|
containerFile string
|
|
fileID uint
|
|
}
|
|
|
|
// CreateAutoAnalysisContainer creates a Static analysis Container with the file
|
|
// returns the UUID of the container and the path of the file
|
|
func CreateAutoAnalysisContainer(fileID uint) AnalysisContainer {
|
|
image := "git.jmbit.de/filegate/utility-containers:staticanalysis"
|
|
conn := socketConnection()
|
|
_, err := images.Pull(conn, image, nil)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
s := specgen.NewSpecGenerator(image, false)
|
|
createResponse, err := containers.CreateWithSpec(conn, s, nil)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
if err := containers.Start(conn, createResponse.ID, nil); err != nil {
|
|
log.Println(err)
|
|
}
|
|
file := db.GetFileByID(fileID)
|
|
fileObject, err := files.GetFile(file.Blob)
|
|
_, err = containers.CopyFromArchive(conn, createResponse.ID, fmt.Sprintf("/mnt/%s", file.Properties.OriginalName), fileObject)
|
|
if err != nil {
|
|
return AnalysisContainer{}
|
|
}
|
|
return AnalysisContainer{
|
|
UUID: createResponse.ID,
|
|
containerFile: fmt.Sprintf("/mnt/%s", file.Properties.OriginalName),
|
|
fileID: file.ID,
|
|
}
|
|
}
|