67d09b50be96b91a6a722e16ff6681e9c90ab4c9
[src/xds/xds-server.git] / lib / xdsserver / apiv1.go
1 /*
2  * Copyright (C) 2017-2018 "IoT.bzh"
3  * Author Sebastien Douheret <sebastien@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package xdsserver
19
20 import (
21         "github.com/gin-gonic/gin"
22 )
23
24 // APIService .
25 type APIService struct {
26         *Context
27         apiRouter *gin.RouterGroup
28 }
29
30 // NewAPIV1 creates a new instance of API service
31 func NewAPIV1(ctx *Context) *APIService {
32         s := &APIService{
33                 Context:   ctx,
34                 apiRouter: ctx.WWWServer.router.Group("/api/v1"),
35         }
36
37         s.apiRouter.GET("/version", s.getVersion)
38
39         s.apiRouter.GET("/config", s.getConfig)
40         s.apiRouter.POST("/config", s.setConfig)
41
42         s.apiRouter.GET("/folders", s.getFolders)
43         s.apiRouter.GET("/folders/:id", s.getFolder)
44         s.apiRouter.PUT("/folders/:id", s.updateFolder)
45         s.apiRouter.POST("/folders", s.addFolder)
46         s.apiRouter.POST("/folders/sync/:id", s.syncFolder)
47         s.apiRouter.DELETE("/folders/:id", s.delFolder)
48
49         s.apiRouter.GET("/sdks", s.getSdks)
50         s.apiRouter.GET("/sdks/:id", s.getSdk)
51         s.apiRouter.POST("/sdks", s.installSdk)
52         s.apiRouter.POST("/sdks/abortinstall", s.abortInstallSdk)
53         s.apiRouter.DELETE("/sdks/:id", s.removeSdk)
54
55         s.apiRouter.POST("/make", s.buildMake)
56         s.apiRouter.POST("/make/:id", s.buildMake)
57
58         s.apiRouter.POST("/exec", s.execCmd)
59         s.apiRouter.POST("/exec/:id", s.execCmd)
60         s.apiRouter.POST("/signal", s.execSignalCmd)
61
62         s.apiRouter.GET("/events", s.eventsList)
63         s.apiRouter.POST("/events/register", s.eventsRegister)
64         s.apiRouter.POST("/events/unregister", s.eventsUnRegister)
65
66         return s
67 }