mirror of
https://github.com/SigNoz/signoz.git
synced 2026-03-09 23:12:20 +00:00
### 📄 Summary - Expose Zeus PutProfile, PutHost and GetHost APIs as first-class OpenAPI-spec endpoints, replacing the previous proxy-based approach - Introduce typed request structs (PostableProfile, PostableHost) instead of raw []byte for type safety and OpenAPI documentation - Wire Zeus handler through the standard dependency chain: handler interface, handler implementation, Handlers struct, signozapiserver provider #### Changes - PUT /api/v2/zeus/profiles - saves deployment profile to Zeus - PUT /api/v2/zeus/hosts - saves deployment host to Zeus - GET /api/v2/zeus/hosts - gets the deployment host from Zeus - All the above new APIs need Admin access Also: - httpzeus provider — marshaling now happens in the provider; upstream error messages are passed through instead of being swallowed; fixes wrong upstream path (/hosts → /host); adds 409 Conflict mapping; replaces errors.Newf with errors.New #### Issues closed by this PR Closes https://github.com/SigNoz/platform-pod/issues/1722
115 lines
2.4 KiB
Go
115 lines
2.4 KiB
Go
package zeus
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/SigNoz/signoz/pkg/errors"
|
|
"github.com/SigNoz/signoz/pkg/http/binding"
|
|
"github.com/SigNoz/signoz/pkg/http/render"
|
|
"github.com/SigNoz/signoz/pkg/licensing"
|
|
"github.com/SigNoz/signoz/pkg/types/authtypes"
|
|
"github.com/SigNoz/signoz/pkg/types/zeustypes"
|
|
"github.com/SigNoz/signoz/pkg/valuer"
|
|
)
|
|
|
|
type handler struct {
|
|
zeus Zeus
|
|
licensing licensing.Licensing
|
|
}
|
|
|
|
func NewHandler(zeus Zeus, licensing licensing.Licensing) Handler {
|
|
return &handler{
|
|
zeus: zeus,
|
|
licensing: licensing,
|
|
}
|
|
}
|
|
|
|
func (h *handler) PutProfile(rw http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
claims, err := authtypes.ClaimsFromContext(ctx)
|
|
if err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
license, err := h.licensing.GetActive(ctx, valuer.MustNewUUID(claims.OrgID))
|
|
if err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
req := new(zeustypes.PostableProfile)
|
|
if err := binding.JSON.BindBody(r.Body, req); err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
if err := h.zeus.PutProfile(ctx, license.Key, req); err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
render.Success(rw, http.StatusNoContent, nil)
|
|
}
|
|
|
|
func (h *handler) GetHosts(rw http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
claims, err := authtypes.ClaimsFromContext(ctx)
|
|
if err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
license, err := h.licensing.GetActive(ctx, valuer.MustNewUUID(claims.OrgID))
|
|
if err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
deploymentBytes, err := h.zeus.GetDeployment(ctx, license.Key)
|
|
if err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
response := zeustypes.NewGettableHost(deploymentBytes)
|
|
|
|
render.Success(rw, http.StatusOK, response)
|
|
}
|
|
|
|
func (h *handler) PutHost(rw http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
claims, err := authtypes.ClaimsFromContext(ctx)
|
|
if err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
license, err := h.licensing.GetActive(ctx, valuer.MustNewUUID(claims.OrgID))
|
|
if err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
req := new(zeustypes.PostableHost)
|
|
if err := binding.JSON.BindBody(r.Body, req); err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
if req.Name == "" {
|
|
render.Error(rw, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "name is required"))
|
|
return
|
|
}
|
|
|
|
if err := h.zeus.PutHost(ctx, license.Key, req); err != nil {
|
|
render.Error(rw, err)
|
|
return
|
|
}
|
|
|
|
render.Success(rw, http.StatusNoContent, nil)
|
|
}
|