Rename info -> admin
This commit is contained in:
parent
785130dc36
commit
11f7749c1d
10 changed files with 55 additions and 55 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
package info
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Info struct {
|
type Admin struct {
|
||||||
component.Base
|
component.Base
|
||||||
Dependencies struct {
|
Dependencies struct {
|
||||||
Fetchers []component.DistilleryFetcher
|
Fetchers []component.DistilleryFetcher
|
||||||
|
|
@ -31,13 +31,13 @@ type Info struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ component.DistilleryFetcher = (*Info)(nil)
|
_ component.DistilleryFetcher = (*Admin)(nil)
|
||||||
_ component.Routeable = (*Info)(nil)
|
_ component.Routeable = (*Admin)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (*Info) Routes() []string { return []string{"/admin/"} }
|
func (*Admin) Routes() []string { return []string{"/admin/"} }
|
||||||
|
|
||||||
func (info *Info) HandleRoute(ctx context.Context, route string) (handler http.Handler, err error) {
|
func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http.Handler, err error) {
|
||||||
|
|
||||||
router := httprouter.New()
|
router := httprouter.New()
|
||||||
|
|
||||||
|
|
@ -45,9 +45,9 @@ func (info *Info) HandleRoute(ctx context.Context, route string) (handler http.H
|
||||||
socket := &httpx.WebSocket{
|
socket := &httpx.WebSocket{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
Fallback: router,
|
Fallback: router,
|
||||||
Handler: info.serveSocket,
|
Handler: admin.serveSocket,
|
||||||
}
|
}
|
||||||
handler = info.Dependencies.Auth.Protect(socket, auth.Admin)
|
handler = admin.Dependencies.Auth.Protect(socket, auth.Admin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle everything
|
// handle everything
|
||||||
|
|
@ -57,25 +57,25 @@ func (info *Info) HandleRoute(ctx context.Context, route string) (handler http.H
|
||||||
|
|
||||||
// add a handler for the index page
|
// add a handler for the index page
|
||||||
router.Handler(http.MethodGet, route+"index", httpx.HTMLHandler[indexContext]{
|
router.Handler(http.MethodGet, route+"index", httpx.HTMLHandler[indexContext]{
|
||||||
Handler: info.index,
|
Handler: admin.index,
|
||||||
Template: indexTemplate,
|
Template: indexTemplate,
|
||||||
})
|
})
|
||||||
|
|
||||||
// add a handler for the component page
|
// add a handler for the component page
|
||||||
router.Handler(http.MethodGet, route+"components", httpx.HTMLHandler[componentContext]{
|
router.Handler(http.MethodGet, route+"components", httpx.HTMLHandler[componentContext]{
|
||||||
Handler: info.components,
|
Handler: admin.components,
|
||||||
Template: componentsTemplate,
|
Template: componentsTemplate,
|
||||||
})
|
})
|
||||||
|
|
||||||
// add a handler for the component page
|
// add a handler for the component page
|
||||||
router.Handler(http.MethodGet, route+"ingredients/:slug", httpx.HTMLHandler[ingredientsContext]{
|
router.Handler(http.MethodGet, route+"ingredients/:slug", httpx.HTMLHandler[ingredientsContext]{
|
||||||
Handler: info.ingredients,
|
Handler: admin.ingredients,
|
||||||
Template: ingredientsTemplate,
|
Template: ingredientsTemplate,
|
||||||
})
|
})
|
||||||
|
|
||||||
// add a handler for the instance page
|
// add a handler for the instance page
|
||||||
router.Handler(http.MethodGet, route+"instance/:slug", httpx.HTMLHandler[instanceContext]{
|
router.Handler(http.MethodGet, route+"instance/:slug", httpx.HTMLHandler[instanceContext]{
|
||||||
Handler: info.instance,
|
Handler: admin.instance,
|
||||||
Template: instanceTemplate,
|
Template: instanceTemplate,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -86,7 +86,7 @@ func (info *Info) HandleRoute(ctx context.Context, route string) (handler http.H
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the instance
|
// get the instance
|
||||||
instance, err := info.Dependencies.Instances.WissKI(r.Context(), r.PostFormValue("slug"))
|
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), r.PostFormValue("slug"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, httpx.ErrNotFound
|
return "", 0, httpx.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package info
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -27,8 +27,8 @@ type componentContext struct {
|
||||||
Analytics lazy.PoolAnalytics
|
Analytics lazy.PoolAnalytics
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *Info) components(r *http.Request) (cp componentContext, err error) {
|
func (admin *Admin) components(r *http.Request) (cp componentContext, err error) {
|
||||||
cp.Analytics = *info.Analytics
|
cp.Analytics = *admin.Analytics
|
||||||
cp.Time = time.Now().UTC()
|
cp.Time = time.Now().UTC()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -48,11 +48,11 @@ type ingredientsContext struct {
|
||||||
Analytics *lazy.PoolAnalytics
|
Analytics *lazy.PoolAnalytics
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *Info) ingredients(r *http.Request) (cp ingredientsContext, err error) {
|
func (admin *Admin) ingredients(r *http.Request) (cp ingredientsContext, err error) {
|
||||||
cp.Time = time.Now().UTC()
|
cp.Time = time.Now().UTC()
|
||||||
|
|
||||||
// find the instance itself!
|
// find the instance itself!
|
||||||
instance, err := info.Dependencies.Instances.WissKI(r.Context(), mux.Vars(r)["slug"])
|
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), mux.Vars(r)["slug"])
|
||||||
if err == instances.ErrWissKINotFound {
|
if err == instances.ErrWissKINotFound {
|
||||||
return cp, httpx.ErrNotFound
|
return cp, httpx.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package info
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -20,24 +20,14 @@ var indexTemplate = static.AssetsControlIndex.MustParseShared(
|
||||||
indexTemplateStr,
|
indexTemplateStr,
|
||||||
)
|
)
|
||||||
|
|
||||||
type indexContext struct {
|
|
||||||
status.Distillery
|
|
||||||
Instances []status.WissKI
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *Info) index(r *http.Request) (idx indexContext, err error) {
|
|
||||||
idx.Distillery, idx.Instances, err = info.Status(r.Context(), true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Status produces a new observation of the distillery, and a new information of all instances
|
// Status produces a new observation of the distillery, and a new information of all instances
|
||||||
// The information on all instances is passed the given quick flag.
|
// The information on all instances is passed the given quick flag.
|
||||||
func (info *Info) Status(ctx context.Context, QuickInformation bool) (target status.Distillery, information []status.WissKI, err error) {
|
func (admin *Admin) Status(ctx context.Context, QuickInformation bool) (target status.Distillery, information []status.WissKI, err error) {
|
||||||
var group errgroup.Group
|
var group errgroup.Group
|
||||||
|
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
// list all the instances
|
// list all the instances
|
||||||
all, err := info.Dependencies.Instances.All(ctx)
|
all, err := admin.Dependencies.Instances.All(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +53,7 @@ func (info *Info) Status(ctx context.Context, QuickInformation bool) (target sta
|
||||||
flags := component.FetcherFlags{
|
flags := component.FetcherFlags{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
for _, o := range info.Dependencies.Fetchers {
|
for _, o := range admin.Dependencies.Fetchers {
|
||||||
o := o
|
o := o
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
return o.Fetch(flags, &target)
|
return o.Fetch(flags, &target)
|
||||||
|
|
@ -88,8 +78,18 @@ func (info *Info) Status(ctx context.Context, QuickInformation bool) (target sta
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nfo *Info) Fetch(flags component.FetcherFlags, target *status.Distillery) error {
|
type indexContext struct {
|
||||||
|
status.Distillery
|
||||||
|
Instances []status.WissKI
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *Admin) index(r *http.Request) (idx indexContext, err error) {
|
||||||
|
idx.Distillery, idx.Instances, err = admin.Status(r.Context(), true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *Admin) Fetch(flags component.FetcherFlags, target *status.Distillery) error {
|
||||||
target.Time = time.Now().UTC()
|
target.Time = time.Now().UTC()
|
||||||
target.Config = nfo.Config
|
target.Config = admin.Config
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package info
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
|
@ -27,9 +27,9 @@ type instanceContext struct {
|
||||||
Info status.WissKI
|
Info status.WissKI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *Info) instance(r *http.Request) (is instanceContext, err error) {
|
func (admin *Admin) instance(r *http.Request) (is instanceContext, err error) {
|
||||||
// find the instance itself!
|
// find the instance itself!
|
||||||
instance, err := info.Dependencies.Instances.WissKI(r.Context(), mux.Vars(r)["slug"])
|
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), mux.Vars(r)["slug"])
|
||||||
if err == instances.ErrWissKINotFound {
|
if err == instances.ErrWissKINotFound {
|
||||||
return is, httpx.ErrNotFound
|
return is, httpx.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package info
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -16,13 +16,13 @@ import (
|
||||||
type InstanceAction struct {
|
type InstanceAction struct {
|
||||||
NumParams int
|
NumParams int
|
||||||
|
|
||||||
HandleInteractive func(ctx context.Context, info *Info, instance *wisski.WissKI, out io.Writer, params ...string) error
|
HandleInteractive func(ctx context.Context, info *Admin, instance *wisski.WissKI, out io.Writer, params ...string) error
|
||||||
HandleResult func(ctx context.Context, info *Info, instance *wisski.WissKI, params ...string) (value any, err error)
|
HandleResult func(ctx context.Context, info *Admin, instance *wisski.WissKI, params ...string) (value any, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
var socketInstanceActions = map[string]InstanceAction{
|
var socketInstanceActions = map[string]InstanceAction{
|
||||||
"snapshot": {
|
"snapshot": {
|
||||||
HandleInteractive: func(ctx context.Context, info *Info, instance *wisski.WissKI, out io.Writer, params ...string) error {
|
HandleInteractive: func(ctx context.Context, info *Admin, instance *wisski.WissKI, out io.Writer, params ...string) error {
|
||||||
return info.Dependencies.Exporter.MakeExport(
|
return info.Dependencies.Exporter.MakeExport(
|
||||||
ctx,
|
ctx,
|
||||||
out,
|
out,
|
||||||
|
|
@ -36,23 +36,23 @@ var socketInstanceActions = map[string]InstanceAction{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"rebuild": {
|
"rebuild": {
|
||||||
HandleInteractive: func(ctx context.Context, _ *Info, instance *wisski.WissKI, out io.Writer, params ...string) error {
|
HandleInteractive: func(ctx context.Context, _ *Admin, instance *wisski.WissKI, out io.Writer, params ...string) error {
|
||||||
return instance.Barrel().Build(ctx, out, true)
|
return instance.Barrel().Build(ctx, out, true)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"update": {
|
"update": {
|
||||||
HandleInteractive: func(ctx context.Context, _ *Info, instance *wisski.WissKI, out io.Writer, params ...string) error {
|
HandleInteractive: func(ctx context.Context, _ *Admin, instance *wisski.WissKI, out io.Writer, params ...string) error {
|
||||||
return instance.Drush().Update(ctx, out)
|
return instance.Drush().Update(ctx, out)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"cron": {
|
"cron": {
|
||||||
HandleInteractive: func(ctx context.Context, _ *Info, instance *wisski.WissKI, str io.Writer, params ...string) error {
|
HandleInteractive: func(ctx context.Context, _ *Admin, instance *wisski.WissKI, str io.Writer, params ...string) error {
|
||||||
return instance.Drush().Cron(ctx, str)
|
return instance.Drush().Cron(ctx, str)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *Info) serveSocket(conn httpx.WebSocketConnection) {
|
func (admin *Admin) serveSocket(conn httpx.WebSocketConnection) {
|
||||||
// read the next message to act on
|
// read the next message to act on
|
||||||
message, ok := <-conn.Read()
|
message, ok := <-conn.Read()
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -61,14 +61,14 @@ func (info *Info) serveSocket(conn httpx.WebSocketConnection) {
|
||||||
|
|
||||||
// perform an action if it exists!
|
// perform an action if it exists!
|
||||||
if action, ok := socketInstanceActions[string(message.Bytes)]; ok {
|
if action, ok := socketInstanceActions[string(message.Bytes)]; ok {
|
||||||
info.handleInstanceAction(conn, action)
|
admin.handleInstanceAction(conn, action)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var instanceParamsTimeout = time.Second
|
var instanceParamsTimeout = time.Second
|
||||||
|
|
||||||
func (info *Info) handleInstanceAction(conn httpx.WebSocketConnection, action InstanceAction) {
|
func (admin *Admin) handleInstanceAction(conn httpx.WebSocketConnection, action InstanceAction) {
|
||||||
|
|
||||||
// read the slug
|
// read the slug
|
||||||
slug, ok := <-conn.Read()
|
slug, ok := <-conn.Read()
|
||||||
|
|
@ -78,7 +78,7 @@ func (info *Info) handleInstanceAction(conn httpx.WebSocketConnection, action In
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve the instance
|
// resolve the instance
|
||||||
instance, err := info.Dependencies.Instances.WissKI(conn.Context(), string(slug.Bytes))
|
instance, err := admin.Dependencies.Instances.WissKI(conn.Context(), string(slug.Bytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
<-conn.WriteText("Instance not found")
|
<-conn.WriteText("Instance not found")
|
||||||
return
|
return
|
||||||
|
|
@ -111,7 +111,7 @@ func (info *Info) handleInstanceAction(conn httpx.WebSocketConnection, action In
|
||||||
|
|
||||||
// handle the interactive action
|
// handle the interactive action
|
||||||
if action.HandleInteractive != nil {
|
if action.HandleInteractive != nil {
|
||||||
err := action.HandleInteractive(conn.Context(), info, instance, writer, params...)
|
err := action.HandleInteractive(conn.Context(), admin, instance, writer, params...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(writer, err)
|
fmt.Fprintln(writer, err)
|
||||||
return
|
return
|
||||||
|
|
@ -121,7 +121,7 @@ func (info *Info) handleInstanceAction(conn httpx.WebSocketConnection, action In
|
||||||
|
|
||||||
// handle the result computation
|
// handle the result computation
|
||||||
if action.HandleResult != nil {
|
if action.HandleResult != nil {
|
||||||
result, err := action.HandleResult(conn.Context(), info, instance, params...)
|
result, err := action.HandleResult(conn.Context(), admin, instance, params...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(writer, "false")
|
fmt.Fprintln(writer, "false")
|
||||||
return
|
return
|
||||||
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth/policy"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth/policy"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control"
|
||||||
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/admin"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/cron"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/cron"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/home"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/home"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/info"
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter/logger"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter/logger"
|
||||||
|
|
@ -100,8 +100,8 @@ func (dis *Distillery) Updatable() []component.Updatable {
|
||||||
func (dis *Distillery) Provisionable() []component.Provisionable {
|
func (dis *Distillery) Provisionable() []component.Provisionable {
|
||||||
return exportAll[component.Provisionable](dis)
|
return exportAll[component.Provisionable](dis)
|
||||||
}
|
}
|
||||||
func (dis *Distillery) Info() *info.Info {
|
func (dis *Distillery) Info() *admin.Admin {
|
||||||
return export[*info.Info](dis)
|
return export[*admin.Admin](dis)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -153,8 +153,8 @@ func (dis *Distillery) allComponents() []initFunc {
|
||||||
manual(func(resolver *resolver.Resolver) {
|
manual(func(resolver *resolver.Resolver) {
|
||||||
resolver.RefreshInterval = time.Minute
|
resolver.RefreshInterval = time.Minute
|
||||||
}),
|
}),
|
||||||
manual(func(info *info.Info) {
|
manual(func(admin *admin.Admin) {
|
||||||
info.Analytics = &dis.pool.Analytics
|
admin.Analytics = &dis.pool.Analytics
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Cron
|
// Cron
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue