github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/api/handlers/compat/version.go (about) 1 package compat 2 3 import ( 4 "fmt" 5 "net/http" 6 goRuntime "runtime" 7 "time" 8 9 "github.com/containers/podman/v2/libpod" 10 "github.com/containers/podman/v2/libpod/define" 11 "github.com/containers/podman/v2/pkg/api/handlers/utils" 12 "github.com/containers/podman/v2/pkg/domain/entities" 13 docker "github.com/docker/docker/api/types" 14 "github.com/pkg/errors" 15 ) 16 17 func VersionHandler(w http.ResponseWriter, r *http.Request) { 18 // 200 ok 19 // 500 internal 20 runtime := r.Context().Value("runtime").(*libpod.Runtime) 21 22 versionInfo, err := define.GetVersion() 23 if err != nil { 24 utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err) 25 return 26 } 27 28 infoData, err := runtime.Info() 29 if err != nil { 30 utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "failed to obtain system memory info")) 31 return 32 } 33 34 components := []docker.ComponentVersion{{ 35 Name: "Podman Engine", 36 Version: versionInfo.Version, 37 Details: map[string]string{ 38 "APIVersion": utils.APIVersion[utils.LibpodTree][utils.CurrentAPIVersion].String(), 39 "Arch": goRuntime.GOARCH, 40 "BuildTime": time.Unix(versionInfo.Built, 0).Format(time.RFC3339), 41 "Experimental": "true", 42 "GitCommit": versionInfo.GitCommit, 43 "GoVersion": versionInfo.GoVersion, 44 "KernelVersion": infoData.Host.Kernel, 45 "MinAPIVersion": utils.APIVersion[utils.LibpodTree][utils.MinimalAPIVersion].String(), 46 "Os": goRuntime.GOOS, 47 }, 48 }} 49 50 apiVersion := utils.APIVersion[utils.CompatTree][utils.CurrentAPIVersion] 51 minVersion := utils.APIVersion[utils.CompatTree][utils.MinimalAPIVersion] 52 53 utils.WriteResponse(w, http.StatusOK, entities.ComponentVersion{ 54 Version: docker.Version{ 55 Platform: struct { 56 Name string 57 }{ 58 Name: fmt.Sprintf("%s/%s/%s-%s", goRuntime.GOOS, goRuntime.GOARCH, infoData.Host.Distribution.Distribution, infoData.Host.Distribution.Version), 59 }, 60 APIVersion: fmt.Sprintf("%d.%d", apiVersion.Major, apiVersion.Minor), 61 Arch: components[0].Details["Arch"], 62 BuildTime: components[0].Details["BuildTime"], 63 Components: components, 64 Experimental: true, 65 GitCommit: components[0].Details["GitCommit"], 66 GoVersion: components[0].Details["GoVersion"], 67 KernelVersion: components[0].Details["KernelVersion"], 68 MinAPIVersion: fmt.Sprintf("%d.%d", minVersion.Major, minVersion.Minor), 69 Os: components[0].Details["Os"], 70 Version: components[0].Version, 71 }}) 72 }