Bump Copyright to 2019
[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         s.apiRouter.GET("/targets", s.getTargets)
67         s.apiRouter.GET("/targets/:id", s.getTarget)
68         s.apiRouter.POST("/targets", s.addTarget)
69         s.apiRouter.DELETE("/targets/:id", s.delTarget)
70         s.apiRouter.GET("/targets/:id/terminals", s.getTgtTerms)
71         s.apiRouter.GET("/targets/:id/terminals/:tid", s.getTgtTerm)
72         s.apiRouter.POST("/targets/:id/terminals", s.createTgtTerm)
73         s.apiRouter.PUT("/targets/:id/terminals/:tid", s.updateTgtTerm)
74         s.apiRouter.DELETE("/targets/:id/terminals/:tid", s.delTgtTerm)
75         s.apiRouter.POST("/targets/:id/terminals/:tid/open", s.openTgtTerm)
76         s.apiRouter.POST("/targets/:id/terminals/:tid/close", s.closeTgtTerm)
77         s.apiRouter.POST("/targets/:id/terminals/:tid/resize", s.resizeTgtTerm)
78         s.apiRouter.POST("/targets/:id/terminals/:tid/signal", s.signalTgtTerm)
79         s.apiRouter.POST("/targets/:id/terminals/:tid/signal/:sig", s.signalTgtTerm)
80
81         s.apiRouter.GET("/updates", s.getXdsSrvUpdate)
82         s.apiRouter.POST("/updates", s.xdsSrvUpdate)
83
84         return s
85 }