Skip to content

Commit

Permalink
Revert "return 204 on 404 with missing optional files (RedHatInsights…
Browse files Browse the repository at this point in the history
…#2643)" (RedHatInsights#2646)

This reverts commit b603840.
  • Loading branch information
loadtheaccumulator authored Jul 15, 2024
1 parent ba58f31 commit 59b5ddd
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 37 deletions.
15 changes: 0 additions & 15 deletions pkg/errors/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,6 @@ func NewNotFound(message string) APIError {
return err
}

// NoContent defines an error where the file was not found, but it's necessary to return a 204
type NoContent struct {
apiError
}

// NewNoContent creat a new NoContent error
func NewNoContent(message string) APIError {
err := new(NoContent)
err.Code = "NO_CONTENT"
err.Title = message
err.Status = http.StatusNoContent

return err
}

// FeatureNotAvailable defines a error when the feature is toggled off via feature flags
type FeatureNotAvailable struct {
apiError
Expand Down
18 changes: 1 addition & 17 deletions pkg/routes/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"
"net/http"
url2 "net/url"
"path/filepath"
"strconv"
"strings"
"time"
Expand All @@ -18,7 +17,6 @@ import (
"github.com/redhatinsights/edge-api/pkg/metrics"
"github.com/redhatinsights/edge-api/pkg/models"
"github.com/redhatinsights/edge-api/pkg/services"
feature "github.com/redhatinsights/edge-api/unleash/features"

"github.com/redhatinsights/edge-api/config"

Expand Down Expand Up @@ -136,27 +134,13 @@ func serveStorageContent(w http.ResponseWriter, r *http.Request, path string) {
logger.WithFields(log.Fields{
"error": err.Error(),
}).Error("error occurred when getting file from request path")

var apiError errors.APIError
if strings.Contains(err.Error(), "was not found on the S3 bucket") {
if feature.Return204for404.IsEnabled() {
// handle optional ostree files when not found
filebase := filepath.Base(path)
switch filebase {
case ".commitmeta", "summary", "summary.sig", "superblock":
apiError = errors.NewNoContent(fmt.Sprintf("file '%s' was not found", path))
default:
apiError = errors.NewNotFound(fmt.Sprintf("file '%s' was not found", path))
}
} else {
apiError = errors.NewNotFound(fmt.Sprintf("file '%s' was not found", path))
}
apiError = errors.NewNotFound(fmt.Sprintf("file '%s' was not found", path))
} else {
apiError = errors.NewInternalServerError()
}

respondWithAPIError(w, logger, apiError)

return
}
defer func(requestFile io.ReadCloser) {
Expand Down
5 changes: 0 additions & 5 deletions unleash/features/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ var SilentGormLogging = &Flag{Name: "edge-management.silent_gorm_logging", EnvVa
// PulpIntegration covers the overall integration of pulp and deprecation of AWS storage
var PulpIntegration = &Flag{Name: "edge-management.pulp_integration", EnvVar: "FEATURE_PULP_INTEGRATION"}

// OSTREE FLAGS

// Return204for404 returns 204 No Content instead of 404 Not Found when not finding an optional ostree file
var Return204for404 = &Flag{Name: "edge-management.return_204", EnvVar: "FEATURE_RETURN_204"}

// (ADD FEATURE FLAGS ABOVE)
// FEATURE FLAG CHECK CODE

Expand Down

0 comments on commit 59b5ddd

Please sign in to comment.