Implement authorization import and revocation checks (T-503)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user