...

Source file src/edge-infra.dev/pkg/edge/device-registrar/services/device_bootstrap_service.go

Documentation: edge-infra.dev/pkg/edge/device-registrar/services

     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  // swagger:route GET /bootstrap/{activationCode} legacy bootstrap
    12  // Bootstraps a device
    13  //
    14  // Bootstraps a device and returns the device's external application and device configuration details
    15  // responses:
    16  //
    17  //	200: DeviceConnectResponse Success
    18  //	400: description:Bad Request
    19  func BootstrapDevice(c *gin.Context) {
    20  	k8sClient, ctx, cancel := config.GetClientandContext(c)
    21  	defer cancel()
    22  
    23  	// verify the deviceBinding
    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  	// bootstrap the device
    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