Skip to content

Commit 9cfc7de

Browse files
authored
Merge pull request #31 from oxyno-zeta/add-template-per-target
feat: Add templates per target
2 parents ef6edc2 + 74600e4 commit 9cfc7de

19 files changed

+3128
-420
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ifndef HAS_GOLANGCI_LINT
103103
ifndef HAS_CURL
104104
$(error You must install curl)
105105
endif
106-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.23.6
106+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.24.0
107107
endif
108108
ifndef HAS_COLORGO
109109
@echo "=> Installing colorgo tool"

conf/config-example.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ log:
1111
# port: 8080
1212

1313
# Template configurations
14-
# template:
14+
# templates:
1515
# badRequest: templates/bad-request.tpl
1616
# folderList: templates/folder-list.tpl
1717
# forbidden: templates/forbidden.tpl
@@ -150,6 +150,32 @@ targets:
150150
# DELETE:
151151
# # Will allow DELETE requests
152152
# enabled: true
153+
## Target custom templates
154+
# templates:
155+
# # Folder list template
156+
# folderList:
157+
# inBucket: false
158+
# path: ""
159+
# # Not found template
160+
# notFound:
161+
# inBucket: false
162+
# path: ""
163+
# # Internal server error template
164+
# internalServerError:
165+
# inBucket: false
166+
# path: ""
167+
# # Forbidden template
168+
# forbidden:
169+
# inBucket: false
170+
# path: ""
171+
# # Unauthorized template
172+
# unauthorized:
173+
# inBucket: false
174+
# path: ""
175+
# # BadRequest template
176+
# badRequest:
177+
# inBucket: false
178+
# path: ""
153179
## Bucket configuration
154180
bucket:
155181
name: super-bucket

