...
1 package services
2
3 import (
4 "net/http"
5
6 "github.com/gin-gonic/gin"
7
8 "edge-infra.dev/pkg/edge/device-registrar/config"
9 )
10
11
12
13
14
15
16
17
18
19 func BootstrapDevice(c *gin.Context) {
20 k8sClient, ctx, cancel := config.GetClientandContext(c)
21 defer cancel()
22
23
24 device, err := retrieveDeviceRegistration(ctx, k8sClient, c)
25 if err == errActivationCodeNotFound {
26 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
27 return
28 } else if err != nil {
29 c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
30 return
31 }
32
33
34 err = bootstrap(ctx, k8sClient, c, device)
35 if err != nil {
36 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
37 return
38 }
39 }
40
View as plain text