github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/pkg/api/handlers/libpod/swagger.go (about) 1 package libpod 2 3 import ( 4 "net/http" 5 "os" 6 7 "github.com/containers/image/v5/manifest" 8 "github.com/containers/libpod/libpod/define" 9 "github.com/containers/libpod/pkg/api/handlers/utils" 10 "github.com/containers/libpod/pkg/domain/entities" 11 "github.com/pkg/errors" 12 ) 13 14 // DefaultPodmanSwaggerSpec provides the default path to the podman swagger spec file 15 const DefaultPodmanSwaggerSpec = "/usr/share/containers/podman/swagger.yaml" 16 17 // List Containers 18 // swagger:response ListContainers 19 type swagInspectPodResponse struct { 20 // in:body 21 Body []entities.ListContainer 22 } 23 24 // Inspect Manifest 25 // swagger:response InspectManifest 26 type swagInspectManifestResponse struct { 27 // in:body 28 Body manifest.List 29 } 30 31 // Kill Pod 32 // swagger:response PodKillReport 33 type swagKillPodResponse struct { 34 // in:body 35 Body entities.PodKillReport 36 } 37 38 // Pause pod 39 // swagger:response PodPauseReport 40 type swagPausePodResponse struct { 41 // in:body 42 Body entities.PodPauseReport 43 } 44 45 // Unpause pod 46 // swagger:response PodUnpauseReport 47 type swagUnpausePodResponse struct { 48 // in:body 49 Body entities.PodUnpauseReport 50 } 51 52 // Stop pod 53 // swagger:response PodStopReport 54 type swagStopPodResponse struct { 55 // in:body 56 Body entities.PodStopReport 57 } 58 59 // Restart pod 60 // swagger:response PodRestartReport 61 type swagRestartPodResponse struct { 62 // in:body 63 Body entities.PodRestartReport 64 } 65 66 // Start pod 67 // swagger:response PodStartReport 68 type swagStartPodResponse struct { 69 // in:body 70 Body entities.PodStartReport 71 } 72 73 // Rm pod 74 // swagger:response PodRmReport 75 type swagRmPodResponse struct { 76 // in:body 77 Body entities.PodRmReport 78 } 79 80 // Info 81 // swagger:response InfoResponse 82 type swagInfoResponse struct { 83 // in:body 84 Body define.Info 85 } 86 87 func ServeSwagger(w http.ResponseWriter, r *http.Request) { 88 path := DefaultPodmanSwaggerSpec 89 if p, found := os.LookupEnv("PODMAN_SWAGGER_SPEC"); found { 90 path = p 91 } 92 if _, err := os.Stat(path); err != nil { 93 if os.IsNotExist(err) { 94 utils.InternalServerError(w, errors.Errorf("file %q does not exist", path)) 95 return 96 } 97 utils.InternalServerError(w, err) 98 return 99 } 100 w.Header().Set("Content-Type", "text/yaml") 101 http.ServeFile(w, r, path) 102 }