aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/handlers/libpod/swagger.go
blob: 9450a70d93b084a2d2460272425653e4a2c9cf60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package libpod

import (
	"net/http"
	"os"

	"github.com/containers/image/v5/manifest"
	"github.com/containers/podman/v3/libpod/define"
	"github.com/containers/podman/v3/pkg/api/handlers/utils"
	"github.com/containers/podman/v3/pkg/domain/entities"
	"github.com/pkg/errors"
)

// DefaultPodmanSwaggerSpec provides the default path to the podman swagger spec file
const DefaultPodmanSwaggerSpec = "/usr/share/containers/podman/swagger.yaml"

// List Containers
// swagger:response ListContainers
type swagInspectPodResponse struct {
	// in:body
	Body []entities.ListContainer
}

// Inspect Manifest
// swagger:response InspectManifest
type swagInspectManifestResponse struct {
	// in:body
	Body manifest.Schema2List
}

// Kill Pod
// swagger:response PodKillReport
type swagKillPodResponse struct {
	// in:body
	Body entities.PodKillReport
}

// Pause pod
// swagger:response PodPauseReport
type swagPausePodResponse struct {
	// in:body
	Body entities.PodPauseReport
}

// Unpause pod
// swagger:response PodUnpauseReport
type swagUnpausePodResponse struct {
	// in:body
	Body entities.PodUnpauseReport
}

// Stop pod
// swagger:response PodStopReport
type swagStopPodResponse struct {
	// in:body
	Body entities.PodStopReport
}

// Restart pod
// swagger:response PodRestartReport
type swagRestartPodResponse struct {
	// in:body
	Body entities.PodRestartReport
}

// Start pod
// swagger:response PodStartReport
type swagStartPodResponse struct {
	// in:body
	Body entities.PodStartReport
}

// Prune pod
// swagger:response PodPruneReport
type swagPrunePodResponse struct {
	// in:body
	Body entities.PodPruneReport
}

// Rm pod
// swagger:response PodRmReport
type swagRmPodResponse struct {
	// in:body
	Body entities.PodRmReport
}

// Info
// swagger:response InfoResponse
type swagInfoResponse struct {
	// in:body
	Body define.Info
}

// Network rm
// swagger:response NetworkRmReport
type swagNetworkRmReport struct {
	// in:body
	Body entities.NetworkRmReport
}

// Network inspect
// swagger:response NetworkInspectReport
type swagNetworkInspectReport struct {
	// in:body
	Body entities.NetworkInspectReport
}

// Network list
// swagger:response NetworkListReport
type swagNetworkListReport struct {
	// in:body
	Body []entities.NetworkListReport
}

// Network create
// swagger:response NetworkCreateReport
type swagNetworkCreateReport struct {
	// in:body
	Body entities.NetworkCreateReport
}

func ServeSwagger(w http.ResponseWriter, r *http.Request) {
	path := DefaultPodmanSwaggerSpec
	if p, found := os.LookupEnv("PODMAN_SWAGGER_SPEC"); found {
		path = p
	}
	if _, err := os.Stat(path); err != nil {
		if os.IsNotExist(err) {
			utils.InternalServerError(w, errors.Errorf("file %q does not exist", path))
			return
		}
		utils.InternalServerError(w, err)
		return
	}
	w.Header().Set("Content-Type", "text/yaml")
	http.ServeFile(w, r, path)
}