internal/component: Check for provisionable
This commit is contained in:
parent
5053c982aa
commit
2a308ee03c
6 changed files with 24 additions and 20 deletions
1
go.mod
1
go.mod
|
|
@ -11,6 +11,7 @@ require (
|
||||||
github.com/go-sql-driver/mysql v1.6.0
|
github.com/go-sql-driver/mysql v1.6.0
|
||||||
github.com/gorilla/mux v1.8.0
|
github.com/gorilla/mux v1.8.0
|
||||||
github.com/gorilla/websocket v1.5.0
|
github.com/gorilla/websocket v1.5.0
|
||||||
|
github.com/julienschmidt/httprouter v1.3.0
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/rs/zerolog v1.28.0
|
github.com/rs/zerolog v1.28.0
|
||||||
github.com/tkw1536/goprogram v0.2.4
|
github.com/tkw1536/goprogram v0.2.4
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -27,6 +27,8 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr
|
||||||
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
|
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
|
||||||
|
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||||
"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"
|
||||||
"github.com/gorilla/mux"
|
"github.com/julienschmidt/httprouter"
|
||||||
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||||
|
|
@ -33,7 +33,7 @@ var (
|
||||||
func (*Info) Routes() []string { return []string{"/dis/"} }
|
func (*Info) Routes() []string { return []string{"/dis/"} }
|
||||||
|
|
||||||
func (info *Info) Handler(ctx context.Context, route string) (handler http.Handler, err error) {
|
func (info *Info) Handler(ctx context.Context, route string) (handler http.Handler, err error) {
|
||||||
router := mux.NewRouter()
|
router := httprouter.New()
|
||||||
{
|
{
|
||||||
socket := &httpx.WebSocket{
|
socket := &httpx.WebSocket{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
|
|
@ -46,40 +46,35 @@ func (info *Info) Handler(ctx context.Context, route string) (handler http.Handl
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle everything
|
// handle everything
|
||||||
router.Path(route).HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
router.HandlerFunc(http.MethodGet, route, func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, route+"/index", http.StatusTemporaryRedirect)
|
http.Redirect(w, r, "index", http.StatusTemporaryRedirect)
|
||||||
})
|
})
|
||||||
|
|
||||||
// add a handler for the index page
|
// add a handler for the index page
|
||||||
router.Path(route + "index").Handler(httpx.HTMLHandler[indexContext]{
|
router.Handler(http.MethodGet, "index", httpx.HTMLHandler[indexContext]{
|
||||||
Handler: info.index,
|
Handler: info.index,
|
||||||
Template: indexTemplate,
|
Template: indexTemplate,
|
||||||
})
|
})
|
||||||
|
|
||||||
// add a handler for the component page
|
// add a handler for the component page
|
||||||
router.Path(route + "components").Handler(httpx.HTMLHandler[componentContext]{
|
router.Handler(http.MethodGet, "components", httpx.HTMLHandler[componentContext]{
|
||||||
Handler: info.components,
|
Handler: info.components,
|
||||||
Template: componentsTemplate,
|
Template: componentsTemplate,
|
||||||
})
|
})
|
||||||
|
|
||||||
// add a handler for the component page
|
// add a handler for the component page
|
||||||
router.Path(route + "ingredients/{slug}").Handler(httpx.HTMLHandler[ingredientsContext]{
|
router.Handler(http.MethodGet, "ingredients/{slug}", httpx.HTMLHandler[ingredientsContext]{
|
||||||
Handler: info.ingredients,
|
Handler: info.ingredients,
|
||||||
Template: ingredientsTemplate,
|
Template: ingredientsTemplate,
|
||||||
})
|
})
|
||||||
|
|
||||||
// add a handler for the instance page
|
// add a handler for the instance page
|
||||||
router.Path(route + "instance/{slug}").Handler(httpx.HTMLHandler[instanceContext]{
|
router.Handler(http.MethodGet, "instance/{slug}", httpx.HTMLHandler[instanceContext]{
|
||||||
Handler: info.instance,
|
Handler: info.instance,
|
||||||
Template: instanceTemplate,
|
Template: instanceTemplate,
|
||||||
})
|
})
|
||||||
|
|
||||||
router.Path(route + "api/login").Handler(httpx.RedirectHandler(func(r *http.Request) (string, int, error) {
|
router.Handler(http.MethodPost, "api/login", httpx.RedirectHandler(func(r *http.Request) (string, int, error) {
|
||||||
// enforce POST
|
|
||||||
if r.Method != http.MethodPost {
|
|
||||||
return "", 0, httpx.ErrMethodNotAllowed
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse the form
|
// parse the form
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ type Meta struct {
|
||||||
sc map[string]*Storage
|
sc map[string]*Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ component.Provisionable = (*Meta)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
// Storage returns a Storage for the instance with the given slug.
|
// Storage returns a Storage for the instance with the given slug.
|
||||||
// When slug is nil, returns a global storage.
|
// When slug is nil, returns a global storage.
|
||||||
func (meta *Meta) Storage(slug string) *Storage {
|
func (meta *Meta) Storage(slug string) *Storage {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ var (
|
||||||
_ component.Backupable = (*SQL)(nil)
|
_ component.Backupable = (*SQL)(nil)
|
||||||
_ component.Snapshotable = (*SQL)(nil)
|
_ component.Snapshotable = (*SQL)(nil)
|
||||||
_ component.Installable = (*SQL)(nil)
|
_ component.Installable = (*SQL)(nil)
|
||||||
|
_ component.Provisionable = (*SQL)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (sql *SQL) Path() string {
|
func (sql *SQL) Path() string {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ var (
|
||||||
_ component.Backupable = (*Triplestore)(nil)
|
_ component.Backupable = (*Triplestore)(nil)
|
||||||
_ component.Snapshotable = (*Triplestore)(nil)
|
_ component.Snapshotable = (*Triplestore)(nil)
|
||||||
_ component.Installable = (*Triplestore)(nil)
|
_ component.Installable = (*Triplestore)(nil)
|
||||||
|
_ component.Provisionable = (*Triplestore)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ts *Triplestore) Path() string {
|
func (ts *Triplestore) Path() string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue