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"
24 "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/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")
77 //increment lock xds counter: it will be decremented,
78 //when SDK is installed in file sdk.go in function ExitCB
79 //at line 308 or when install is aborted in following function
80 LockXdsUpdateCounter(s.Context, true)
81 sdk, err := s.sdks.Install(id, args.Filename, args.Force, args.Timeout, args.InstallArgs, sess)
83 LockXdsUpdateCounter(s.Context, false)
84 common.APIError(c, err.Error())
88 c.JSON(http.StatusOK, sdk)
91 // abortInstallSdk Abort a SDK installation
92 func (s *APIService) abortInstallSdk(c *gin.Context) {
93 var args xsapiv1.SDKInstallArgs
95 if err := c.BindJSON(&args); err != nil {
96 common.APIError(c, "Invalid arguments")
99 id, err := s.sdks.ResolveID(args.ID)
101 common.APIError(c, err.Error())
105 sdk, err := s.sdks.AbortInstall(id, args.Timeout)
107 common.APIError(c, err.Error())
111 LockXdsUpdateCounter(s.Context, false)
112 c.JSON(http.StatusOK, sdk)
115 // removeSdk Uninstall a Sdk
116 func (s *APIService) removeSdk(c *gin.Context) {
117 id, err := s.sdks.ResolveID(c.Param("id"))
119 common.APIError(c, err.Error())
123 // Retrieve session info
124 sess := s.sessions.Get(c)
126 common.APIError(c, "Unknown sessions")
130 s.Log.Debugln("Remove SDK id ", id)
132 LockXdsUpdateCounter(s.Context, true)
133 delEntry, err := s.sdks.Remove(id, -1, sess)
135 common.APIError(c, err.Error())
138 LockXdsUpdateCounter(s.Context, false)
139 c.JSON(http.StatusOK, delEntry)