8a4029058b
Add demo dashboard settings table and CRUD API * Add demo dashboard settings table and CRUD API - Migration 00000000000123: create demoDashboardSettings table (id, guid, key, value JSONB, isDeleted, timestamps) - SQLC queries and repository for create, list, listByGuid, get, update, soft delete - OpenAPI paths and schemas in queryAPI.yaml; regenerate api.gen.go (embedded spec) - Handlers in api/queryAPI/demodashboardsettings.go; ConfigProvider GetDBQueries for repo access - Unit tests for demo dashboard settings CRUD * Fix sqlc-generated demo dashboard setting types Align demo dashboard settings handlers with sqlc output (DemoDashboardSetting model + pointer slices) so CI codegen/build succeeds. * Fix CI gosec and gofmt issues - Suppress gosec G115 for TotalCount len->int32 cast (consistent with other list endpoints) - gofmt mock GetDBQueries() in test helpers * gofmt query API demo settings * Tighten demo dashboard settings OpenAPI constraints * Regenerate query API embedded spec * refactor: generic UI settings (table, API, service) and three-layer architecture - Replace demo-dashboard-settings with generic UI settings: - Table uiSettings with namespace (was guid), key, value JSONB; UNIQUE(namespace, key) - Migration 123: create_ui_settings (single migration, no rename) - OpenAPI: /ui-settings, UISettingsService, UISetting schemas with namespace - API types and handlers: CreateUISetting, ListUISettings, GetUISetting, UpdateUISetting, DeleteUISetting - Add service layer (architecture fix): - internal/uisettings: Service with Create, List, ListByNamespace, Get, Update, SoftDelete - Controllers call s.svc.UISettings only; remove GetDBQueries from queryAPI ConfigProvider - Wire UISettings in Services, main.go, and testutils - Repository: uisettings.sql + uisettings.sql.go, UISetting model; remove demodashboardsettings - Controller: uisettings.go (replaces demodashboardsettings.go), ErrNotFound from uisettings package - Tests: uisettings_test.go with namespace-based list/cre… * Add UISetting model and generated queries for uiSettings table - models.go: add UISetting struct (sqlc 1.30.0) - uisettings.sql.go: generated CRUD for ui_settings feature Made-with: Cursor * Use repository.UiSetting to match sqlc-generated type - service and API use repository.UiSetting (sqlc struct name for uiSettings table) - uisettings.sql.go: keep CreateUISetting/GetUISetting etc. from query names, return *UiSetting - Fixes Docker/CI build undefined repository.UISetting * Fix import formatting for golangci-lint * Lint fix * uisettings list test * tests fixes * Merge main: resolve api.gen.go conflicts (UI settings + DeleteDocument) * Doc updates and elimination of index redundancy Approved-by: Jay Brown
173 lines
5.7 KiB
Go
173 lines
5.7 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"
|
|
|
|
queryapi "queryorchestration/api/queryAPI"
|
|
"queryorchestration/internal/backgroundtask"
|
|
"queryorchestration/internal/client"
|
|
clientupdate "queryorchestration/internal/client/update"
|
|
"queryorchestration/internal/cognitoauth"
|
|
"queryorchestration/internal/collector"
|
|
collectorset "queryorchestration/internal/collector/set"
|
|
"queryorchestration/internal/document"
|
|
documentbatch "queryorchestration/internal/document/batch"
|
|
documentupload "queryorchestration/internal/document/upload"
|
|
"queryorchestration/internal/eula"
|
|
"queryorchestration/internal/export"
|
|
"queryorchestration/internal/fieldextraction"
|
|
"queryorchestration/internal/folder"
|
|
"queryorchestration/internal/label"
|
|
"queryorchestration/internal/server/api"
|
|
"queryorchestration/internal/serviceconfig"
|
|
awsc "queryorchestration/internal/serviceconfig/aws"
|
|
"queryorchestration/internal/serviceconfig/build"
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
|
"queryorchestration/internal/serviceconfig/queue/clientsync"
|
|
"queryorchestration/internal/uisettings"
|
|
"queryorchestration/internal/usermanagement"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
|
|
"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)
|
|
uiSvc := uisettings.New(cfg)
|
|
|
|
services := &queryapi.Services{
|
|
Export: exp,
|
|
Collector: col,
|
|
CollectorSet: colupdate,
|
|
Client: cli,
|
|
ClientUpdate: cliUpdate,
|
|
Document: doc,
|
|
DocumentUpload: docup,
|
|
DocumentBatch: docbatch,
|
|
UISettings: uiSvc,
|
|
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)
|
|
}
|
|
|
|
// Create Cognito SDK client for environment attribute registration and middleware use.
|
|
// This client is created once and reused for the lifetime of the process.
|
|
awsCfg, err := awsc.GetAWSConfig(ctx)
|
|
if err != nil {
|
|
slog.Error("Failed to load AWS config for Cognito client", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
cognitoClient := cognitoidentityprovider.NewFromConfig(awsCfg)
|
|
|
|
// Ensure the custom:environment_id attribute is registered on the Cognito user pool.
|
|
// This is safe to call on every startup (idempotent). Failure is non-fatal because
|
|
// the attribute may already exist or the environment may not support this API (e.g. LocalStack).
|
|
if err := usermanagement.EnsureEnvironmentIDAttribute(ctx, cognitoClient, cfg.GetAuthUserPoolID(), cfg.GetLogger()); err != nil {
|
|
cfg.GetLogger().Warn("Failed to ensure Cognito environment_id attribute", "error", err)
|
|
} else {
|
|
cfg.GetLogger().Info("Cognito custom attribute custom:environment_id is registered")
|
|
}
|
|
|
|
// 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()
|
|
}
|