Documentation ¶
Overview ¶
Package portal implements HTTP routes for portal pages.
These pages can be registered at init()-time, and will be routed to /admin/portal.
Typically they read/write `settings` as defined by `go.chromium.org/luci/server/settings`, but they can also be used to provide information to administrators or to provide admin-only actions (such as clearing queues or providing admin tokens).
Index ¶
- Variables
- func GetPages() map[string]Page
- func InstallHandlers(r *router.Router, base router.MiddlewareChain, adminAuth auth.Method)
- func RegisterPage(pageKey string, p Page)
- type Action
- type BasePage
- func (BasePage) Actions(c context.Context) ([]Action, error)
- func (BasePage) Fields(c context.Context) ([]Field, error)
- func (BasePage) Overview(c context.Context) (template.HTML, error)
- func (BasePage) ReadSettings(c context.Context) (map[string]string, error)
- func (BasePage) Title(c context.Context) (string, error)
- func (BasePage) WriteSettings(c context.Context, values map[string]string, who, why string) error
- type Field
- type FieldType
- type Page
- type YesOrNo
Constants ¶
This section is empty.
Variables ¶
var AssumeTrustedPort auth.Method = trustedPortAuth{}
AssumeTrustedPort can be passed as auth.Method to InstallHandlers to indicate that portal endpoints are being exposed on an internal port accessible only to cluster administrators and no additional auth checks are required (or they are not possible).
Functions ¶
func InstallHandlers ¶
InstallHandlers installs HTTP handlers that implement admin UI.
`adminAuth` is the method that will be used to authenticate the access (regardless of what's installed in the base context). It must be able to distinguish admins (aka superusers) from non-admins. It is needed because settings UI must be usable even before auth system is configured.
`adminAuth` can be a special value portal.AssumeTrustedPort which completely disables all authentication and authorization checks (by delegating them to the network layer).
func RegisterPage ¶
RegisterPage makes exposes UI for a portal page (identified by given unique key).
Should be called once when application starts (e.g. from init() of a package that defines the page). Panics if such key is already registered.
Types ¶
type Action ¶
type Action struct { ID string // page-unique ID Title string // what's displayed on the button Help template.HTML // optional help text Confirmation string // optional text for "Are you sure?" confirmation prompt // Callback is executed on click. // // The context is derived through the base middleware in the router. The // return values is presented to the user as is. Callback func(c context.Context) (template.HTML, error) }
Action corresponds to a button that triggers a parameterless callback.
type BasePage ¶
type BasePage struct{}
BasePage can be embedded into Page implementers to provide default behavior.
func (BasePage) ReadSettings ¶
ReadSettings returns a map "field ID => field value to display".
type Field ¶
type Field struct { ID string // page unique ID Title string // human friendly name Type FieldType // how the field is displayed and behaves Placeholder string // optional placeholder value Validator func(string) error // optional value validation Help template.HTML // optional help text ChoiceVariants []string // valid only for FieldChoice }
Field is description of a single UI element of the page.
Its ID acts as a key in map used by ReadSettings\WriteSettings.
func YesOrNoField ¶
YesOrNoField modifies the field so that it corresponds to YesOrNo value.
It sets 'Type', 'ChoiceVariants' and 'Validator' properties.
type FieldType ¶
type FieldType string
FieldType describes look and feel of UI field, see the enum below.
const ( FieldText FieldType = "text" // one line of text, editable FieldChoice FieldType = "choice" // pick one of predefined choices FieldStatic FieldType = "static" // one line of text, read only FieldPassword FieldType = "password" // one line of text, editable but obscured )
Note: exact values here are important. They are referenced in the HTML template that renders the settings page. See server/portal/*.
func (FieldType) IsEditable ¶
IsEditable returns true for fields that can be edited.
type Page ¶
type Page interface { // Title is used in UI to name this page. Title(c context.Context) (string, error) // Overview is optional HTML paragraph describing this page. Overview(c context.Context) (template.HTML, error) // Fields describes the schema of the settings on the page (if any). Fields(c context.Context) ([]Field, error) // Actions is additional list of actions to present on the page. // // Each action is essentially a clickable button that triggers a parameterless // callback. Actions(c context.Context) ([]Action, error) // ReadSettings returns a map "field ID => field value to display". // // It is called when rendering the settings page. ReadSettings(c context.Context) (map[string]string, error) // WriteSettings saves settings described as a map "field ID => field value". // // All values are validated using field validators first. WriteSettings(c context.Context, values map[string]string, who, why string) error }
Page controls how some portal section (usually corresponding to a key in global settings JSON blob) is displayed and edited in UI.
Packages that wishes to expose UI for managing their settings register a page via RegisterPage(...) call during init() time.