2 * Copyright (C) 2017-2018 "IoT.bzh"
3 * Author Sebastien Douheret <sebastien@iot.bzh>
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
24 "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
25 "github.com/gin-gonic/gin"
28 // getSdks returns all SDKs configuration
29 func (s *APIService) getSdks(c *gin.Context) {
30 c.JSON(http.StatusOK, s.sdks.GetAll())
33 // getSdk returns a specific Sdk configuration
34 func (s *APIService) getSdk(c *gin.Context) {
35 id, err := s.sdks.ResolveID(c.Param("id"))
37 common.APIError(c, err.Error())
41 if sdk.Profile == "" {
42 common.APIError(c, "Invalid id")
46 c.JSON(http.StatusOK, sdk)
49 // installSdk Install a new Sdk
50 func (s *APIService) installSdk(c *gin.Context) {
51 var args xsapiv1.SDKInstallArgs
53 if err := c.BindJSON(&args); err != nil {
54 common.APIError(c, "Invalid arguments")
57 id, err := s.sdks.ResolveID(args.ID)
59 common.APIError(c, err.Error())
63 // Support install from ID->URL or from local file
65 s.Log.Debugf("Installing SDK id %s (force %v)", id, args.Force)
66 } else if args.Filename != "" {
67 s.Log.Debugf("Installing SDK filename %s (force %v)", args.Filename, args.Force)
70 // Retrieve session info
71 sess := s.sessions.Get(c)
73 common.APIError(c, "Unknown sessions")
80 sdk, err := s.sdks.Install(id, args.Filename, args.Force, args.Timeout, args.InstallArgs, sess)
85 common.APIError(c, err.Error())
89 c.JSON(http.StatusOK, sdk)
92 // abortInstallSdk Abort a SDK installation
93 func (s *APIService) abortInstallSdk(c *gin.Context) {
94 var args xsapiv1.SDKInstallArgs
96 if err := c.BindJSON(&args); err != nil {
97 common.APIError(c, "Invalid arguments")
100 id, err := s.sdks.ResolveID(args.ID)
102 common.APIError(c, err.Error())
106 sdk, err := s.sdks.AbortInstall(id, args.Timeout)
108 common.APIError(c, err.Error())
112 c.JSON(http.StatusOK, sdk)
118 // removeSdk Uninstall a Sdk
119 func (s *APIService) removeSdk(c *gin.Context) {
120 id, err := s.sdks.ResolveID(c.Param("id"))
122 common.APIError(c, err.Error())
126 // Retrieve session info
127 sess := s.sessions.Get(c)
129 common.APIError(c, "Unknown sessions")
133 s.Log.Debugln("Remove SDK id ", id)
135 delEntry, err := s.sdks.Remove(id, -1, sess)
137 common.APIError(c, err.Error())
140 c.JSON(http.StatusOK, delEntry)