Implement authorization import and revocation checks (T-503)

This commit is contained in:
ila
2026-07-20 09:07:30 +08:00
parent b4453130de
commit 76f6108496
36 changed files with 2197 additions and 68 deletions
+58 -4
View File
@@ -35,10 +35,28 @@ func main() {
}
func run() error {
return runWithCatalogLoader(application.UnconfiguredCatalogLoader{})
return runWithLoaders(
application.UnconfiguredCatalogLoader{},
application.UnconfiguredAuthorizationLoader{},
)
}
func runWithCatalogLoader(loader application.CatalogSnapshotLoader) error {
return runWithLoaders(loader, application.UnconfiguredAuthorizationLoader{})
}
func runWithLoaders(
loader application.CatalogSnapshotLoader,
authorizationLoader application.AuthorizationSnapshotLoader,
) error {
return runWithCompositions(loader, authorizationLoader, nil)
}
func runWithCompositions(
loader application.CatalogSnapshotLoader,
authorizationLoader application.AuthorizationSnapshotLoader,
licenseImport *application.LicenseImport,
) error {
platform := windows.New()
window := new(app.Window)
window.Option(
@@ -64,6 +82,7 @@ func runWithCatalogLoader(loader application.CatalogSnapshotLoader) error {
)
}()
catalogDone := startCatalogBootstrap(eventContext, runtime, loader)
authorizationDone := startAuthorizationBootstrap(eventContext, runtime, authorizationLoader)
defer func() {
cancelEvents()
runtime.Close()
@@ -75,6 +94,13 @@ func runWithCatalogLoader(loader application.CatalogSnapshotLoader) error {
!errors.Is(bootstrapErr, application.ErrEventRelayClosed) {
log.Printf("%s catalog bootstrap failed", core.ProductName)
}
if authorizationErr := <-authorizationDone; authorizationErr != nil &&
!errors.Is(authorizationErr, context.Canceled) &&
!errors.Is(authorizationErr, application.ErrAuthorizationSourceUnconfigured) &&
!errors.Is(authorizationErr, application.ErrRuntimeClosed) &&
!errors.Is(authorizationErr, application.ErrEventRelayClosed) {
log.Printf("%s authorization bootstrap failed", core.ProductName)
}
if pumpErr := <-pumpDone; pumpErr != nil &&
!errors.Is(pumpErr, context.Canceled) &&
!errors.Is(pumpErr, application.ErrEventRelayClosed) {
@@ -82,6 +108,7 @@ func runWithCatalogLoader(loader application.CatalogSnapshotLoader) error {
}
}()
var operations op.Ops
importing := make(chan struct{}, 1)
for {
switch event := window.Event().(type) {
@@ -91,9 +118,24 @@ func runWithCatalogLoader(loader application.CatalogSnapshotLoader) error {
if err := relay.Drain(shell.ApplyEvent); err != nil {
log.Printf("apply application event: %v", err)
}
context := app.NewContext(&operations, event)
shell.Layout(context, theme)
event.Frame(context.Ops)
gtx := app.NewContext(&operations, event)
shell.Layout(gtx, theme)
if shell.TakeLicenseImportRequest() && licenseImport != nil {
select {
case importing <- struct{}{}:
go func() {
defer func() { <-importing }()
if importErr := licenseImport.Run(eventContext); importErr != nil &&
!errors.Is(importErr, context.Canceled) &&
!errors.Is(importErr, application.ErrRuntimeClosed) &&
!errors.Is(importErr, application.ErrEventRelayClosed) {
log.Printf("%s license import failed", core.ProductName)
}
}()
default:
}
}
event.Frame(gtx.Ops)
}
}
}
@@ -109,3 +151,15 @@ func startCatalogBootstrap(
}()
return done
}
func startAuthorizationBootstrap(
ctx context.Context,
runtime *application.Runtime,
loader application.AuthorizationSnapshotLoader,
) <-chan error {
done := make(chan error, 1)
go func() {
done <- application.NewAuthorizationBootstrap(loader, runtime).Run(ctx)
}()
return done
}