docs/configuration.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ You can see a full example in the [Example section](#example)
5353
| resources | [[Resource]](#resource) | No | None | Resources declaration for path whitelist or specific authentication on path list |
5454
| mount | [MountConfiguration](#mountconfiguration) | Yes | None | Mount point configuration |
5555
| actions | [ActionsConfiguration](#actionsconfiguration) | No | GET action enabled | Actions allowed on target (GET, PUT or DELETE) |
56+
| templates | [TargetTemplateConfig](#targettemplateconfig) | No | None | Custom target templates from files on local filesystem or in bucket |
57+
58+
## TargetTemplateConfig
59+
60+
| Key | Type | Required | Default | Description |
61+
| ------------------- | ----------------------------------------------------- | -------- | ------- | ------------------------------------------------- |
62+
| folderList | [TargetTemplateConfigItem](#targettemplateconfigitem) | No | None | Folder list custom template declaration |
63+
| notFound | [TargetTemplateConfigItem](#targettemplateconfigitem) | No | None | Not Found custom template declaration |
64+
| internalServerError | [TargetTemplateConfigItem](#targettemplateconfigitem) | No | None | Internal server error custom template declaration |
65+
| forbidden | [TargetTemplateConfigItem](#targettemplateconfigitem) | No | None | Forbidden custom template declaration |
66+
| unauthorized | [TargetTemplateConfigItem](#targettemplateconfigitem) | No | None | Unauthorized custom template declaration |
67+
| badRequest | [TargetTemplateConfigItem](#targettemplateconfigitem) | No | None | Bad Request custom template declaration |
68+
69+
## TargetTemplateConfigItem
70+
71+
| Key | Type | Required | Default | Description |
72+
| -------- | ------- | -------- | ------- | ----------------------------------------------- |
73+
| inBucket | Boolean | No | `false` | Is the file in bucket or on local file system ? |
74+
| path | String | Yes | None | Path for template file |
5675

5776
## ActionsConfiguration
5877

@@ -213,7 +232,7 @@ log:
213232
# port: 8080
214233

215234
# Template configurations
216-
# template:
235+
# templates:
217236
# badRequest: templates/bad-request.tpl
218237
# folderList: templates/folder-list.tpl
219238
# forbidden: templates/forbidden.tpl
@@ -249,6 +268,7 @@ log:
249268
# List targets feature
250269
# This will generate a webpage with list of targets with links using targetList template
251270
# listTargets:
271+
# # To enable the list targets feature
252272
# enabled: false
253273
# ## Mount point
254274
# mount:
@@ -260,6 +280,11 @@ log:
260280
# resource:
261281
# # A Path must be declared for a resource filtering
262282
# path: /
283+
# # HTTP Methods authorized (Must be in GET, PUT or DELETE)
284+
# methods:
285+
# - GET
286+
# - PUT
287+
# - DELETE
263288
# # Whitelist
264289
# whitelist: false
265290
# # A authentication provider declared in section before, here is the key name
@@ -293,6 +318,11 @@ targets:
293318
# whiteList: true
294319
# # A Path must be declared for a resource filtering (a wildcard can be added to match every sub path)
295320
# - path: /specific_doc/*
321+
# # HTTP Methods authorized (Must be in GET, PUT or DELETE)
322+
# methods:
323+
# - GET
324+
# - PUT
325+
# - DELETE
296326
# # A authentication provider declared in section before, here is the key name
297327
# provider: provider1
298328
# # OIDC section for access filter
@@ -302,6 +332,11 @@ targets:
302332
# - group: specific_users
303333
# # A Path must be declared for a resource filtering (a wildcard can be added to match every sub path)
304334
# - path: /directory1/*
335+
# # HTTP Methods authorized (Must be in GET, PUT or DELETE)
336+
# methods:
337+
# - GET
338+
# - PUT
339+
# - DELETE
305340
# # A authentication provider declared in section before, here is the key name
306341
# provider: provider1
307342
# # Basic authentication section
@@ -336,12 +371,39 @@ targets:
336371
# DELETE:
337372
# # Will allow DELETE requests
338373
# enabled: true
374+
## Target custom templates
375+
# templates:
376+
# # Folder list template
377+
# folderList:
378+
# inBucket: false
379+
# path: ""
380+
# # Not found template
381+
# notFound:
382+
# inBucket: false
383+
# path: ""
384+
# # Internal server error template
385+
# internalServerError:
386+
# inBucket: false
387+
# path: ""
388+
# # Forbidden template
389+
# forbidden:
390+
# inBucket: false
391+
# path: ""
392+
# # Unauthorized template
393+
# unauthorized:
394+
# inBucket: false
395+
# path: ""
396+
# # BadRequest template
397+
# badRequest:
398+
# inBucket: false
399+
# path: ""
339400
## Bucket configuration
340401
bucket:
341402
name: super-bucket
342403
prefix:
343404
region: eu-west-1
344405
s3Endpoint:
406+
disableSSL: false
345407
# credentials:
346408
# accessKey:
347409
# env: AWS_ACCESS_KEY_ID

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/oxyno-zeta/s3-proxy
33
go 1.13
44

55
require (
6+
github.com/Masterminds/goutils v1.1.0 // indirect
67
github.com/Masterminds/semver v1.5.0 // indirect
78
github.com/Masterminds/sprig v2.22.0+incompatible
8-
github.com/Masterminds/sprig/v3 v3.0.2
99
github.com/aws/aws-sdk-go v1.29.29
1010
github.com/coreos/go-oidc v2.2.1+incompatible
1111
github.com/dgrijalva/jwt-go v3.2.0+incompatible
@@ -16,10 +16,12 @@ require (
1616
github.com/go-playground/validator/v10 v10.2.0
1717
github.com/gobwas/glob v0.2.3
1818
github.com/golang/protobuf v1.3.3 // indirect
19+
github.com/google/uuid v1.1.1 // indirect
1920
github.com/huandu/xstrings v1.3.0 // indirect
2021
github.com/imdario/mergo v0.3.8 // indirect
2122
github.com/johannesboyne/gofakes3 v0.0.0-20200218152459-de0855a40bc1
2223
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
24+
github.com/mitchellh/copystructure v1.0.0 // indirect
2325
github.com/mitchellh/reflectwalk v1.0.1 // indirect
2426
github.com/pelletier/go-toml v1.6.0 // indirect
2527
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect

go.sum

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,15 @@ github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RP
77
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
88
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
99
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
10-
github.com/Masterminds/semver/v3 v3.0.3/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
1110
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
1211
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
13-
github.com/Masterminds/sprig/v3 v3.0.2/go.mod h1:oesJ8kPONMONaZgtiHNzUShJbksypC5kWczhZAf6+aU=
1412
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
1513
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
1614
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
1715
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
1816
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
1917
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
2018
github.com/aws/aws-sdk-go v1.17.4/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
21-
github.com/aws/aws-sdk-go v1.28.13 h1:JyCQQ86yil3hg7MtWdNH8Pbcgx92qlUV2v22Km63Mf4=
22-
github.com/aws/aws-sdk-go v1.28.13/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
23-
github.com/aws/aws-sdk-go v1.29.16/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
24-
github.com/aws/aws-sdk-go v1.29.17/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
25-
github.com/aws/aws-sdk-go v1.29.18 h1:3T6OdmTwOiEX/didd+RkTdOm6WPzXKFLMVS+ZH9DX1I=
26-
github.com/aws/aws-sdk-go v1.29.18/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
27-
github.com/aws/aws-sdk-go v1.29.24 h1:KOnds/LwADMDBaALL4UB98ZR+TUR1A1mYmAYbdLixLA=
28-
github.com/aws/aws-sdk-go v1.29.24/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
2919
github.com/aws/aws-sdk-go v1.29.29 h1:4TdSYzXL8bHKu80tzPjO4c0ALw4Fd8qZGqf1aozUcBU=
3020
github.com/aws/aws-sdk-go v1.29.29/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
3121
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
@@ -73,8 +63,6 @@ github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8c
7363
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
7464
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
7565
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
76-
github.com/go-playground/validator/v10 v10.1.0 h1:LNfPbVcg93V/91tkAQH8nbFbFn7u2X4hHnLMeRZHIMM=
77-
github.com/go-playground/validator/v10 v10.1.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
7866
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
7967
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
8068
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
@@ -109,16 +97,13 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
10997
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
11098
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
11199
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
112-
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
113100
github.com/huandu/xstrings v1.3.0 h1:gvV6jG9dTgFEncxo+AF7PH6MZXi/vZl25owA/8Dg8Wo=
114101
github.com/huandu/xstrings v1.3.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
115-
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
116102
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
117103
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
118104
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
119105
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
120-
github.com/johannesboyne/gofakes3 v0.0.0-20191228161223-9aee1c78a252 h1:ZABLXRnnFNP5nkVzVBx2kQ/4GvSLUqcD2YUc+9Uc2Mo=
121-
github.com/johannesboyne/gofakes3 v0.0.0-20191228161223-9aee1c78a252/go.mod h1:cPDudDcSR9fls3ZmrXgt0GU2QpQGQRJc4JBNtKyNr1s=
106+
github.com/johannesboyne/gofakes3 v0.0.0-20200218152459-de0855a40bc1 h1:jUva9XoPV9p9TE66pzRbSRY5cFJcUBoTkgxyQjxLLGI=
122107
github.com/johannesboyne/gofakes3 v0.0.0-20200218152459-de0855a40bc1/go.mod h1:fNiSoOiEI5KlkWXn26OwKnNe58ilTIkpBlgOrt7Olu8=
123108
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
124109
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
@@ -171,10 +156,6 @@ github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prY
171156
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
172157
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
173158
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
174-
github.com/prometheus/client_golang v1.4.1 h1:FFSuS004yOQEtDdTq+TAOLP5xUq63KqAFYyOi8zA+Y8=
175-
github.com/prometheus/client_golang v1.4.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
176-
github.com/prometheus/client_golang v1.5.0 h1:Ctq0iGpCmr3jeP77kbF2UxgvRwzWWz+4Bh9/vJTyg1A=
177-
github.com/prometheus/client_golang v1.5.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
178159
github.com/prometheus/client_golang v1.5.1 h1:bdHYieyGlH+6OLEk2YQha8THib30KP0/yD0YH9m6xcA=
179160
github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
180161
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
@@ -236,8 +217,6 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
236217
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
237218
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
238219
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
239-
github.com/thoas/go-funk v0.5.0 h1:XXFUVqX6xnIDqXxENFHBFS1X5AoT0EDs7HJq2krRfD8=
240-
github.com/thoas/go-funk v0.5.0/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
241220
github.com/thoas/go-funk v0.6.0 h1:ryxN0pa9FnI7YHgODdLIZ4T6paCZJt8od6N9oRztMxM=
242221
github.com/thoas/go-funk v0.6.0/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
243222
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
@@ -250,7 +229,6 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
250229
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
251230
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
252231
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
253-
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
254232
golang.org/x/crypto v0.0.0-20200208060501-ecb85df21340 h1:KOcEaR10tFr7gdJV2GCKw8Os5yED1u1aOqHjOAb6d2Y=
255233
golang.org/x/crypto v0.0.0-20200208060501-ecb85df21340/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
256234
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -270,8 +248,6 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowK
270248
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
271249
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
272250
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
273-
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
274-
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
275251
golang.org/x/net v0.0.0-20200320220750-118fecf932d8 h1:1+zQlQqEEhUeStBTi653GZAnAuivZq/2hz+Iz+OP7rg=
276252
golang.org/x/net v0.0.0-20200320220750-118fecf932d8/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
277253
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=

pkg/bucket/client.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ type Client interface {
1818
Put(inp *PutInput)
1919
// Delete will delete file on request path
2020
Delete(requestPath string)
21+
// Handle not found errors with bucket configuration
22+
HandleNotFound(requestPath string)
23+
// Handle forbidden errors with bucket configuration
24+
HandleForbidden(requestPath string)
25+
// Handle bad request errors with bucket configuration
26+
HandleBadRequest(err error, requestPath string)
27+
// Handle internal server error errors with bucket configuration
28+
HandleInternalServerError(err error, requestPath string)
29+
// Handle unauthorized errors with bucket configuration
30+
HandleUnauthorized(requestPath string)
2131
}
2232

2333
// PutInput represents Put input
@@ -28,30 +38,35 @@ type PutInput struct {
2838
ContentType string
2939
}
3040

41+
// ErrorHandlers error handlers
42+
type ErrorHandlers struct {
43+
HandleNotFoundWithTemplate func(tplString string, rw http.ResponseWriter, requestPath string, logger logrus.FieldLogger, tplCfg *config.TemplateConfig) //nolint: lll
44+
HandleInternalServerErrorWithTemplate func(tplString string, rw http.ResponseWriter, err error, requestPath string, logger logrus.FieldLogger, tplCfg *config.TemplateConfig) //nolint: lll
45+
HandleForbiddenWithTemplate func(tplString string, rw http.ResponseWriter, requestPath string, logger logrus.FieldLogger, tplCfg *config.TemplateConfig) //nolint: lll
46+
HandleBadRequestWithTemplate func(tplString string, rw http.ResponseWriter, requestPath string, err error, logger logrus.FieldLogger, tplCfg *config.TemplateConfig) //nolint: lll
47+
HandleUnauthorizedWithTemplate func(tplString string, rw http.ResponseWriter, requestPath string, logger logrus.FieldLogger, tplCfg *config.TemplateConfig) //nolint: lll
48+
}
49+
3150
// NewClient will generate a new client to do GET,PUT or DELETE actions
3251
// nolint:whitespace
3352
func NewClient(
3453
tgt *config.TargetConfig, tplConfig *config.TemplateConfig, logger logrus.FieldLogger,
3554
mountPath string, httpRW http.ResponseWriter,
36-
handleNotFound func(rw http.ResponseWriter, requestPath string, logger logrus.FieldLogger, tplCfg *config.TemplateConfig),
37-
handleInternalServerError func(rw http.ResponseWriter, err error, requestPath string, logger logrus.FieldLogger, tplCfg *config.TemplateConfig),
38-
handleForbidden func(rw http.ResponseWriter, requestPath string, logger logrus.FieldLogger, tplCfg *config.TemplateConfig),
3955
metricsCtx metrics.Client,
56+
errorHandlers *ErrorHandlers,
4057
) (Client, error) {
4158
s3ctx, err := s3client.NewS3Context(tgt, logger, metricsCtx)
4259
if err != nil {
4360
return nil, err
4461
}
4562

4663
return &requestContext{
47-
s3Context: s3ctx,
48-
logger: logger,
49-
bucketInstance: tgt,
50-
mountPath: mountPath,
51-
httpRW: httpRW,
52-
tplConfig: tplConfig,
53-
handleNotFound: handleNotFound,
54-
handleForbidden: handleForbidden,
55-
handleInternalServerError: handleInternalServerError,
64+
s3Context: s3ctx,
65+
logger: logger,
66+
targetCfg: tgt,
67+
mountPath: mountPath,
68+
httpRW: httpRW,
69+
tplConfig: tplConfig,
70+
errorsHandlers: errorHandlers,
5671
}, nil
5772
}

0 commit comments

Comments
 (0)