Skip to content

Commit b8f8585

Browse files
committed
configurable proxy
1 parent 2145b48 commit b8f8585

2 files changed

Lines changed: 37 additions & 20 deletions

File tree

backend/doi/doi.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/rclone/rclone/fs/config/configmap"
2020
"github.com/rclone/rclone/fs/config/configstruct"
2121
"github.com/rclone/rclone/fs/fserrors"
22+
"github.com/rclone/rclone/fs/fshttp"
2223
"github.com/rclone/rclone/fs/hash"
2324
"github.com/rclone/rclone/lib/cache"
2425
"github.com/rclone/rclone/lib/pacer"
@@ -72,6 +73,16 @@ The DOI provider can be set when rclone does not automatically recognize a suppo
7273
}},
7374
Required: false,
7475
Advanced: true,
76+
}, {
77+
Name: "proxy_url",
78+
Help: "Proxy URL",
79+
Required: false,
80+
Advanced: true,
81+
}, {
82+
Name: "proxy_ca_cert",
83+
Help: "Proxy CA certificate",
84+
Required: false,
85+
Advanced: true,
7586
}},
7687
}
7788
fs.Register(fsi)
@@ -91,8 +102,10 @@ const (
91102

92103
// Options defines the configuration for this backend
93104
type Options struct {
94-
Doi string `config:"doi"` // The DOI, a digital identifier of an object, usually a dataset
95-
Provider string `config:"provider"` // The DOI provider
105+
Doi string `config:"doi"` // The DOI, a digital identifier of an object, usually a dataset
106+
Provider string `config:"provider"` // The DOI provider
107+
ProxyURL string `config:"proxy_url"`
108+
ProxyCACert string `config:"proxy_ca_cert"`
96109
}
97110

98111
// Fs stores the interface to the remote HTTP files
@@ -277,9 +290,14 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
277290
}
278291
opt.Doi = parseDoi(opt.Doi)
279292

280-
client, err := newHttpClient(ctx)
281-
if err != nil {
282-
return nil, err
293+
var client *http.Client
294+
if opt.ProxyURL != "" {
295+
client, err = newHttpClient(ctx, opt)
296+
if err != nil {
297+
return nil, err
298+
}
299+
} else {
300+
client = fshttp.NewClient(ctx)
283301
}
284302

285303
ci := fs.GetConfig(ctx)

backend/doi/proxy.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ import (
1111
"net/url"
1212
"os"
1313

14+
"github.com/rclone/rclone/fs"
1415
"github.com/rclone/rclone/fs/fshttp"
1516
)
1617

17-
var (
18-
caCertFile = "/Users/leafty/projects/github.com/sdsc/renku-squid-cache/self.cert"
19-
proxyUrlStr = "http://localhost:3128"
20-
)
21-
22-
func newHttpClient(ctx context.Context) (client *http.Client, err error) {
18+
func newHttpClient(ctx context.Context, opt *Options) (client *http.Client, err error) {
2319
client = fshttp.NewClient(ctx)
2420

25-
proxyUrl, err := url.Parse(proxyUrlStr)
21+
proxyUrl, err := url.Parse(opt.ProxyURL)
2622
if err != nil {
2723
return nil, err
2824
}
@@ -33,14 +29,17 @@ func newHttpClient(ctx context.Context) (client *http.Client, err error) {
3329
rootCAs = x509.NewCertPool()
3430
}
3531

36-
// Read in the self-signed certificate
37-
certs, err := os.ReadFile(caCertFile)
38-
if err != nil {
39-
return nil, err
40-
}
41-
42-
if ok := rootCAs.AppendCertsFromPEM(certs); !ok {
43-
return nil, fmt.Errorf("could not append self-signed certificate to the CA pool")
32+
if opt.ProxyCACert != "" {
33+
fs.Logf(nil, "Adding to root CAs: %s", opt.ProxyCACert)
34+
// Read in the self-signed certificate
35+
certs, err := os.ReadFile(opt.ProxyCACert)
36+
if err != nil {
37+
return nil, err
38+
}
39+
// Add the certificate to the root CAs
40+
if ok := rootCAs.AppendCertsFromPEM(certs); !ok {
41+
return nil, fmt.Errorf("could not append self-signed certificate to the CA pool")
42+
}
4443
}
4544

4645
defaultTransport := http.DefaultTransport.(*http.Transport)

0 commit comments

Comments
 (0)