Skip to content

Commit

Permalink
Http handler updates
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJoiner committed Oct 30, 2024
1 parent d0d9c90 commit 6a48387
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 76 deletions.
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ go 1.23
require (
github.com/ClickHouse/clickhouse-go/v2 v2.30.0
github.com/DIMO-Network/clickhouse-infra v0.0.3
github.com/DIMO-Network/model-garage v0.3.3
github.com/DIMO-Network/nameindexer v0.0.8
github.com/DIMO-Network/shared v0.11.1
github.com/aws/aws-sdk-go-v2 v1.32.2
github.com/aws/aws-sdk-go-v2/credentials v1.17.27
github.com/aws/aws-sdk-go-v2/service/s3 v1.65.3
github.com/ethereum/go-ethereum v1.14.11
github.com/gofiber/contrib/jwt v1.0.10
github.com/gofiber/fiber/v2 v2.52.5
github.com/gofiber/swagger v1.1.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/prometheus/client_golang v1.19.1
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.9.0
github.com/swaggo/swag v1.16.4
golang.org/x/sync v0.8.0
google.golang.org/grpc v1.65.0
Expand All @@ -26,7 +30,6 @@ require (

require (
github.com/ClickHouse/ch-go v0.61.5 // indirect
github.com/DIMO-Network/model-garage v0.3.3 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/MicahParks/keyfunc/v2 v2.1.0 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
Expand All @@ -45,16 +48,15 @@ require (
github.com/aws/smithy-go v1.22.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/ethereum/go-ethereum v1.14.11 // indirect
github.com/friendsofgo/errors v0.9.2 // indirect
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.7.1 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -67,6 +69,7 @@ require (
github.com/paulmach/orb v0.11.1 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
Expand Down
19 changes: 13 additions & 6 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/DIMO-Network/fetch-api/internal/config"
Expand All @@ -29,11 +30,16 @@ import (
"google.golang.org/grpc"
)

// CreateWebServer creates a new web server with the given logger and settings.
func CreateWebServer(logger *zerolog.Logger, settings *config.Settings) (*fiber.App, error) {
if !common.IsHexAddress(settings.VehicleNFTAddress) {
return nil, errors.New("invalid vehicle NFT address")
}
vehicleNFTAddress := common.HexToAddress(settings.VehicleNFTAddress)
chainId, err := strconv.ParseUint(settings.ChainID, 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse chain ID: %w", err)
}

app := fiber.New(fiber.Config{
ErrorHandler: func(c *fiber.Ctx, err error) error {
Expand Down Expand Up @@ -75,17 +81,18 @@ func CreateWebServer(logger *zerolog.Logger, settings *config.Settings) (*fiber.
}

s3Client := s3ClientFromSettings(settings)

h := httphandler.NewHandler(chConn, s3Client, settings.CloudEventBucket, settings.CloudEventBucket)
vehHandler := httphandler.NewHandler(logger, chConn, s3Client,
settings.CloudEventBucket, settings.EphemeralBucket, vehicleNFTAddress, chainId)
// File endpoints
vehicleGroup.Post("/latest-filename/:tokenId", vehiclePriv, jwtAuth, h.GetLatestFileName)
vehicleGroup.Post("/filenames/:tokenId", vehiclePriv, jwtAuth, h.GetFileNames)
vehicleGroup.Post("/files/:tokenId", jwtAuth, vehiclePriv, h.GetFiles)
vehicleGroup.Post("/latest-file/:tokenId", jwtAuth, vehiclePriv, h.GetLatestFile)
vehicleGroup.Post("/latest-filename/:tokenId", vehiclePriv, jwtAuth, vehHandler.GetLatestFileName)
vehicleGroup.Post("/filenames/:tokenId", vehiclePriv, jwtAuth, vehHandler.GetFileNames)
vehicleGroup.Post("/files/:tokenId", jwtAuth, vehiclePriv, vehHandler.GetFiles)
vehicleGroup.Post("/latest-file/:tokenId", jwtAuth, vehiclePriv, vehHandler.GetLatestFile)

return app, nil
}

// CreateGRPCServer creates a new gRPC server with the given logger and settings.
func CreateGRPCServer(logger *zerolog.Logger, settings *config.Settings) (*grpc.Server, error) {
chConn, err := chClientFromSettings(settings)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Settings struct {
TokenExchangeJWTKeySetURL string `yaml:"TOKEN_EXCHANGE_JWK_KEY_SET_URL"`
TokenExchangeIssuer string `yaml:"TOKEN_EXCHANGE_ISSUER_URL"`
VehicleNFTAddress string `yaml:"VEHICLE_NFT_ADDRESS"`
ChainID string `yaml:"CHAIN_ID"`
CloudEventBucket string `yaml:"CLOUDEVENT_BUCKET"`
EphemeralBucket string `yaml:"EPHEMERAL_BUCKET"`
S3AWSRegion string `yaml:"S3_AWS_REGION"`
Expand Down
Loading

0 comments on commit 6a48387

Please sign in to comment.