Claude-assisted improvements (untested)
- dev auth flow (side-step OAuth) - db event processing integration tests - dev scripts (eg Makefile) - db / test db migration setup scripts.
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/lmittmann/tint"
|
||||
|
||||
"ruben/inventory2/config"
|
||||
"ruben/inventory2/domains/accounts"
|
||||
"ruben/inventory2/domains/amazon"
|
||||
"ruben/inventory2/domains/authentication"
|
||||
@@ -32,11 +33,6 @@ import (
|
||||
"ruben/inventory2/server/sse"
|
||||
)
|
||||
|
||||
const (
|
||||
etsyAPIKeystring = "38ncokqh0jih5jshfk8iv4n5"
|
||||
etsyAPISharedSecret = "jaaw0tyizf"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger := logging.New(tint.NewHandler(os.Stderr, &tint.Options{
|
||||
AddSource: true,
|
||||
@@ -68,14 +64,29 @@ func runApp(ctx context.Context, logger *logging.Logger) error {
|
||||
ctx, shutdown := context.WithCancel(ctx)
|
||||
defer shutdown()
|
||||
|
||||
// load configuration
|
||||
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load configuration: %w", err)
|
||||
}
|
||||
|
||||
// connect to the database
|
||||
|
||||
connPool, err := newPool(ctx)
|
||||
connPool, err := newPool(ctx, cfg.DatabaseURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize database connection pool: %w", err)
|
||||
}
|
||||
|
||||
auth, err := authentication.New(ctx, connPool, logger.WithGroup("authenticator"))
|
||||
auth, err := authentication.New(
|
||||
ctx,
|
||||
connPool,
|
||||
logger.WithGroup("authenticator"),
|
||||
cfg.Auth0Domain,
|
||||
cfg.Auth0ClientID,
|
||||
cfg.Auth0ClientSecret,
|
||||
cfg.Auth0CallbackURL,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to construct authenticator: %w", err)
|
||||
}
|
||||
@@ -84,7 +95,7 @@ func runApp(ctx context.Context, logger *logging.Logger) error {
|
||||
|
||||
// start http server
|
||||
|
||||
sseQueue, srvErrCh := runServer(ctx, logger, connPool, auth, accts)
|
||||
sseQueue, srvErrCh := runServer(ctx, logger, connPool, auth, accts, cfg)
|
||||
|
||||
// start background processes
|
||||
|
||||
@@ -207,6 +218,7 @@ func runServer(
|
||||
connPool *pgxpool.Pool,
|
||||
auth *authentication.Authenticator,
|
||||
accts *accounts.Store,
|
||||
cfg config.Config,
|
||||
) (*sse.Queue, <-chan error) {
|
||||
r := server.NewRouter(
|
||||
logger.WithGroup("server"),
|
||||
@@ -219,11 +231,12 @@ func runServer(
|
||||
func(acctID int64) string {
|
||||
return fmt.Sprintf("/oauth/account/%d/auth_code", acctID)
|
||||
},
|
||||
etsyAPIKeystring,
|
||||
etsyAPISharedSecret,
|
||||
cfg.EtsyAPIKeystring,
|
||||
cfg.EtsyAPISharedSecret,
|
||||
connPool,
|
||||
),
|
||||
auth,
|
||||
cfg.DevAuthEnabled,
|
||||
)
|
||||
|
||||
srv := &http.Server{
|
||||
|
||||
Reference in New Issue
Block a user