@@ -19,15 +19,15 @@ import (
19
19
"context"
20
20
"encoding/json"
21
21
"encoding/xml"
22
+ errs "errors"
22
23
"fmt"
23
24
"io"
24
25
"io/ioutil"
25
26
"math/rand"
26
27
"net/http"
27
28
"net/url"
28
- "time"
29
-
30
29
"openappsec.io/smartsync-service/models"
30
+ "time"
31
31
32
32
"openappsec.io/ctxutils"
33
33
"openappsec.io/errors"
@@ -39,8 +39,10 @@ const (
39
39
traceClientTimeout = 2 * time .Minute
40
40
41
41
//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"
44
46
45
47
tenantIDHeader = "x-tenant-id"
46
48
headerKeyTraceID = "X-Trace-Id"
@@ -71,7 +73,13 @@ func NewAdapter(c Configuration) (*Adapter, error) {
71
73
72
74
// initialize the adapter
73
75
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
+ }
75
83
if err != nil {
76
84
return errors .Wrapf (err , "failed to get reverse proxy baseURL from %v" , rpBaseURL )
77
85
}
@@ -84,7 +92,7 @@ func (a *Adapter) initialize(c Configuration) error {
84
92
return nil
85
93
}
86
94
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
88
96
func (a * Adapter ) GetFileRaw (ctx context.Context , tenantID string , path string ) ([]byte , bool , error ) {
89
97
if path [:1 ] != "/" {
90
98
path = "/" + path
@@ -108,7 +116,7 @@ func (a *Adapter) GetFileRaw(ctx context.Context, tenantID string, path string)
108
116
}
109
117
decompressed , err := ioutil .ReadAll (compressor )
110
118
defer compressor .Close ()
111
- if err != nil {
119
+ if err != nil && ! errs . Is ( err , io . ErrUnexpectedEOF ) {
112
120
log .WithContext (ctx ).Warnf ("failed to decompress, err: %v, is EOF: %v" , err , err == io .EOF )
113
121
return []byte {}, false , errors .Wrapf (err , "failed to decompress %v" , string (resp ))
114
122
}
@@ -121,7 +129,7 @@ func (a *Adapter) GetFileRaw(ctx context.Context, tenantID string, path string)
121
129
return resp , false , nil
122
130
}
123
131
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
125
133
func (a * Adapter ) GetFile (ctx context.Context , tenantID string , path string , out interface {}) (bool , error ) {
126
134
data , isCompressed , err := a .GetFileRaw (ctx , tenantID , path )
127
135
if err != nil {
0 commit comments