Files
query-orchestration/cmd/queryAPI/main.go
T
Jay Brown 63c12a2f44 Merged in feature/eula.part1 (pull request #206)
eula support

* eula support

* docs
2026-01-22 18:17:27 +00:00

152 lines
4.5 KiB
Go

// This API currently manages all user entities to be managed. This allows users of the service to change required entities and processes.
//
// The entities in question:
//
// - Client - A client is a single client of the Doczy project, all configurations and clients for a client will be in reference to the respective client.
//
// - Collector - A collector specifies document processing settings for a given client.
//
// - Sample - A sample is a subset of documents to be used for testing. When it is active a client will only process documents in the sample.
//
// - Export - An export is a manually started process which outputs the results for a client to a given location.
//
// Note: Query functionality has been removed from this API. See remove_query_plan.md for details.
package main
import (
"context"
"fmt"
"log/slog"
"os"
"queryorchestration/internal/backgroundtask"
"queryorchestration/internal/client"
"queryorchestration/internal/cognitoauth"
"queryorchestration/internal/collector"
"queryorchestration/internal/document"
"queryorchestration/internal/eula"
"queryorchestration/internal/export"
"queryorchestration/internal/fieldextraction"
"queryorchestration/internal/folder"
"queryorchestration/internal/label"
"queryorchestration/internal/server/api"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/build"
"queryorchestration/internal/serviceconfig/objectstore"
"queryorchestration/internal/serviceconfig/queue/clientsync"
queryapi "queryorchestration/api/queryAPI"
documentbatch "queryorchestration/internal/document/batch"
documentupload "queryorchestration/internal/document/upload"
clientupdate "queryorchestration/internal/client/update"
collectorset "queryorchestration/internal/collector/set"
"github.com/getkin/kin-openapi/openapi3"
_ "github.com/lib/pq"
)
type QueryAPIConfig struct {
api.BaseConfig
clientsync.ClientSyncConfig
objectstore.ObjectStoreConfig
BackgroundRunner *backgroundtask.Runner
}
func main() {
// Print version information before any environment checks
build.PrintVersionInfo("queryAPI")
ctx := context.Background()
cfg := &QueryAPIConfig{}
cfg.RegisterHandlersFunc = func() (*openapi3.T, error) {
exp := export.New()
col := collector.New(cfg)
colupdate := collectorset.New(cfg, &collectorset.Services{
Collector: col,
})
cli := client.New(cfg)
cliUpdate := clientupdate.New(cfg, &clientupdate.Services{
Client: cli,
})
doc := document.New(cfg)
docup := documentupload.New(cfg)
docbatch := documentbatch.New(cfg)
fieldext := fieldextraction.New(cfg)
fld := folder.New(cfg)
lbl := label.New(cfg)
eul := eula.New(cfg)
services := &queryapi.Services{
Export: exp,
Collector: col,
CollectorSet: colupdate,
Client: cli,
ClientUpdate: cliUpdate,
Document: doc,
DocumentUpload: docup,
DocumentBatch: docbatch,
FieldExtraction: fieldext,
Folder: fld,
Label: lbl,
Eula: eul,
}
cons := queryapi.NewControllers(services, cfg)
queryapi.RegisterHandlers(cfg.Router, cons)
swagger, err := queryapi.GetSwagger()
if err != nil {
return nil, fmt.Errorf("error loading swagger: %w", err)
}
return swagger, nil
}
// Both of these operations (InitializeConfig and InitializeAuthConfig)
// would be better off in one function but since there are services
// that need the config but do not use auth we will keep them separate for now.
// This must be done before the rbac.InitializeAuthProvider
errInitializingConfig := serviceconfig.InitializeConfig(cfg)
if errInitializingConfig != nil {
slog.Error(errInitializingConfig.Error())
os.Exit(1)
}
// Authentication specific config.
cfg.BaseURL = fmt.Sprintf("%s:%d", cfg.BaseURL, cfg.Port)
errorInitializingAuthConfig := cfg.InitializeAuthConfig(cfg.BaseURL, cfg.GetLogger())
fmt.Printf("base url after InitializeAuthConfig: %s\n", cfg.BaseURL)
// join initErr with errorInitializingAuthConfig
if errorInitializingAuthConfig != nil {
slog.Error(errorInitializingAuthConfig.Error())
os.Exit(1)
}
// Validate Permit.io configuration before starting server
if err := cognitoauth.ValidatePermitIOConfiguration(); err != nil {
slog.Error("Permit.io configuration validation failed", "error", err)
os.Exit(1)
}
// Initialize S3 client before creating the server (needed for background worker)
err := cfg.SetStoreClient(ctx)
if err != nil {
slog.Error(err.Error())
os.Exit(1)
}
server, err := api.New(ctx, cfg)
if err != nil {
slog.Error(err.Error())
os.Exit(1)
}
server.Listen()
}