Merge C24 docs portal and client guide
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
e81f1cba4c
17 files changed
+1328
-56
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
|
||||
)
|
||||
|
||||
func docsRouter(t *testing.T, signIn bool) http.Handler {
|
||||
t.Helper()
|
||||
cfg := baseConfig(config.Endpoint{ID: "a", URL: "http://127.0.0.1:1", Models: []string{"m"}})
|
||||
cfg.Auth.Enabled = true
|
||||
cfg.Auth.Store = filepath.Join(t.TempDir(), "store.db")
|
||||
cfg.Landing.DocsSignIn = signIn
|
||||
return newTestRouter(t, cfg).Handler()
|
||||
}
|
||||
|
||||
// The docs are public by default on a gateway with keys: the client guide is
|
||||
// for the person who has none yet, so asking for one first defeats it.
|
||||
func TestTheDocsAreServedWithoutAKey(t *testing.T) {
|
||||
h := docsRouter(t, false)
|
||||
for _, path := range []string{"/docs", "/docs/clients"} {
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil))
|
||||
if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), "llmgw docs") {
|
||||
t.Errorf("%s: %d %.200s", path, w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDocsSignInSendsAVisitorToSignIn(t *testing.T) {
|
||||
h := docsRouter(t, true)
|
||||
for _, path := range []string{"/docs", "/docs/install"} {
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil))
|
||||
// The session guard, not the key check: a browser has no key.
|
||||
if strings.Contains(w.Body.String(), "api key") {
|
||||
t.Errorf("%s asked a browser for an API key", path)
|
||||
}
|
||||
if w.Code != http.StatusSeeOther || w.Header().Get("Location") != "/login" {
|
||||
t.Errorf("%s: %d to %q, want a redirect to /login", path, w.Code, w.Header().Get("Location"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,6 +231,11 @@ func (r *Router) Handler() http.Handler {
|
||||
pages.RegisterAdminGuard(mux, r.store, r.guardLibrary)
|
||||
}
|
||||
pages.Register(mux)
|
||||
// The docs portal, with the menu of whoever is signed in, and only to
|
||||
// them when the site asked for that.
|
||||
docs := pages.DocsPage(web.Docs(version.Version, true), r.landing.DocsSignIn)
|
||||
mux.HandleFunc("GET /docs", docs)
|
||||
mux.HandleFunc("GET /docs/{doc}", docs)
|
||||
r.registerChat(mux, pages)
|
||||
// An organization's own page, for the people who manage it.
|
||||
pages.RegisterOrgPages(mux, r.store, r.acct)
|
||||
@@ -282,18 +287,29 @@ func (r *Router) Handler() http.Handler {
|
||||
Catalog: r.catalogAdmin, Fleet: r.clusterView,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// No accounts, so nobody to show a menu to or to send to sign in.
|
||||
docs := web.Docs(version.Version, false)
|
||||
mux.HandleFunc("GET /docs", docs)
|
||||
mux.HandleFunc("GET /docs/{doc}", docs)
|
||||
}
|
||||
|
||||
if r.auth == nil {
|
||||
return mux
|
||||
}
|
||||
exempt := []string{"/health", "/ready", "/leader", "/", "/about", "/_static/", "/claim/",
|
||||
"/signup", "/login", "/login/", "/logout", "/profile", "/profile/", "/scim/",
|
||||
"/admin", "/admin/", "/chat", "/chat/", "/org", "/org/", "/setup/"}
|
||||
// The docs are public unless the site said otherwise, and then guarded by
|
||||
// the session check in front of them — or, on a gateway with keys and no
|
||||
// accounts to sign in to, by the key like any other path.
|
||||
if !r.landing.DocsSignIn || r.accounts != nil {
|
||||
exempt = append(exempt, "/docs", "/docs/")
|
||||
}
|
||||
// Wrapping the whole mux rather than checking inside each handler: adding a
|
||||
// route must not be able to add an unauthenticated one by omission. Health
|
||||
// stays open because a load balancer has no key.
|
||||
return auth.Middleware(r.auth, r.log,
|
||||
"/health", "/ready", "/leader", "/", "/about", "/_static/", "/claim/",
|
||||
"/signup", "/login", "/login/", "/logout", "/profile", "/profile/", "/scim/",
|
||||
"/admin", "/admin/", "/chat", "/chat/", "/org", "/org/", "/setup/")(mux)
|
||||
return auth.Middleware(r.auth, r.log, exempt...)(mux)
|
||||
}
|
||||
|
||||
// parsedRequest is what the router needs from a request. Everything else in the
|
||||
|
||||
Reference in new issue
Block a user