74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package handler
|
|
|
|
import (
|
|
"git.sundynix.cn/Blizzard/Veyra/internal/apperror"
|
|
"git.sundynix.cn/Blizzard/Veyra/internal/service"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
func bindProviders(r *gin.Engine, options IdentityOptions) {
|
|
admin := r.Group("/api/admin/v1", func(c *gin.Context) { authenticate(c, options, "admin") })
|
|
admin.Use(func(c *gin.Context) {
|
|
if options.Providers == nil {
|
|
fail(c, apperror.ErrUnavailable)
|
|
return
|
|
}
|
|
c.Next()
|
|
})
|
|
admin.GET("/providers", func(c *gin.Context) {
|
|
list, err := options.Providers.List(c.Request.Context(), currentUser(c))
|
|
if err != nil {
|
|
fail(c, err)
|
|
return
|
|
}
|
|
success(c, http.StatusOK, list)
|
|
})
|
|
admin.PUT("/providers/:key", func(c *gin.Context) {
|
|
if !sameOrigin(c.Request) {
|
|
fail(c, apperror.ErrForbidden)
|
|
return
|
|
}
|
|
var input service.ProviderInput
|
|
if !decode(c, &input) {
|
|
return
|
|
}
|
|
config, err := options.Providers.Save(c.Request.Context(), currentUser(c), c.Param("key"), c.Writer.Header().Get("X-Request-ID"), input)
|
|
if err != nil {
|
|
fail(c, err)
|
|
return
|
|
}
|
|
success(c, http.StatusOK, config)
|
|
})
|
|
admin.POST("/providers/model_review/copy-primary", func(c *gin.Context) {
|
|
if !sameOrigin(c.Request) {
|
|
fail(c, apperror.ErrForbidden)
|
|
return
|
|
}
|
|
if options.Providers == nil {
|
|
fail(c, apperror.ErrUnavailable)
|
|
return
|
|
}
|
|
var input struct {
|
|
ExpectedVersion int64 `json:"expected_version"`
|
|
}
|
|
if !decode(c, &input) {
|
|
return
|
|
}
|
|
result, err := options.Providers.CopyPrimaryToReview(c.Request.Context(), currentUser(c), c.Writer.Header().Get("X-Request-ID"), input.ExpectedVersion)
|
|
if err != nil {
|
|
fail(c, err)
|
|
return
|
|
}
|
|
success(c, http.StatusOK, result)
|
|
})
|
|
admin.GET("/audit-events", func(c *gin.Context) {
|
|
list, err := options.Providers.Audit(c.Request.Context(), currentUser(c))
|
|
if err != nil {
|
|
fail(c, err)
|
|
return
|
|
}
|
|
success(c, http.StatusOK, list)
|
|
})
|
|
}
|