Skip to content

Commit eeabda1

Browse files
oskarhurstOskar Hurst
andauthored
version bump Cog (#617)
Co-authored-by: Oskar Hurst <oskar.a.hurst@usace.army.mil>
1 parent 37ecf5a commit eeabda1

3 files changed

Lines changed: 53 additions & 45 deletions

File tree

api/handlers/productfile_cog.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import (
55
"log"
66
"net/http"
77

8-
"github.com/aws/aws-sdk-go/aws"
9-
"github.com/aws/aws-sdk-go/aws/session"
10-
"github.com/aws/aws-sdk-go/service/s3"
8+
"github.com/aws/aws-sdk-go-v2/aws"
9+
"github.com/aws/aws-sdk-go-v2/service/s3"
1110
"github.com/google/uuid"
1211
"github.com/labstack/echo/v4"
1312

1413
"github.com/USACE/cumulus-api/api/middleware"
1514
"github.com/USACE/cumulus-api/api/models"
1615

17-
_ "github.com/jackc/pgx/v4"
18-
"github.com/jackc/pgx/v4/pgxpool"
16+
_ "github.com/jackc/pgx/v5"
17+
"github.com/jackc/pgx/v5/pgxpool"
1918
)
2019

2120
// ListProductfilesCOG returns the productfiles for a product over a time range as
@@ -60,7 +59,7 @@ func ListProductfilesCOG(db *pgxpool.Pool) echo.HandlerFunc {
6059
// Content-Range/Accept-Ranges so a GDAL /vsicurl/ client can read tiles directly
6160
// (no full download). HEAD returns size + range support for /vsicurl/ probing.
6261
// Every request is authenticated (private route) and logged for metering.
63-
func StreamProductfileCOG(db *pgxpool.Pool, awsCfg *aws.Config) echo.HandlerFunc {
62+
func StreamProductfileCOG(db *pgxpool.Pool, awsCfg *aws.Config, endpoint string, forcePathStyle, disableSSL bool) echo.HandlerFunc {
6463
return func(c echo.Context) error {
6564
pfID, err := uuid.Parse(c.Param("productfile_id"))
6665
if err != nil {
@@ -72,11 +71,20 @@ func StreamProductfileCOG(db *pgxpool.Pool, awsCfg *aws.Config) echo.HandlerFunc
7271
return c.String(http.StatusNotFound, "Productfile not found")
7372
}
7473

75-
client := s3.New(session.New(awsCfg))
74+
ctx := c.Request().Context()
75+
client := s3.NewFromConfig(*awsCfg, func(o *s3.Options) {
76+
o.UsePathStyle = forcePathStyle
77+
if endpoint != "" {
78+
o.BaseEndpoint = aws.String(endpoint)
79+
}
80+
if disableSSL {
81+
o.EndpointOptions.DisableHTTPS = true
82+
}
83+
})
7684

7785
// HEAD: metadata only (size + range support) for /vsicurl/ probing.
7886
if c.Request().Method == http.MethodHead {
79-
head, err := client.HeadObject(&s3.HeadObjectInput{Bucket: &obj.Bucket, Key: &obj.Key})
87+
head, err := client.HeadObject(ctx, &s3.HeadObjectInput{Bucket: &obj.Bucket, Key: &obj.Key})
8088
if err != nil {
8189
return c.String(http.StatusInternalServerError, err.Error())
8290
}
@@ -94,7 +102,7 @@ func StreamProductfileCOG(db *pgxpool.Pool, awsCfg *aws.Config) echo.HandlerFunc
94102
in.Range = aws.String(rangeHeader)
95103
}
96104

97-
out, err := client.GetObject(in)
105+
out, err := client.GetObject(ctx, in)
98106
if err != nil {
99107
return c.String(http.StatusInternalServerError, err.Error())
100108
}

api/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ func main() {
162162
public.GET("/products/:product_id/files", handlers.ListProductfiles(db))
163163
// Direct, Range-capable COG access (authenticated + metered) for desktop clients
164164
private.GET("/products/:product_id/cog-files", handlers.ListProductfilesCOG(db))
165-
private.GET("/products/:product_id/cog/:productfile_id", handlers.StreamProductfileCOG(db, &awsCfg))
166-
private.HEAD("/products/:product_id/cog/:productfile_id", handlers.StreamProductfileCOG(db, &awsCfg))
165+
private.GET("/products/:product_id/cog/:productfile_id", handlers.StreamProductfileCOG(db, &cfg.AwsConfig, cfg.AWSS3Endpoint, cfg.AWSS3ForcePathStyle, cfg.AWSS3DisableSSL))
166+
private.HEAD("/products/:product_id/cog/:productfile_id", handlers.StreamProductfileCOG(db, &cfg.AwsConfig, cfg.AWSS3Endpoint, cfg.AWSS3ForcePathStyle, cfg.AWSS3DisableSSL))
167167

168168
// Productfiles
169169
private.POST("/productfiles", handlers.CreateProductfiles(db),

docker-compose.yml

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ services:
158158
- CUMULUS_ASYNC_ENGINE_PACKAGER_TARGET=local/http://localhost:9324/queue/cumulus-packager
159159
- CUMULUS_ASYNC_ENGINE_STATISTICS=AWSSQS
160160
- CUMULUS_ASYNC_ENGINE_STATISTICS_TARGET=local/http://localhost:9324/queue/cumulus-statistics
161-
- CUMULUS_STATIC_HOST=http://localhost
161+
- CUMULUS_STATIC_HOST=http://localhost/api
162162
- CUMULUS_AWS_S3_REGION=us-east-1
163163
- CUMULUS_AWS_S3_BUCKET=castle-data-develop
164164
- CUMULUS_AWS_S3_BUCKET_PREFIX=cumulus/ui
@@ -169,7 +169,7 @@ services:
169169
volumes:
170170
- ./api/:/go/src/app/:rw
171171
ports:
172-
- '8080:80'
172+
- '80: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)