Use embed.fs for self-contained build
This commit is contained in:
parent
0effaaa586
commit
695f5cae6b
12 changed files with 47 additions and 19 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,8 @@
|
||||||
.idea/
|
.idea/
|
||||||
/cacert-idp
|
/cacert-idp
|
||||||
/static
|
/static
|
||||||
|
/ui/css/
|
||||||
|
/ui/images/
|
||||||
|
/ui/js/
|
||||||
certs/
|
certs/
|
||||||
idp.toml
|
idp.toml
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -1,9 +1,19 @@
|
||||||
GOFILES = $(wildcard */*.go)
|
GOFILES = $(wildcard */*.go)
|
||||||
TEMPLATES = $(wildcard templates/*.gohtml)
|
TEMPLATES = $(wildcard ui/templates/*.gohtml)
|
||||||
TRANSLATIONS = $(wildcard active.*.toml)
|
TRANSLATIONS = $(wildcard active.*.toml)
|
||||||
|
RESOURCES = ui/css ui/images ui/js
|
||||||
|
|
||||||
all: cacert-idp
|
all: cacert-idp
|
||||||
|
|
||||||
|
ui/css: ../cacert_resources/static/css
|
||||||
|
cp -r ../cacert_resources/static/css ui/
|
||||||
|
|
||||||
|
ui/js: ../cacert_resources/static/js
|
||||||
|
cp -r ../cacert_resources/static/js ui/
|
||||||
|
|
||||||
|
ui/images: ../cacert_resources/static/images
|
||||||
|
cp -r ../cacert_resources/static/images ui/
|
||||||
|
|
||||||
go.sum: go.mod
|
go.sum: go.mod
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
|
@ -15,11 +25,11 @@ translations: $(TRANSLATIONS) $(GOFILES)
|
||||||
goi18n merge active.*.toml translate.*.toml; \
|
goi18n merge active.*.toml translate.*.toml; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cacert-idp: go.sum $(GOFILES) $(TEMPLATES) translations
|
cacert-idp: go.sum $(GOFILES) $(TEMPLATES) translations $(RESOURCES)
|
||||||
CGO_ENABLED=0 go build -o $@ ./cmd/idp.go
|
CGO_ENABLED=0 go build -o $@ ./cmd/idp.go
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f cacert-idp
|
rm -rf cacert-idp ui/css ui/js ui/images
|
||||||
|
|
||||||
.PHONY: all translations clean
|
.PHONY: all translations clean
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.cacert.org/oidc_idp/ui"
|
||||||
"github.com/go-openapi/runtime/client"
|
"github.com/go-openapi/runtime/client"
|
||||||
"github.com/gorilla/csrf"
|
"github.com/gorilla/csrf"
|
||||||
"github.com/knadh/koanf"
|
"github.com/knadh/koanf"
|
||||||
|
@ -103,7 +104,7 @@ func main() {
|
||||||
logoutHandler := handlers.NewLogoutHandler(handlerContext, logger)
|
logoutHandler := handlers.NewLogoutHandler(handlerContext, logger)
|
||||||
logoutSuccessHandler := handlers.NewLogoutSuccessHandler()
|
logoutSuccessHandler := handlers.NewLogoutSuccessHandler()
|
||||||
errorHandler := handlers.NewErrorHandler()
|
errorHandler := handlers.NewErrorHandler()
|
||||||
staticFiles := http.FileServer(http.Dir("static"))
|
staticFiles := http.FileServer(http.FS(ui.Static))
|
||||||
|
|
||||||
router := http.NewServeMux()
|
router := http.NewServeMux()
|
||||||
router.Handle("/login", loginHandler)
|
router.Handle("/login", loginHandler)
|
||||||
|
@ -140,7 +141,7 @@ func main() {
|
||||||
errorMiddleware, err := handlers.ErrorHandling(
|
errorMiddleware, err := handlers.ErrorHandling(
|
||||||
ctx,
|
ctx,
|
||||||
logger,
|
logger,
|
||||||
"templates",
|
ui.Templates,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf("could not initialize request error handling: %v", err)
|
logger.Fatalf("could not initialize request error handling: %v", err)
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
commonModels "git.cacert.org/oidc_idp/models"
|
commonModels "git.cacert.org/oidc_idp/models"
|
||||||
|
"git.cacert.org/oidc_idp/ui"
|
||||||
"github.com/go-playground/form/v4"
|
"github.com/go-playground/form/v4"
|
||||||
"github.com/gorilla/csrf"
|
"github.com/gorilla/csrf"
|
||||||
"github.com/lestrrat-go/jwx/jwt/openid"
|
"github.com/lestrrat-go/jwx/jwt/openid"
|
||||||
|
@ -430,8 +431,12 @@ func (h *consentHandler) GetUserInfoFromClientCertificate(r *http.Request, subje
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConsentHandler(ctx context.Context, logger *log.Logger) (*consentHandler, error) {
|
func NewConsentHandler(ctx context.Context, logger *log.Logger) (*consentHandler, error) {
|
||||||
consentTemplate := template.Must(template.ParseFiles(
|
consentTemplate := template.Must(
|
||||||
"templates/base.gohtml", "templates/consent.gohtml"))
|
template.ParseFS(
|
||||||
|
ui.Templates,
|
||||||
|
"templates/base.gohtml",
|
||||||
|
"templates/consent.gohtml",
|
||||||
|
))
|
||||||
|
|
||||||
return &consentHandler{
|
return &consentHandler{
|
||||||
adminClient: ctx.Value(CtxAdminClient).(*admin.Client),
|
adminClient: ctx.Value(CtxAdminClient).(*admin.Client),
|
||||||
|
|
|
@ -21,8 +21,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
|
||||||
|
|
||||||
"git.cacert.org/oidc_idp/services"
|
"git.cacert.org/oidc_idp/services"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
|
@ -118,14 +118,11 @@ func (w *errorResponseWriter) Write(content []byte) (int, error) {
|
||||||
return w.ResponseWriter.Write(content)
|
return w.ResponseWriter.Write(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrorHandling(
|
func ErrorHandling(handlerContext context.Context, logger *log.Logger, templateFS fs.FS) (func(http.Handler) http.Handler, error) {
|
||||||
handlerContext context.Context,
|
errorTemplates, err := template.ParseFS(
|
||||||
logger *log.Logger,
|
templateFS,
|
||||||
templateBaseDir string,
|
"templates/base.gohtml",
|
||||||
) (func(http.Handler) http.Handler, error) {
|
"templates/errors.gohtml",
|
||||||
errorTemplates, err := template.ParseFiles(
|
|
||||||
path.Join(templateBaseDir, "base.gohtml"),
|
|
||||||
path.Join(templateBaseDir, "errors.gohtml"),
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.cacert.org/oidc_idp/ui"
|
||||||
"github.com/gorilla/csrf"
|
"github.com/gorilla/csrf"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"github.com/ory/hydra-client-go/client/admin"
|
"github.com/ory/hydra-client-go/client/admin"
|
||||||
|
@ -237,11 +238,13 @@ func NewLoginHandler(ctx context.Context, logger *log.Logger) (*loginHandler, er
|
||||||
context: ctx,
|
context: ctx,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
templates: map[templateName]*template.Template{
|
templates: map[templateName]*template.Template{
|
||||||
CertificateLogin: template.Must(template.ParseFiles(
|
CertificateLogin: template.Must(template.ParseFS(
|
||||||
|
ui.Templates,
|
||||||
"templates/base.gohtml",
|
"templates/base.gohtml",
|
||||||
"templates/client_certificate.gohtml",
|
"templates/client_certificate.gohtml",
|
||||||
)),
|
)),
|
||||||
NoEmailsInClientCertificate: template.Must(template.ParseFiles(
|
NoEmailsInClientCertificate: template.Must(template.ParseFS(
|
||||||
|
ui.Templates,
|
||||||
"templates/base.gohtml",
|
"templates/base.gohtml",
|
||||||
"templates/no_email_in_client_certificate.gohtml",
|
"templates/no_email_in_client_certificate.gohtml",
|
||||||
)),
|
)),
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
</main>
|
</main>
|
||||||
<footer class="footer mt-auto py-3">
|
<footer class="footer mt-auto py-3">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<span class="text-muted small">© 2020, 2021 <a href="https://www.cacert.org/">CAcert</a></span>
|
<span class="text-muted small">© 2020-2022 <a href="https://www.cacert.org/">CAcert</a></span>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<script type="text/javascript" src="/js/cacert.bundle.js"></script>
|
<script type="text/javascript" src="/js/cacert.bundle.js"></script>
|
9
ui/ui.go
Normal file
9
ui/ui.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed templates/*
|
||||||
|
var Templates embed.FS
|
||||||
|
|
||||||
|
//go:embed css/* js/* images/*
|
||||||
|
var Static embed.FS
|
Loading…
Reference in a new issue