Skip to content

Commit

Permalink
temp return zero byte files for missing ostree optionals (RedHatInsig…
Browse files Browse the repository at this point in the history
…hts#2648)

Signed-off-by: Jonathan Holloway <jholloway@redhat.com>
  • Loading branch information
loadtheaccumulator authored Jul 16, 2024
1 parent 59b5ddd commit 9a48370
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/services/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package services

import (
"bytes"
"fmt"
"io"
"os"
Expand All @@ -11,6 +12,7 @@ import (

"github.com/redhatinsights/edge-api/config"
"github.com/redhatinsights/edge-api/pkg/services/files"
feature "github.com/redhatinsights/edge-api/unleash/features"

"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/s3"
Expand Down Expand Up @@ -109,6 +111,19 @@ func (s *S3FilesService) GetFile(path string) (io.ReadCloser, error) {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case s3.ErrCodeNoSuchKey:
// temporarily returning zero byte file for missing ostree optionals as 200
// FIXME: this is a workaround being tested. don't let it become forgotten technical debt!
if feature.Return200for404.IsEnabled() {
basepath := filepath.Base(path)
switch basepath {
case ".commitmeta", "summary", "summary.sig", "superblock":
o.Body.Close()
zeroByteCloser := io.NopCloser(bytes.NewBufferString(""))

return zeroByteCloser, nil
}
}

return nil, fmt.Errorf("the object %s was not found on the S3 bucket", path)
case s3.ErrCodeInvalidObjectState:
return nil, fmt.Errorf("the object %s was not found on the S3 bucket because of an invalid state", path)
Expand Down
5 changes: 5 additions & 0 deletions unleash/features/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ 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 Return200for404 = &Flag{Name: "edge-management.return_200_4_404", EnvVar: "FEATURE_RETURN_200_4_404"}

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

Expand Down

0 comments on commit 9a48370

Please sign in to comment.