Documentation
¶
Overview ¶
**************************************************************
* * Copyright (C) 2024, Pelican Project, Morgridge Institute for Research * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You may * obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * **************************************************************
Index ¶
- Constants
- Variables
- func AdminAuthHandler(ctx *gin.Context)
- func AuthHandler(ctx *gin.Context)
- func CheckAdmin(user string, groups []string) (isAdmin bool, message string)
- func ConfigOAuthClientAPIs(engine *gin.Engine) error
- func ConfigureEmbeddedPrometheus(ctx context.Context, engine *gin.Engine, ...) error
- func ConfigureServerWebAPI(ctx context.Context, engine *gin.Engine, egrp *errgroup.Group) error
- func DowntimeAuthHandler(ctx *gin.Context)
- func GenerateCSRFCookie(ctx *gin.Context, metadata map[string]string) (string, error)
- func GenerateOAuthState(metadata map[string]string) string
- func GetEngine() (*gin.Engine, error)
- func GetSessionHandler() (gin.HandlerFunc, error)
- func GetUserGroups(ctx *gin.Context) (user string, userId string, groups []string, err error)
- func HandleCreateDowntime(ctx *gin.Context)
- func HandleDeleteDowntime(ctx *gin.Context)
- func HandleDeleteLogLevel(ctx *gin.Context)
- func HandleGetDowntime(ctx *gin.Context)
- func HandleGetDowntimeByUUID(ctx *gin.Context)
- func HandleGetLogLevel(ctx *gin.Context)
- func HandleGetServerLocalMetadataHistory(ctx *gin.Context)
- func HandleSetLogLevel(ctx *gin.Context)
- func HandleUpdateDowntime(ctx *gin.Context)
- func InitServerWebLogin(ctx context.Context) error
- func ParseOAuthState(state string) (metadata map[string]string, err error)
- func RequireAuthMiddleware(ctx *gin.Context)
- func RunEngine(ctx context.Context, engine *gin.Engine, egrp *errgroup.Group) error
- func RunEngineRoutine(ctx context.Context, engine *gin.Engine, egrp *errgroup.Group, curRoutine bool) error
- func RunEngineRoutineWithListener(ctx context.Context, engine *gin.Engine, egrp *errgroup.Group, curRoutine bool, ...) error
- func ServerHeaderMiddleware(ctx *gin.Context)
- func WritePasswordEntry(user, password string) error
- type AddGroupMemberReq
- type AddUserReq
- type CreateApiTokenReq
- type CreateGroupReq
- type DowntimeInput
- type InitLogin
- type LogLevelChangeResponse
- type LogLevelStatusResponse
- type Login
- type LogrusAdapter
- type OIDCEnabledServerRes
- type ParameterLevelStatus
- type PasswordReset
- type ReadyHandler
- type SetLogLevelRequest
- type UserRole
- type WhoAmIRes
Constants ¶
const ( GroupSourceTypeOIDC string = "oidc" GroupSourceTypeFile string = "file" GroupSourceTypeInternal string = "internal" GroupSourceTypeGitHub string = "github" )
Group source types
const ( MaxLabelLimit = 128 MaxLabelNameLengthLimit = 256 MaxLabelValueLengthLimit = 4096 MaxSampleLimit = 800 )
Variables ¶
var ErrNotReady = errors.New("Scrape manager not ready")
ErrNotReady is returned if the underlying scrape manager is not ready yet.
Functions ¶
func AdminAuthHandler ¶
adminAuthHandler checks the admin status of a logged-in user. This middleware should be cascaded behind the web_ui.AuthHandler
func AuthHandler ¶
Check if user is authenticated by checking if the "login" cookie is present and set the user identity to ctx
func CheckAdmin ¶
checkAdmin checks if a user string has admin privilege. It returns boolean and a message indicating the error message.
Note that by default it only checks if user == "admin". If you have a custom list of admin identifiers to check, you should set Server.UIAdminUsers. If you want to grant admin privileges based on group membership, you should set Server.AdminGroups.
func ConfigOAuthClientAPIs ¶
Configure OAuth2 client and register related authentication endpoints for Web UI
func ConfigureServerWebAPI ¶ added in v1.0.4
Configure endpoints for server web APIs. This function does not configure any UI specific paths but just redirect root path to /view.
You need to mount the static resources for UI in a separate function
func DowntimeAuthHandler ¶
DowntimeAuthHandler allows EITHER: 1. Admin cookie authentication (req from this server itself), OR 2. Server bearer token authentication (req from another server, i.e. origin/cache)
func GenerateCSRFCookie ¶
Generate a 16B random string and set as the value of ctx session key "oauthstate" return a string for OAuth2 "state" query parameter including the random string and other metadata
func GenerateOAuthState ¶
Generate the state for the authentication request in OAuth2 code flow. The metadata are formatted similar to url query parameters:
key1=val1&key2=val2
where values are url-encoded. We then base64 encode the resulting string in order to ensure that over-zealous providers do not treat the final URL as a double-encoding attack or somesuch.
func GetSessionHandler ¶
func GetSessionHandler() (gin.HandlerFunc, error)
Setup and return the session handler for web UI APIs. Calling multiple times will only set up the handler once
func GetUserGroups ¶
Get user information including userId from the login cookie or Bearer token. Returns username, userId, sub, issuer, groups, and error.
func HandleCreateDowntime ¶
func HandleDeleteDowntime ¶
func HandleDeleteLogLevel ¶
HandleDeleteLogLevel handles DELETE requests to remove a temporary log level change
func HandleGetDowntime ¶
func HandleGetDowntimeByUUID ¶
func HandleGetLogLevel ¶
HandleGetLogLevel handles GET requests to retrieve current log level status
func HandleGetServerLocalMetadataHistory ¶
HandleGetServerLocalMetadataHistory returns the locally cached server metadata history for Origins/Caches.
func HandleSetLogLevel ¶
HandleSetLogLevel handles POST requests to temporarily change log level
func HandleUpdateDowntime ¶
func InitServerWebLogin ¶ added in v1.0.4
Setup the initial server web login by sending the one-time code to stdout and record health status of the WebUI based on the success of the initialization
func ParseOAuthState ¶
Parse the OAuth2 callback state into a key-val map. Error if keys are duplicated state is the url-decoded value of the query parameter "state" in the the OAuth2 callback request
func RequireAuthMiddleware ¶
Require auth; if missing, redirect to the login endpoint.
The current implementation forces the OAuth2 endpoint; future work may instead use a generic login page.
func RunEngine ¶
Run the gin engine in the current goroutine.
Will use a background golang routine to periodically reload the certificate utilized by the UI.
func RunEngineRoutine ¶
func RunEngineRoutine(ctx context.Context, engine *gin.Engine, egrp *errgroup.Group, curRoutine bool) error
Run the gin engine; if curRoutine is false, it will run in a background goroutine.
func RunEngineRoutineWithListener ¶
func RunEngineRoutineWithListener(ctx context.Context, engine *gin.Engine, egrp *errgroup.Group, curRoutine bool, ln net.Listener) error
Run the web engine connected to a provided listener `ln`.
func ServerHeaderMiddleware ¶
func WritePasswordEntry ¶ added in v1.0.4
Types ¶
type AddGroupMemberReq ¶
type AddGroupMemberReq struct {
UserID string `json:"userId"`
}
type AddUserReq ¶
type CreateApiTokenReq ¶
type CreateGroupReq ¶
type DowntimeInput ¶
type DowntimeInput struct {
CreatedBy string `json:"createdBy"` // Person who created this downtime
UpdatedBy string `json:"updatedBy"` // Person who last updated this downtime
ServerName string `json:"serverName"` // Empty for Origin/Cache input; Not empty for Registry input
ServerID string `json:"serverId"`
Source string `json:"source"` // Automatically set by the server; should only be set by input during testing
Class server_structs.Class `json:"class"`
Description string `json:"description"`
Severity server_structs.Severity `json:"severity"`
StartTime int64 `json:"startTime"` // Epoch UTC in seconds
EndTime int64 `json:"endTime"` // Epoch UTC in seconds
}
type LogLevelChangeResponse ¶
type LogLevelChangeResponse struct {
ChangeID string `json:"changeId"`
Level string `json:"level"`
ParameterName string `json:"parameterName,omitempty"`
EndTime time.Time `json:"endTime"`
Remaining int `json:"remainingSeconds"`
}
LogLevelChangeResponse represents a log level change with its metadata
type LogLevelStatusResponse ¶
type LogLevelStatusResponse struct {
CurrentLevel string `json:"currentLevel"`
BaseLevel string `json:"baseLevel"`
ActiveChanges []LogLevelChangeResponse `json:"activeChanges"`
Parameters []ParameterLevelStatus `json:"parameters"`
}
LogLevelStatusResponse represents the current log level status
type LogrusAdapter ¶ added in v1.0.4
func (LogrusAdapter) Log ¶ added in v1.0.4
func (a LogrusAdapter) Log(keyvals ...interface{}) error
Log method which satisfies the kitlog.Logger interface. It also propragates field level and field message to top level log
type OIDCEnabledServerRes ¶
type OIDCEnabledServerRes struct {
ODICEnabledServers []string `json:"oidc_enabled_servers"`
}
type ParameterLevelStatus ¶
type ParameterLevelStatus struct {
ParameterName string `json:"parameterName"`
CurrentLevel string `json:"currentLevel"`
BaseLevel string `json:"baseLevel"`
}
ParameterLevelStatus summarizes the current/base level for a parameter.
type PasswordReset ¶ added in v1.0.4
type PasswordReset struct {
Password string `form:"password"`
}
type ReadyHandler ¶
type ReadyHandler struct {
// contains filtered or unexported fields
}
func (*ReadyHandler) SetReady ¶
func (h *ReadyHandler) SetReady(v bool)
type SetLogLevelRequest ¶
type SetLogLevelRequest struct {
Level string `json:"level" binding:"required"` // Log level (e.g., "debug", "info", "warn", "error")
Duration int `json:"duration" binding:"required,min=1"` // Duration in seconds
ParameterName string `json:"parameterName"` // Parameter name like "Logging.Level" or "Logging.Origin.Xrootd"
}
SetLogLevelRequest represents a request to temporarily change log level