casaos_api.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. // Package codegen provides primitives to interact with the openapi HTTP API.
  2. //
  3. // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT.
  4. package codegen
  5. import (
  6. "bytes"
  7. "compress/gzip"
  8. "encoding/base64"
  9. "fmt"
  10. "net/url"
  11. "path"
  12. "strings"
  13. "github.com/getkin/kin-openapi/openapi3"
  14. "github.com/labstack/echo/v4"
  15. )
  16. const (
  17. Access_tokenScopes = "access_token.Scopes"
  18. )
  19. // BaseResponse defines model for BaseResponse.
  20. type BaseResponse struct {
  21. // Message message returned by server side if there is any
  22. Message *string `json:"message,omitempty"`
  23. }
  24. // HealthPorts defines model for HealthPorts.
  25. type HealthPorts struct {
  26. TCP *[]int `json:"tcp,omitempty"`
  27. UDP *[]int `json:"udp,omitempty"`
  28. }
  29. // HealthServices defines model for HealthServices.
  30. type HealthServices struct {
  31. NotRunning *[]string `json:"not_running,omitempty"`
  32. Running *[]string `json:"running,omitempty"`
  33. }
  34. // GetHealthPortsOK defines model for GetHealthPortsOK.
  35. type GetHealthPortsOK struct {
  36. Data *HealthPorts `json:"data,omitempty"`
  37. // Message message returned by server side if there is any
  38. Message *string `json:"message,omitempty"`
  39. }
  40. // GetHealthServicesOK defines model for GetHealthServicesOK.
  41. type GetHealthServicesOK struct {
  42. Data *HealthServices `json:"data,omitempty"`
  43. // Message message returned by server side if there is any
  44. Message *string `json:"message,omitempty"`
  45. }
  46. // ResponseInternalServerError defines model for ResponseInternalServerError.
  47. type ResponseInternalServerError = BaseResponse
  48. // ResponseOK defines model for ResponseOK.
  49. type ResponseOK = BaseResponse
  50. // ServerInterface represents all server handlers.
  51. type ServerInterface interface {
  52. // Test file methods
  53. // (GET /file/test)
  54. GetFileTest(ctx echo.Context) error
  55. // Get log
  56. // (GET /health/logs)
  57. GetHealthlogs(ctx echo.Context) error
  58. // Get port in use
  59. // (GET /health/ports)
  60. GetHealthPorts(ctx echo.Context) error
  61. // Get service status
  62. // (GET /health/services)
  63. GetHealthServices(ctx echo.Context) error
  64. }
  65. // ServerInterfaceWrapper converts echo contexts to parameters.
  66. type ServerInterfaceWrapper struct {
  67. Handler ServerInterface
  68. }
  69. // GetFileTest converts echo context to params.
  70. func (w *ServerInterfaceWrapper) GetFileTest(ctx echo.Context) error {
  71. var err error
  72. ctx.Set(Access_tokenScopes, []string{""})
  73. // Invoke the callback with all the unmarshalled arguments
  74. err = w.Handler.GetFileTest(ctx)
  75. return err
  76. }
  77. // GetHealthlogs converts echo context to params.
  78. func (w *ServerInterfaceWrapper) GetHealthlogs(ctx echo.Context) error {
  79. var err error
  80. ctx.Set(Access_tokenScopes, []string{""})
  81. // Invoke the callback with all the unmarshalled arguments
  82. err = w.Handler.GetHealthlogs(ctx)
  83. return err
  84. }
  85. // GetHealthPorts converts echo context to params.
  86. func (w *ServerInterfaceWrapper) GetHealthPorts(ctx echo.Context) error {
  87. var err error
  88. ctx.Set(Access_tokenScopes, []string{""})
  89. // Invoke the callback with all the unmarshalled arguments
  90. err = w.Handler.GetHealthPorts(ctx)
  91. return err
  92. }
  93. // GetHealthServices converts echo context to params.
  94. func (w *ServerInterfaceWrapper) GetHealthServices(ctx echo.Context) error {
  95. var err error
  96. ctx.Set(Access_tokenScopes, []string{""})
  97. // Invoke the callback with all the unmarshalled arguments
  98. err = w.Handler.GetHealthServices(ctx)
  99. return err
  100. }
  101. // This is a simple interface which specifies echo.Route addition functions which
  102. // are present on both echo.Echo and echo.Group, since we want to allow using
  103. // either of them for path registration
  104. type EchoRouter interface {
  105. CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  106. DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  107. GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  108. HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  109. OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  110. PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  111. POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  112. PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  113. TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  114. }
  115. // RegisterHandlers adds each server route to the EchoRouter.
  116. func RegisterHandlers(router EchoRouter, si ServerInterface) {
  117. RegisterHandlersWithBaseURL(router, si, "")
  118. }
  119. // Registers handlers, and prepends BaseURL to the paths, so that the paths
  120. // can be served under a prefix.
  121. func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
  122. wrapper := ServerInterfaceWrapper{
  123. Handler: si,
  124. }
  125. router.GET(baseURL+"/file/test", wrapper.GetFileTest)
  126. router.GET(baseURL+"/health/logs", wrapper.GetHealthlogs)
  127. router.GET(baseURL+"/health/ports", wrapper.GetHealthPorts)
  128. router.GET(baseURL+"/health/services", wrapper.GetHealthServices)
  129. }
  130. // Base64 encoded, gzipped, json marshaled Swagger object
  131. var swaggerSpec = []string{
  132. "H4sIAAAAAAAC/8xX3W7bRhN9lcV+30VcUKIQI0BAIBf5aRwjKGQ0LlrAMpTVckRuQu5uZ4aKVYPvXuyS",
  133. "smhJEeykKXola3/OnHM8szO6ldrV3lmwTDK7lQjknSWIX86A34GquLxwyDR9H9a0swyWw5/K+8poxcbZ",
  134. "9BM5G9ZIl1CruFtV06XMrm7l/xGWMpP/S7eh0u4cpa8Uwa99TNkmt9Kj84BsOga54gh2DGJAUbZte922",
  135. "bSJzII3GB24yk9P3sk22cj4AroyG/7iiDcvjojahzi0DWlWFW4A/Izp8lLiHS9pnsoktuuCiiz4g90ij",
  136. "v4dLcKVNerDo+L0b2e7/owYiVcSN+0D9hkDgBi3kYrEW1Okjk4MwS8ElIAhDQtm1TCTcqNpXIDMpE4mg",
  137. "8qmt1jJjbCCRvPZhhxiNLTriw8Td48Xahw/DUMfvd+DPJ3dgxjIUEJ3uVxSiClRuRoUbWVWHtcvXF+FE",
  138. "k38F8NnpIwF/e3MxFHCXp3sarOM5NtYGxQdDS61IORpTByH3bNrh0SbyIXijQjF8UeuH40Y5BLpBw+sP",
  139. "IXc6BUprIJqz+wwxR03IjBJUDigT2fvxsuHSofkrpvM2lvLmPaw7p4xduv0UmzWTyan2RnODEL/AzAoh",
  140. "RLdBrkENoobcqBcz+cQjLAFppF3lcBQzHDKRK/x8MpOCUBPwi5ksmT1laYrqy7gwXDaLhgD74htrV6fn",
  141. "Gn4vVQWXoMu0coVLa2Vs2pnXf8wXylrAeYCfW1OUPH8+mfibsbfFTH4r2SoA/UC2/MXEEPNF1cBxwqYu",
  142. "hKoChdeK1PRDR+rfZ9SxSXeyYGY7VuLlxbnw6FYmBxK1IQ1VpSy4hkQNXLqcxNKhyM1yCQiWBWmwCo2j",
  143. "cUB561AYogbCI5WL3JBuiIyzlAhfgSIQK0OGw1smrs4Mv2sWAsE7Muxwff1k40bnxL78juaJcCg+OWPF",
  144. "lWtQvDGkHebb23m3MC6K9LP98+Vi8WoBf5yMZ7FcDMfa3QqWiVwBUlckq6ehXJ0Hq7yRmTwdT8anMpFe",
  145. "cRlrNF2aClIGip2lAN4vtEsgFuHYxrOxjJAYS/Y8l1kYDt6aoIk4vt6DMejpZPK1rnR3Lh20ujaRzx5z",
  146. "5VDrju9RU9cK14f4B9tUQTK7km+Hy9fhXlrGdzlkJg0s2dPbPd/x1GHFX2nYTjPwiBhB1fcb99JhrVhm",
  147. "cmFsYH6w7R2aYv5hv86AReWKgUud1sM++U0HPm5U16i/JTf25ugfozjoEMaKhuCBymnQug8WToDtO64g",
  148. "VtyQcEsBSpfiY99rf/ooepiDRbUzI3yXfYO5/cc42AvppR41cTAvxJ8E9yeFq+v2OhwIwSjuN1jJTKar",
  149. "p31/kOFAD7/r+pPL6ZvpyXbA2IkeflQcv3DvTQiBbkasijN0je/i9ed+2XtN9oRet38HAAD///s5WXsj",
  150. "DgAA",
  151. }
  152. // GetSwagger returns the content of the embedded swagger specification file
  153. // or error if failed to decode
  154. func decodeSpec() ([]byte, error) {
  155. zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
  156. if err != nil {
  157. return nil, fmt.Errorf("error base64 decoding spec: %s", err)
  158. }
  159. zr, err := gzip.NewReader(bytes.NewReader(zipped))
  160. if err != nil {
  161. return nil, fmt.Errorf("error decompressing spec: %s", err)
  162. }
  163. var buf bytes.Buffer
  164. _, err = buf.ReadFrom(zr)
  165. if err != nil {
  166. return nil, fmt.Errorf("error decompressing spec: %s", err)
  167. }
  168. return buf.Bytes(), nil
  169. }
  170. var rawSpec = decodeSpecCached()
  171. // a naive cached of a decoded swagger spec
  172. func decodeSpecCached() func() ([]byte, error) {
  173. data, err := decodeSpec()
  174. return func() ([]byte, error) {
  175. return data, err
  176. }
  177. }
  178. // Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
  179. func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
  180. var res = make(map[string]func() ([]byte, error))
  181. if len(pathToFile) > 0 {
  182. res[pathToFile] = rawSpec
  183. }
  184. return res
  185. }
  186. // GetSwagger returns the Swagger specification corresponding to the generated code
  187. // in this file. The external references of Swagger specification are resolved.
  188. // The logic of resolving external references is tightly connected to "import-mapping" feature.
  189. // Externally referenced files must be embedded in the corresponding golang packages.
  190. // Urls can be supported but this task was out of the scope.
  191. func GetSwagger() (swagger *openapi3.T, err error) {
  192. var resolvePath = PathToRawSpec("")
  193. loader := openapi3.NewLoader()
  194. loader.IsExternalRefsAllowed = true
  195. loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
  196. var pathToFile = url.String()
  197. pathToFile = path.Clean(pathToFile)
  198. getSpec, ok := resolvePath[pathToFile]
  199. if !ok {
  200. err1 := fmt.Errorf("path not found: %s", pathToFile)
  201. return nil, err1
  202. }
  203. return getSpec()
  204. }
  205. var specData []byte
  206. specData, err = rawSpec()
  207. if err != nil {
  208. return
  209. }
  210. swagger, err = loader.LoadFromData(specData)
  211. if err != nil {
  212. return
  213. }
  214. return
  215. }