Files
akvorado/orchestrator/http.go
Vincent Bernat f67d2493b0 orchestrator: allow to register several configuration for a given service
Use the first one by default and if the index is not known. Remove
service registration as this is not used yet.
2022-06-29 15:45:59 +02:00

44 lines
972 B
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package orchestrator
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
)
func (c *Component) configurationHandlerFunc(gc *gin.Context) {
service := gc.Param("service")
indexStr := gc.Param("index")
index, err := strconv.Atoi(indexStr)
if indexStr != "" && err != nil {
gc.JSON(http.StatusNotFound, gin.H{"message": "Invalid configuration index."})
return
}
c.serviceLock.Lock()
var configuration interface{}
serviceConfigurations, ok := c.serviceConfigurations[ServiceType(service)]
if ok {
l := len(serviceConfigurations)
switch {
case l == 0:
ok = false
case index < l:
configuration = serviceConfigurations[index]
default:
configuration = serviceConfigurations[0]
}
}
c.serviceLock.Unlock()
if !ok {
gc.JSON(http.StatusNotFound, gin.H{"message": "Configuration not found."})
return
}
gc.YAML(http.StatusOK, configuration)
}