Add a form to provision a new instance
This commit is contained in:
parent
80906d3791
commit
53f63d4efd
25 changed files with 367 additions and 236 deletions
|
|
@ -70,7 +70,9 @@ var (
|
|||
menuUsers = component.MenuItem{Title: "Users", Path: "/admin/users/"}
|
||||
menuUserCreate = component.MenuItem{Title: "Create User", Path: "/admin/users/create/"}
|
||||
|
||||
menuInstances = component.MenuItem{Title: "Instances", Path: "/admin/instance/"}
|
||||
menuProvision = component.MenuItem{Title: "Provision", Path: "/admin/instances/provision/"}
|
||||
|
||||
menuInstances = component.MenuItem{Title: "Instances", Path: "/admin/instances/"}
|
||||
menuInstance = component.DummyMenuItem()
|
||||
menuGrants = component.DummyMenuItem()
|
||||
menuIngredients = component.DummyMenuItem()
|
||||
|
|
@ -94,10 +96,13 @@ func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http
|
|||
router.Handler(http.MethodGet, route, index)
|
||||
}
|
||||
|
||||
// add a handler for the instances page
|
||||
// add a handler for the instances (and provision) page
|
||||
{
|
||||
instances := admin.instances(ctx)
|
||||
router.Handler(http.MethodGet, route+"instance/", instances)
|
||||
router.Handler(http.MethodGet, route+"instances/", instances)
|
||||
|
||||
provision := admin.instanceProvision(ctx)
|
||||
router.Handler(http.MethodGet, route+"instances/provision", provision)
|
||||
}
|
||||
|
||||
// add a handler for the user page
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
<div class="pure-u-1-1">
|
||||
<form class="pure-form pure-form-aligned" id="provision">
|
||||
<fieldset disabled="disabled">
|
||||
<div class="pure-control-group">
|
||||
<label for="slug">Slug</label>
|
||||
<input name="slug" id="slug" placeholder="" autocomplete="slug">
|
||||
</div>
|
||||
<input type="submit" value="Provision" class="pure-button">
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
|
@ -130,6 +130,9 @@ func (admin *Admin) instances(ctx context.Context) http.Handler {
|
|||
menuAdmin,
|
||||
menuInstances,
|
||||
),
|
||||
templating.Actions(
|
||||
menuProvision,
|
||||
),
|
||||
)
|
||||
|
||||
return tpl.HTMLHandler(func(r *http.Request) (idx indexContext, err error) {
|
||||
|
|
|
|||
42
internal/dis/component/server/admin/instance_provision.go
Normal file
42
internal/dis/component/server/admin/instance_provision.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed "html/instance_provision.html"
|
||||
var instanceProvisionHTML []byte
|
||||
var instanceProvisionTemplate = templating.Parse[instanceProvisionContext](
|
||||
"instance_provision.html", instanceProvisionHTML, nil,
|
||||
|
||||
templating.Title("Provision New Instance"),
|
||||
templating.Assets(assets.AssetsAdminProvision),
|
||||
)
|
||||
|
||||
type instanceProvisionContext struct {
|
||||
templating.RuntimeFlags
|
||||
|
||||
// nothing for the moment
|
||||
}
|
||||
|
||||
func (admin *Admin) instanceProvision(ctx context.Context) http.Handler {
|
||||
tpl := instanceProvisionTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
|
||||
templating.Crumbs(
|
||||
menuAdmin,
|
||||
menuInstances,
|
||||
menuProvision,
|
||||
),
|
||||
)
|
||||
|
||||
return tpl.HTMLHandler(func(r *http.Request) (ipc instanceProvisionContext, err error) {
|
||||
return ipc, nil
|
||||
})
|
||||
}
|
||||
|
|
@ -2,9 +2,12 @@ package socket
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/provision"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
)
|
||||
|
||||
|
|
@ -24,6 +27,32 @@ var actions = map[string]SocketAction{
|
|||
)
|
||||
},
|
||||
},
|
||||
"provision": {
|
||||
NumParams: 1,
|
||||
HandleInteractive: func(ctx context.Context, sockets *Sockets, out io.Writer, params ...string) error {
|
||||
|
||||
// read the flags of the instance to be provisioned
|
||||
var flags provision.ProvisionFlags
|
||||
if err := json.Unmarshal([]byte(params[0]), &flags); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
instance, err := sockets.Dependencies.Provision.Provision(
|
||||
out,
|
||||
ctx,
|
||||
flags,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "URL: %s\n", instance.URL().String())
|
||||
fmt.Fprintf(out, "Username: %s\n", instance.DrupalUsername)
|
||||
fmt.Fprintf(out, "Password: %s\n", instance.DrupalPassword)
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// socket specific actions
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances/purger"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/provision"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"github.com/tkw1536/goprogram/status"
|
||||
"github.com/tkw1536/pkglib/httpx"
|
||||
|
|
@ -19,6 +20,7 @@ type Sockets struct {
|
|||
component.Base
|
||||
|
||||
Dependencies struct {
|
||||
Provision *provision.Provision
|
||||
Instances *instances.Instances
|
||||
Exporter *exporter.Exporter
|
||||
Purger *purger.Purger
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue