Skip to content

Commit ae7b155

Browse files
use decompressed data after getting unexpected EOF (#2)
* use decompressed data after getting unexpected EOF * config refactor --------- Co-authored-by: Nahum Perman <[email protected]>
1 parent 30d8322 commit ae7b155

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

build/package/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ RUN setcap CAP_NET_BIND_SERVICE=+eip /go/bin/app
3636
# Use an unprivileged user.
3737
USER appuser
3838

39+
ENV APPSEC_MODE "standalone"
3940
# Port on which the service will be exposed.
40-
EXPOSE 8080
41+
EXPOSE 80
4142

4243
# Run the app binary.
4344
ENTRYPOINT ["/go/bin/app"]

cmd/server/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
"os"
1919
"time"
2020

21+
"openappsec.io/log"
2122
"openappsec.io/smartsync-service/internal/app"
2223
"openappsec.io/smartsync-service/internal/app/ingector"
23-
"openappsec.io/log"
2424
)
2525

2626
const (
@@ -35,7 +35,7 @@ const (
3535
func main() {
3636
initCtx, initCancel := context.WithTimeout(context.Background(), initTimeout*time.Second)
3737

38-
isStandAloneMode := os.Getenv(envKeyMode) == "stand-alone"
38+
isStandAloneMode := os.Getenv(envKeyMode) == "standalone"
3939
var app *app.App
4040
var err error
4141
if isStandAloneMode {

configs/bootstrapConfig.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
server:
2-
port: 8080
2+
port: 80
33
timeout: "15s"
44
configurationServer: "" # configuration server can be either etcd or empty
55
log:

go.mod

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ module openappsec.io/smartsync-service
22

33
go 1.18
44

5+
replace (
6+
openappsec.io/configuration => ./dependencies/openappsec.io/configuration
7+
openappsec.io/ctxutils => ./dependencies/openappsec.io/ctxutils
8+
openappsec.io/errors => ./dependencies/openappsec.io/errors
9+
openappsec.io/health => ./dependencies/openappsec.io/health
10+
openappsec.io/httputils => ./dependencies/openappsec.io/httputils
11+
openappsec.io/kafka => ./dependencies/openappsec.io/kafka
12+
openappsec.io/log => ./dependencies/openappsec.io/log
13+
openappsec.io/redis => ./dependencies/openappsec.io/redis
14+
openappsec.io/tracer => ./dependencies/openappsec.io/tracer
15+
)
16+
517
require (
618
github.com/go-chi/chi v4.1.2+incompatible
719
github.com/google/uuid v1.1.2
@@ -49,15 +61,3 @@ require (
4961
gopkg.in/ini.v1 v1.64.0 // indirect
5062
gopkg.in/yaml.v2 v2.4.0 // indirect
5163
)
52-
53-
replace (
54-
openappsec.io/configuration => ./dependencies/openappsec.io/configuration
55-
openappsec.io/ctxutils => ./dependencies/openappsec.io/ctxutils
56-
openappsec.io/errors => ./dependencies/openappsec.io/errors
57-
openappsec.io/health => ./dependencies/openappsec.io/health
58-
openappsec.io/httputils => ./dependencies/openappsec.io/httputils
59-
openappsec.io/kafka => ./dependencies/openappsec.io/kafka
60-
openappsec.io/log => ./dependencies/openappsec.io/log
61-
openappsec.io/redis => ./dependencies/openappsec.io/redis
62-
openappsec.io/tracer => ./dependencies/openappsec.io/tracer
63-
)

internal/pkg/db/s3/s3.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import (
1919
"context"
2020
"encoding/json"
2121
"encoding/xml"
22+
errs "errors"
2223
"fmt"
2324
"io"
2425
"io/ioutil"
2526
"math/rand"
2627
"net/http"
2728
"net/url"
28-
"time"
29-
3029
"openappsec.io/smartsync-service/models"
30+
"time"
3131

3232
"openappsec.io/ctxutils"
3333
"openappsec.io/errors"
@@ -39,8 +39,10 @@ const (
3939
traceClientTimeout = 2 * time.Minute
4040

4141
//conf Key Reverse Proxy
42-
rp = "rp"
43-
rpBaseURL = rp + ".baseUrl"
42+
rp = "rp"
43+
rpBaseURL = rp + ".baseUrl"
44+
sharedStorageKey = "shared_storage"
45+
sharedStorageHostKey = sharedStorageKey + ".host"
4446

4547
tenantIDHeader = "x-tenant-id"
4648
headerKeyTraceID = "X-Trace-Id"
@@ -71,7 +73,13 @@ func NewAdapter(c Configuration) (*Adapter, error) {
7173

7274
// initialize the adapter
7375
func (a *Adapter) initialize(c Configuration) error {
74-
baseURL, err := c.GetString(rpBaseURL)
76+
var baseURL string
77+
host, err := c.GetString(sharedStorageHostKey)
78+
if err != nil {
79+
baseURL, err = c.GetString(rpBaseURL)
80+
} else {
81+
baseURL = fmt.Sprintf("http://%s/api", host)
82+
}
7583
if err != nil {
7684
return errors.Wrapf(err, "failed to get reverse proxy baseURL from %v", rpBaseURL)
7785
}
@@ -84,7 +92,7 @@ func (a *Adapter) initialize(c Configuration) error {
8492
return nil
8593
}
8694

87-
//GetFileRaw - download file, return raw data and true if data was decompressed
95+
// GetFileRaw - download file, return raw data and true if data was decompressed
8896
func (a *Adapter) GetFileRaw(ctx context.Context, tenantID string, path string) ([]byte, bool, error) {
8997
if path[:1] != "/" {
9098
path = "/" + path
@@ -108,7 +116,7 @@ func (a *Adapter) GetFileRaw(ctx context.Context, tenantID string, path string)
108116
}
109117
decompressed, err := ioutil.ReadAll(compressor)
110118
defer compressor.Close()
111-
if err != nil {
119+
if err != nil && !errs.Is(err, io.ErrUnexpectedEOF) {
112120
log.WithContext(ctx).Warnf("failed to decompress, err: %v, is EOF: %v", err, err == io.EOF)
113121
return []byte{}, false, errors.Wrapf(err, "failed to decompress %v", string(resp))
114122
}
@@ -121,7 +129,7 @@ func (a *Adapter) GetFileRaw(ctx context.Context, tenantID string, path string)
121129
return resp, false, nil
122130
}
123131

124-
//GetFile - download file and unmarshal to out return true is data was decompressed
132+
// GetFile - download file and unmarshal to out return true is data was decompressed
125133
func (a *Adapter) GetFile(ctx context.Context, tenantID string, path string, out interface{}) (bool, error) {
126134
data, isCompressed, err := a.GetFileRaw(ctx, tenantID, path)
127135
if err != nil {

0 commit comments

Comments
 (0)