casaos_api.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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/http"
  11. "net/url"
  12. "path"
  13. "strings"
  14. "github.com/deepmap/oapi-codegen/pkg/runtime"
  15. "github.com/getkin/kin-openapi/openapi3"
  16. "github.com/labstack/echo/v4"
  17. )
  18. const (
  19. Access_tokenScopes = "access_token.Scopes"
  20. )
  21. // Defines values for SetZerotierNetworkStatusJSONBodyStatus.
  22. const (
  23. Offline SetZerotierNetworkStatusJSONBodyStatus = "offline"
  24. Online SetZerotierNetworkStatusJSONBodyStatus = "online"
  25. )
  26. // BaseResponse defines model for BaseResponse.
  27. type BaseResponse struct {
  28. // Message message returned by server side if there is any
  29. Message *string `json:"message,omitempty"`
  30. }
  31. // HealthPorts defines model for HealthPorts.
  32. type HealthPorts struct {
  33. TCP *[]int `json:"tcp,omitempty"`
  34. UDP *[]int `json:"udp,omitempty"`
  35. }
  36. // HealthServices defines model for HealthServices.
  37. type HealthServices struct {
  38. NotRunning *[]string `json:"not_running,omitempty"`
  39. Running *[]string `json:"running,omitempty"`
  40. }
  41. // ZTInfo defines model for ZTInfo.
  42. type ZTInfo struct {
  43. Id *string `json:"id,omitempty"`
  44. Name *string `json:"name,omitempty"`
  45. Status *string `json:"status,omitempty"`
  46. }
  47. // GetHealthPortsOK defines model for GetHealthPortsOK.
  48. type GetHealthPortsOK struct {
  49. Data *HealthPorts `json:"data,omitempty"`
  50. // Message message returned by server side if there is any
  51. Message *string `json:"message,omitempty"`
  52. }
  53. // GetHealthServicesOK defines model for GetHealthServicesOK.
  54. type GetHealthServicesOK struct {
  55. Data *HealthServices `json:"data,omitempty"`
  56. // Message message returned by server side if there is any
  57. Message *string `json:"message,omitempty"`
  58. }
  59. // GetZTInfoOK defines model for GetZTInfoOK.
  60. type GetZTInfoOK = ZTInfo
  61. // ResponseInternalServerError defines model for ResponseInternalServerError.
  62. type ResponseInternalServerError = BaseResponse
  63. // ResponseOK defines model for ResponseOK.
  64. type ResponseOK = BaseResponse
  65. // SetZerotierNetworkStatusJSONBody defines parameters for SetZerotierNetworkStatus.
  66. type SetZerotierNetworkStatusJSONBody struct {
  67. Status *SetZerotierNetworkStatusJSONBodyStatus `json:"status,omitempty"`
  68. }
  69. // SetZerotierNetworkStatusJSONBodyStatus defines parameters for SetZerotierNetworkStatus.
  70. type SetZerotierNetworkStatusJSONBodyStatus string
  71. // SetZerotierNetworkStatusJSONRequestBody defines body for SetZerotierNetworkStatus for application/json ContentType.
  72. type SetZerotierNetworkStatusJSONRequestBody SetZerotierNetworkStatusJSONBody
  73. // ServerInterface represents all server handlers.
  74. type ServerInterface interface {
  75. // Test file methods
  76. // (GET /file/test)
  77. GetFileTest(ctx echo.Context) error
  78. // Get log
  79. // (GET /health/logs)
  80. GetHealthlogs(ctx echo.Context) error
  81. // Get port in use
  82. // (GET /health/ports)
  83. GetHealthPorts(ctx echo.Context) error
  84. // Get service status
  85. // (GET /health/services)
  86. GetHealthServices(ctx echo.Context) error
  87. // Get Zerotier info
  88. // (GET /zt/info)
  89. GetZerotierInfo(ctx echo.Context) error
  90. // Set Zerotier network status
  91. // (PUT /zt/{network_id}/status)
  92. SetZerotierNetworkStatus(ctx echo.Context, networkId string) error
  93. }
  94. // ServerInterfaceWrapper converts echo contexts to parameters.
  95. type ServerInterfaceWrapper struct {
  96. Handler ServerInterface
  97. }
  98. // GetFileTest converts echo context to params.
  99. func (w *ServerInterfaceWrapper) GetFileTest(ctx echo.Context) error {
  100. var err error
  101. ctx.Set(Access_tokenScopes, []string{""})
  102. // Invoke the callback with all the unmarshalled arguments
  103. err = w.Handler.GetFileTest(ctx)
  104. return err
  105. }
  106. // GetHealthlogs converts echo context to params.
  107. func (w *ServerInterfaceWrapper) GetHealthlogs(ctx echo.Context) error {
  108. var err error
  109. ctx.Set(Access_tokenScopes, []string{""})
  110. // Invoke the callback with all the unmarshalled arguments
  111. err = w.Handler.GetHealthlogs(ctx)
  112. return err
  113. }
  114. // GetHealthPorts converts echo context to params.
  115. func (w *ServerInterfaceWrapper) GetHealthPorts(ctx echo.Context) error {
  116. var err error
  117. ctx.Set(Access_tokenScopes, []string{""})
  118. // Invoke the callback with all the unmarshalled arguments
  119. err = w.Handler.GetHealthPorts(ctx)
  120. return err
  121. }
  122. // GetHealthServices converts echo context to params.
  123. func (w *ServerInterfaceWrapper) GetHealthServices(ctx echo.Context) error {
  124. var err error
  125. ctx.Set(Access_tokenScopes, []string{""})
  126. // Invoke the callback with all the unmarshalled arguments
  127. err = w.Handler.GetHealthServices(ctx)
  128. return err
  129. }
  130. // GetZerotierInfo converts echo context to params.
  131. func (w *ServerInterfaceWrapper) GetZerotierInfo(ctx echo.Context) error {
  132. var err error
  133. ctx.Set(Access_tokenScopes, []string{""})
  134. // Invoke the callback with all the unmarshalled arguments
  135. err = w.Handler.GetZerotierInfo(ctx)
  136. return err
  137. }
  138. // SetZerotierNetworkStatus converts echo context to params.
  139. func (w *ServerInterfaceWrapper) SetZerotierNetworkStatus(ctx echo.Context) error {
  140. var err error
  141. // ------------- Path parameter "network_id" -------------
  142. var networkId string
  143. err = runtime.BindStyledParameterWithLocation("simple", false, "network_id", runtime.ParamLocationPath, ctx.Param("network_id"), &networkId)
  144. if err != nil {
  145. return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter network_id: %s", err))
  146. }
  147. ctx.Set(Access_tokenScopes, []string{""})
  148. // Invoke the callback with all the unmarshalled arguments
  149. err = w.Handler.SetZerotierNetworkStatus(ctx, networkId)
  150. return err
  151. }
  152. // This is a simple interface which specifies echo.Route addition functions which
  153. // are present on both echo.Echo and echo.Group, since we want to allow using
  154. // either of them for path registration
  155. type EchoRouter interface {
  156. CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  157. DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  158. GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  159. HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  160. OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  161. PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  162. POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  163. PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  164. TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  165. }
  166. // RegisterHandlers adds each server route to the EchoRouter.
  167. func RegisterHandlers(router EchoRouter, si ServerInterface) {
  168. RegisterHandlersWithBaseURL(router, si, "")
  169. }
  170. // Registers handlers, and prepends BaseURL to the paths, so that the paths
  171. // can be served under a prefix.
  172. func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
  173. wrapper := ServerInterfaceWrapper{
  174. Handler: si,
  175. }
  176. router.GET(baseURL+"/file/test", wrapper.GetFileTest)
  177. router.GET(baseURL+"/health/logs", wrapper.GetHealthlogs)
  178. router.GET(baseURL+"/health/ports", wrapper.GetHealthPorts)
  179. router.GET(baseURL+"/health/services", wrapper.GetHealthServices)
  180. router.GET(baseURL+"/zt/info", wrapper.GetZerotierInfo)
  181. router.PUT(baseURL+"/zt/:network_id/status", wrapper.SetZerotierNetworkStatus)
  182. }
  183. // Base64 encoded, gzipped, json marshaled Swagger object
  184. var swaggerSpec = []string{
  185. "H4sIAAAAAAAC/8xX72/bNhD9VwhuH5pBsbxk3ToB/dAfaxoUW4Ilw4bGhktLZ4mNRKp3pyRuoP99oCjb",
  186. "sq386pqhn2xRp7v3Hnnk47WMbVFaA4ZJRtcSgUprCJqHA+C3oHLOji0yHb1zY7E1DIbdX1WWuY4Va2vC",
  187. "j2SNG6M4g0I1b/P8aCajs2v5PcJMRvK7cFUq9HEUvlQEf7Y1ZR1cyxJtCcjaI0gUN8luS9GBKOu6Htd1",
  188. "HcgEKEZdOmwykkfvZB2s6JwAXugYvnFGC5R3knp/emhm9oFkbqvvE8obay7oHRoGNCp3SAF/Q7T41TCs",
  189. "y7iNZFFb+OLCV++A+4p63IXFqVIHbbJmlte+iDbXQAFEKm1erCdqXwgErtBAIqZzQZ4f6QSEngnOAEFo",
  190. "EsrMZSDhShVlDjKSMpAIKjky+VxGjBUEkuele0OM2qQeeLdZtnBxXLofzVA0z8vkz4bLZNowpNAo3Y4o",
  191. "ROWgXO2mdteowo2dvjp2EVVyQ8Kn+w9M+Nfr4y6BZW9scTCWJ1gZ4xj3lpaxImVpQD6F3JJpA0cdyPvk",
  192. "200Vw6Wa3z+vY9N22hYLnazX+HFv/6enP//y7NdhX16vUTf+lSJ1dNIXS6y42mBgTa5ND+IGIkFcoeb5",
  193. "iVvdHp2KYyCasD2Hpou0W7sZqARQLtDIFxVnFvXnpuFWuVWp30HLXrfc15tgVA2H+3GpY64QmgcYGSGE",
  194. "8C/IVhiDKCDR6vlIPikRZoC0G9vc4m7TgxCJROH5zkgKwpiAn49kxlxSFIaoLgep5qyaVgTYbg+D2Bbh",
  195. "YQx/ZyqHU4izMLepDQulTeint/2ZTJUxgBOXfmJ0mvHk2XBYXg1Kk47kl4LNXaJHRMuXuikxmeYV3A5Y",
  196. "F6lQuYPgl5AH9f8j8mjCjVUwMh6VeHF8KEq0FzoBEoWmGPJcGbAViQI4swmJmUWR6NkMEAwLisEo1JYG",
  197. "Lssbi0ITVeC20UQkmuKKSFtDgShzUATiQpNmt9uKswPNb6upQCgtabY4Hz9ZqOGV2KbvYe4Ii+Kj1Uac",
  198. "2QrFa02xxWT1deIHBmkanptPL6bTl1P4Z2cwatpFc6eTHWEZyAtA8k1yseea2ZZgVKllJPcHw8G+DGSp",
  199. "OGt6NJzpHEIGas6+FHi70U6BWLiwhWYD2aTEpmUPExk5d/FGO07EzfnSMYd7w+FN5+YyLuwcxnUgnz7k",
  200. "kz5z0exHVVEonPfhd7KplGR0Jt90h8fuuzBrTg63MqkjyRZff8A0Uf2Mb7AUNmbgXWIEVaxbi5nFQrGM",
  201. "5FQbh7z3YO7zWV9ZrwNgkdu0o5Ln2q9TufAItwvlrcSXrI2t28XjMHY8hDaiIrgnc+qYi97GcWlbTyD8",
  202. "eSrsTICKM/GhdQM/fBBtmt6m2nAx/0m+zm3mcRRsibRU7xLxM4eLc/1G8d4DWtaAwkX2CrSIaOzRF8qz",
  203. "vBc9jixrJDqqLMe3dLk2wJcWzyc6qcOVESurHplOuhXa79oZ2BbsZCXYHz70ZDFXpUJVAANSc3NdL7LI",
  204. "qxMZeBfnzo+Vh1vhbebgU6URksXtYrXBbW5nYx8MxC9tMn/QNWzdBnfMqqkKJ+7SqtrZrPk3Du5jZJcj",
  205. "dvoRYm6t7be2qm6Z8zvWV8enN9O87tDPxm5K/EXSL4MKcxnJ8GKv9WXSBbQFNhfJk9Oj10c7q0Wx0fV1",
  206. "cNcHa2exK3S1yyo9QFuVvl4b9/vWKb61wYzrfwMAAP//9tkexLESAAA=",
  207. }
  208. // GetSwagger returns the content of the embedded swagger specification file
  209. // or error if failed to decode
  210. func decodeSpec() ([]byte, error) {
  211. zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
  212. if err != nil {
  213. return nil, fmt.Errorf("error base64 decoding spec: %s", err)
  214. }
  215. zr, err := gzip.NewReader(bytes.NewReader(zipped))
  216. if err != nil {
  217. return nil, fmt.Errorf("error decompressing spec: %s", err)
  218. }
  219. var buf bytes.Buffer
  220. _, err = buf.ReadFrom(zr)
  221. if err != nil {
  222. return nil, fmt.Errorf("error decompressing spec: %s", err)
  223. }
  224. return buf.Bytes(), nil
  225. }
  226. var rawSpec = decodeSpecCached()
  227. // a naive cached of a decoded swagger spec
  228. func decodeSpecCached() func() ([]byte, error) {
  229. data, err := decodeSpec()
  230. return func() ([]byte, error) {
  231. return data, err
  232. }
  233. }
  234. // Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
  235. func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
  236. var res = make(map[string]func() ([]byte, error))
  237. if len(pathToFile) > 0 {
  238. res[pathToFile] = rawSpec
  239. }
  240. return res
  241. }
  242. // GetSwagger returns the Swagger specification corresponding to the generated code
  243. // in this file. The external references of Swagger specification are resolved.
  244. // The logic of resolving external references is tightly connected to "import-mapping" feature.
  245. // Externally referenced files must be embedded in the corresponding golang packages.
  246. // Urls can be supported but this task was out of the scope.
  247. func GetSwagger() (swagger *openapi3.T, err error) {
  248. var resolvePath = PathToRawSpec("")
  249. loader := openapi3.NewLoader()
  250. loader.IsExternalRefsAllowed = true
  251. loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
  252. var pathToFile = url.String()
  253. pathToFile = path.Clean(pathToFile)
  254. getSpec, ok := resolvePath[pathToFile]
  255. if !ok {
  256. err1 := fmt.Errorf("path not found: %s", pathToFile)
  257. return nil, err1
  258. }
  259. return getSpec()
  260. }
  261. var specData []byte
  262. specData, err = rawSpec()
  263. if err != nil {
  264. return
  265. }
  266. swagger, err = loader.LoadFromData(specData)
  267. if err != nil {
  268. return
  269. }
  270. return
  271. }