Skip to content

Commit fb42974

Browse files
Merge pull request #616 from USACE/issue488/serve-media-fix
Update serve downloads.
2 parents d191ffe + 3e1b50b commit fb42974

3 files changed

Lines changed: 49 additions & 38 deletions

File tree

api/handlers/media.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ func cleanFilepath(rawPath string) (string, error) {
2222
return filepath.Clean("/" + p), nil
2323
}
2424

25-
func ServeMedia(awsCfg *aws.Config, bucket *string) echo.HandlerFunc {
25+
func ServeMedia(awsCfg *aws.Config, bucket *string, endpoint string, forcePathStyle, disableSSL bool) echo.HandlerFunc {
2626
return func(c echo.Context) error {
2727
path, err := cleanFilepath(c.Request().RequestURI)
2828
if err != nil {
2929
return c.String(http.StatusBadRequest, err.Error())
3030
}
3131

32-
// _client := s3.New(session.New(awsCfg))
33-
_client := s3.NewFromConfig(*awsCfg)
32+
_client := s3.NewFromConfig(*awsCfg, func(o *s3.Options) {
33+
o.UsePathStyle = forcePathStyle // was a.WithS3ForcePathStyle(...)
34+
if endpoint != "" { // was: if cfg.AWSS3Endpoint != "" { a.WithEndpoint(...) }
35+
o.BaseEndpoint = aws.String(endpoint)
36+
}
37+
if disableSSL { // was a.WithDisableSSL(...)
38+
o.EndpointOptions.DisableHTTPS = true
39+
}
40+
})
3441
output, err := _client.GetObject(context.Background(), &s3.GetObjectInput{Bucket: bucket, Key: aws.String(path)})
3542
if err != nil {
3643
return c.String(500, err.Error())

api/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,12 @@ func main() {
228228
middleware.IsAdmin,
229229
)
230230

231-
// Downloads
232-
public.GET("/cumulus/download/*", handlers.ServeMedia(&cfg.AwsConfig, &cfg.AWSS3Bucket)) // Serve Downloads
231+
// Serve Downloads
232+
public.GET("/cumulus/download/*", handlers.ServeMedia(
233+
&cfg.AwsConfig, &cfg.AWSS3Bucket,
234+
cfg.AWSS3Endpoint, cfg.AWSS3ForcePathStyle, cfg.AWSS3DisableSSL,
235+
))
236+
233237
// List Downloads
234238
private.GET("/downloads", handlers.ListAdminDownloads(db), middleware.IsAdmin)
235239
// Create Download (Anonymous)

docker-compose.yml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ services:
169169
volumes:
170170
- ./api/:/go/src/app/:rw
171171
ports:
172-
- '80:80'
172+
- '8080:80'
173173
- '2345:2345' # expose port to host for Go delve
174174
restart: always
175175
depends_on:
@@ -202,38 +202,38 @@ services:
202202
cumulusdb:
203203
condition: service_started
204204
# --------------------------------------
205-
featureserv:
206-
build:
207-
context: pg_featureserv
208-
platform: linux/amd64 # this is the supported architecture for postgis
209-
container_name: featureserv
210-
restart: always
211-
environment:
212-
# - DATABASE_URL=postgres://cumulus_user:cumulus_pass@cumulusdb:5432/postgres
213-
# Individual PG env vars are easier to provide in IaC instead of the DATABASE_URL
214-
- PGHOST=cumulusdb
215-
- PGPORT=5432
216-
- PGUSER=cumulus_user
217-
- PGPASSWORD=cumulus_pass
218-
- PGDATABASE=postgres
219-
- PGTARGETROLE=cumulus_reader #this env var is custom
220-
- PGFS_SERVER_HTTPPORT=8080
221-
- PGFS_SERVER_HTTPSPORT=8443
222-
- PGFS_SERVER_URLBASE=http://localhost/features
223-
- PGFS_SERVER_BASEPATH=/features
224-
- PGFS_SERVER_DEBUG=true
225-
- PGFS_WEBSITE_BASEMAPURL=http://a.tile.openstreetmap.org/{z}/{x}/{y}.png
226-
# The API provides a proxy using /features
227-
# This port exposure is for direct access/troubleshooting locally
228-
ports:
229-
- '8080:8080'
230-
depends_on:
231-
cumulusdb:
232-
condition: service_started
233-
flyway:
234-
condition: service_completed_successfully
235-
api:
236-
condition: service_started
205+
# featureserv:
206+
# build:
207+
# context: pg_featureserv
208+
# platform: linux/amd64 # this is the supported architecture for postgis
209+
# container_name: featureserv
210+
# restart: always
211+
# environment:
212+
# # - DATABASE_URL=postgres://cumulus_user:cumulus_pass@cumulusdb:5432/postgres
213+
# # Individual PG env vars are easier to provide in IaC instead of the DATABASE_URL
214+
# - PGHOST=cumulusdb
215+
# - PGPORT=5432
216+
# - PGUSER=cumulus_user
217+
# - PGPASSWORD=cumulus_pass
218+
# - PGDATABASE=postgres
219+
# - PGTARGETROLE=cumulus_reader #this env var is custom
220+
# - PGFS_SERVER_HTTPPORT=8080
221+
# - PGFS_SERVER_HTTPSPORT=8443
222+
# - PGFS_SERVER_URLBASE=http://localhost/features
223+
# - PGFS_SERVER_BASEPATH=/features
224+
# - PGFS_SERVER_DEBUG=true
225+
# - PGFS_WEBSITE_BASEMAPURL=http://a.tile.openstreetmap.org/{z}/{x}/{y}.png
226+
# # The API provides a proxy using /features
227+
# # This port exposure is for direct access/troubleshooting locally
228+
# ports:
229+
# - '8080:8080'
230+
# depends_on:
231+
# cumulusdb:
232+
# condition: service_started
233+
# flyway:
234+
# condition: service_completed_successfully
235+
# api:
236+
# condition: service_started
237237
# --------------------------------------
238238
# pgadmin:
239239
# image: dpage/pgadmin4

0 commit comments

Comments
 (0)