mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-14 21:30:05 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
810218124e | ||
|
|
5aff256377 |
@@ -37,6 +37,7 @@ func NewRouter(db *gorm.DB, jobs *bg.Jobs, studio http.Handler) http.Handler {
|
|||||||
r.Use(middleware.Recoverer)
|
r.Use(middleware.Recoverer)
|
||||||
r.Use(SecurityHeaders)
|
r.Use(SecurityHeaders)
|
||||||
r.Use(requestBodyLimit(10 << 20))
|
r.Use(requestBodyLimit(10 << 20))
|
||||||
|
r.Use(httprate.LimitByIP(1000, 1*time.Minute))
|
||||||
r.Use(middleware.StripSlashes)
|
r.Use(middleware.StripSlashes)
|
||||||
|
|
||||||
allowed := getAllowedOrigins()
|
allowed := getAllowedOrigins()
|
||||||
|
|||||||
@@ -503,7 +503,6 @@ func ListRecordSets(db *gorm.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GetRecordSet godoc
|
// GetRecordSet godoc
|
||||||
//
|
//
|
||||||
// @ID GetRecordSet
|
// @ID GetRecordSet
|
||||||
@@ -517,35 +516,35 @@ func ListRecordSets(db *gorm.DB) http.HandlerFunc {
|
|||||||
// @Failure 404 {string} string "not found"
|
// @Failure 404 {string} string "not found"
|
||||||
// @Router /dns/records/{id} [get]
|
// @Router /dns/records/{id} [get]
|
||||||
func GetRecordSet(db *gorm.DB) http.HandlerFunc {
|
func GetRecordSet(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
orgID, ok := httpmiddleware.OrgIDFrom(r.Context())
|
orgID, ok := httpmiddleware.OrgIDFrom(r.Context())
|
||||||
if !ok {
|
if !ok {
|
||||||
utils.WriteError(w, http.StatusForbidden, "org_required", "specify X-Org-ID")
|
utils.WriteError(w, http.StatusForbidden, "org_required", "specify X-Org-ID")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := uuid.Parse(chi.URLParam(r, "id"))
|
id, err := uuid.Parse(chi.URLParam(r, "id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteError(w, http.StatusBadRequest, "bad_id", "invalid UUID")
|
utils.WriteError(w, http.StatusBadRequest, "bad_id", "invalid UUID")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var row models.RecordSet
|
var row models.RecordSet
|
||||||
if err := db.
|
if err := db.
|
||||||
Joins("Domain").
|
Joins("Domain").
|
||||||
Where(`record_sets.id = ? AND "Domain"."organization_id" = ?`, id, orgID).
|
Where(`record_sets.id = ? AND "Domain"."organization_id" = ?`, id, orgID).
|
||||||
First(&row).Error; err != nil {
|
First(&row).Error; err != nil {
|
||||||
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
utils.WriteError(w, http.StatusNotFound, "not_found", "record set not found")
|
utils.WriteError(w, http.StatusNotFound, "not_found", "record set not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
utils.WriteError(w, http.StatusInternalServerError, "db_error", err.Error())
|
utils.WriteError(w, http.StatusInternalServerError, "db_error", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.WriteJSON(w, http.StatusOK, recordOut(&row))
|
utils.WriteJSON(w, http.StatusOK, recordOut(&row))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRecordSet godoc
|
// CreateRecordSet godoc
|
||||||
|
|||||||
Reference in New Issue
Block a user