rest

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggerMiddleware

func LoggerMiddleware(next http.Handler) http.Handler

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter) *responseWriter

func RegisterFrontend added in v1.2.1

func RegisterFrontend(e *echo.Echo)

RegisterFrontend serves the embedded React SPA from web/dist. It serves static assets directly and falls back to index.html for client-side routing.

Types

type ChangePasswordRequest

type ChangePasswordRequest struct {
	OldPassword string `json:"oldPassword"`
	NewPassword string `json:"newPassword"`
}

type CreateRoleRequest

type CreateRoleRequest struct {
	Name         string       `json:"name"`
	Description  string       `json:"description"`
	RolePolicies []RolePolicy `json:"rolePolicies"`
}

type CreateScheduleStrategyRequest

type CreateScheduleStrategyRequest struct {
	StrategyNamespace string          `json:"strategyNamespace,omitempty"`
	LabelSelectors    []LabelSelector `json:"labelSelectors,omitempty"`
	K8sNamespace      []string        `json:"k8sNamespace,omitempty"`
	CommandRegex      string          `json:"commandRegex,omitempty"`
	Priority          int             `json:"priority,omitempty"`
	ExecutionTime     int64           `json:"executionTime,omitempty"`
}

type CreateUserRequest

type CreateUserRequest struct {
	UserName string `json:"username"`
	Password string `json:"password"`
}

type DeleteRoleRequest

type DeleteRoleRequest struct {
	ID string `json:"id"`
}

type DeleteScheduleIntentsRequest added in v1.1.0

type DeleteScheduleIntentsRequest struct {
	IntentIDs []string `json:"intentIds"`
}

type DeleteScheduleStrategyRequest added in v1.1.0

type DeleteScheduleStrategyRequest struct {
	StrategyID string `json:"strategyId"`
}

type EmptyResponse

type EmptyResponse struct{}

EmptyResponse is used for endpoints that return no data payload.

type ErrorResponse

type ErrorResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
}

ErrorResponse represents error response structure

type GetNodePodPIDMappingResponse added in v1.2.0

type GetNodePodPIDMappingResponse struct {
	Pods      []PodPIDInfo `json:"pods"`
	Timestamp string       `json:"timestamp"`
	NodeName  string       `json:"node_name"`
	NodeID    string       `json:"node_id,omitempty"`
}

GetNodePodPIDMappingResponse is the response structure for the GET /api/v1/nodes/:nodeID/pods/pids endpoint

type GetSelfUserResponse

type GetSelfUserResponse struct {
	ID       string            `json:"id"`
	UserName string            `json:"username"`
	Roles    []string          `json:"roles"`
	Status   domain.UserStatus `json:"status"`
}

type Handler

type Handler struct {
	Svc domain.Service
}

func NewHandler

func NewHandler(params Params) (*Handler, error)

func (*Handler) ChangePassword

func (h *Handler) ChangePassword(w http.ResponseWriter, r *http.Request)

ChangePassword godoc @Summary Change own password @Description Update current user's password. @Tags Users @Accept json @Produce json @Security BearerAuth @Param request body ChangePasswordRequest true "Password payload" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/users/self/password [put]

func (*Handler) CreateRole

func (h *Handler) CreateRole(w http.ResponseWriter, r *http.Request)

CreateRole godoc @Summary Create role @Description Create a new role with policies. @Tags Roles @Accept json @Produce json @Security BearerAuth @Param request body CreateRoleRequest true "Role payload" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/roles [post]

func (*Handler) CreateScheduleStrategy

func (h *Handler) CreateScheduleStrategy(w http.ResponseWriter, r *http.Request)

CreateScheduleStrategy godoc @Summary Create schedule strategy @Description Create a new schedule strategy. @Tags Strategies @Accept json @Produce json @Security BearerAuth @Param request body CreateScheduleStrategyRequest true "Schedule strategy payload" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/strategies [post]

func (*Handler) CreateUser

func (h *Handler) CreateUser(w http.ResponseWriter, r *http.Request)

CreateUser godoc @Summary Create user @Description Create a new user account. @Tags Users @Accept json @Produce json @Security BearerAuth @Param request body CreateUserRequest true "User payload" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/users [post]

func (*Handler) DeleteRole

func (h *Handler) DeleteRole(w http.ResponseWriter, r *http.Request)

DeleteRole godoc @Summary Delete role @Description Delete a role by ID. @Tags Roles @Accept json @Produce json @Security BearerAuth @Param request body DeleteRoleRequest true "Role payload" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/roles [delete]

func (*Handler) DeleteScheduleIntents added in v1.1.0

func (h *Handler) DeleteScheduleIntents(w http.ResponseWriter, r *http.Request)

DeleteScheduleIntents godoc @Summary Delete schedule intents @Description Delete one or more schedule intents. @Tags Strategies @Accept json @Produce json @Security BearerAuth @Param request body DeleteScheduleIntentsRequest true "Intent IDs to delete" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/intents [delete]

func (*Handler) DeleteScheduleStrategy added in v1.1.0

func (h *Handler) DeleteScheduleStrategy(w http.ResponseWriter, r *http.Request)

DeleteScheduleStrategy godoc @Summary Delete schedule strategy @Description Delete a schedule strategy and its associated intents. @Tags Strategies @Accept json @Produce json @Security BearerAuth @Param request body DeleteScheduleStrategyRequest true "Strategy ID to delete" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/strategies [delete]

func (*Handler) ErrorResponse

func (h *Handler) ErrorResponse(ctx context.Context, w http.ResponseWriter, status int, errMsg string, err error)

func (*Handler) GetAuthMiddleware

func (h *Handler) GetAuthMiddleware(permissionKey domain.PermissionKey) func(next http.Handler) http.Handler

func (*Handler) GetClaimsFromContext

func (h *Handler) GetClaimsFromContext(ctx context.Context) (domain.Claims, bool)

GetClaimsFromContext extracts domain.Claims from the request context

func (*Handler) GetNodePodPIDMapping added in v1.2.0

func (h *Handler) GetNodePodPIDMapping(w http.ResponseWriter, r *http.Request)

GetNodePodPIDMapping godoc @Summary Get Pod-PID mapping for a specific node @Description Returns all pods running on the specified node with their associated process IDs @Tags Nodes @Produce json @Security BearerAuth @Param nodeID path string true "Node ID" @Success 200 {object} SuccessResponse[GetNodePodPIDMappingResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/nodes/{nodeID}/pods/pids [get]

func (*Handler) GetPathParam added in v1.2.0

func (h *Handler) GetPathParam(r *http.Request, name string) string

GetPathParam retrieves a path parameter from request context

func (*Handler) GetRolePolicyFromContext

func (h *Handler) GetRolePolicyFromContext(ctx context.Context) (domain.RolePolicy, bool)

func (*Handler) GetSelfUser

func (h *Handler) GetSelfUser(w http.ResponseWriter, r *http.Request)

GetSelfUser godoc @Summary Get current user @Description Retrieve profile of the authenticated user. @Tags Users @Produce json @Security BearerAuth @Success 200 {object} SuccessResponse[GetSelfUserResponse] @Failure 401 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/users/self [get]

func (*Handler) HandleError

func (h *Handler) HandleError(ctx context.Context, w http.ResponseWriter, err error)

func (*Handler) HealthCheck

func (h *Handler) HealthCheck(w http.ResponseWriter, r *http.Request)

HealthCheck godoc @Summary Health check @Description Basic health check for readiness probes. @Tags System @Produce json @Success 200 {object} HealthResponse @Router /health [get]

func (*Handler) JSONBind

func (h *Handler) JSONBind(r *http.Request, dst any) error

func (*Handler) JSONResponse

func (h *Handler) JSONResponse(ctx context.Context, w http.ResponseWriter, status int, data any)

func (*Handler) ListNodes added in v1.2.0

func (h *Handler) ListNodes(w http.ResponseWriter, r *http.Request)

ListNodes godoc @Summary List all Kubernetes nodes @Description Returns all nodes in the Kubernetes cluster @Tags Nodes @Produce json @Security BearerAuth @Success 200 {object} SuccessResponse[ListNodesResponse] @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/nodes [get]

func (*Handler) ListPermissions

func (h *Handler) ListPermissions(w http.ResponseWriter, r *http.Request)

ListPermissions godoc @Summary List permissions @Description Retrieve all permission keys. @Tags Roles @Produce json @Security BearerAuth @Success 200 {object} SuccessResponse[ListPermissionsResponse] @Failure 401 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/permissions [get]

func (*Handler) ListRoles

func (h *Handler) ListRoles(w http.ResponseWriter, r *http.Request)

ListRoles godoc @Summary List roles @Description Retrieve available roles. @Tags Roles @Produce json @Security BearerAuth @Success 200 {object} SuccessResponse[ListRolesResponse] @Failure 401 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/roles [get]

func (*Handler) ListSelfScheduleIntents

func (h *Handler) ListSelfScheduleIntents(w http.ResponseWriter, r *http.Request)

ListSelfScheduleIntents godoc @Summary List self schedule intents @Description List schedule intents created by the authenticated user. @Tags Strategies @Accept json @Produce json @Security BearerAuth @Success 200 {object} SuccessResponse[ListScheduleIntentsResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/intents/self [get]

func (*Handler) ListSelfScheduleStrategies

func (h *Handler) ListSelfScheduleStrategies(w http.ResponseWriter, r *http.Request)

ListSelfScheduleStrategies godoc @Summary List self schedule strategies @Description List schedule strategies created by the authenticated user. @Tags Strategies @Accept json @Produce json @Security BearerAuth @Success 200 {object} SuccessResponse[ListSchedulerStrategiesResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/strategies/self [get]

func (*Handler) ListUsers

func (h *Handler) ListUsers(w http.ResponseWriter, r *http.Request)

ListUsers godoc @Summary List users @Description Retrieve user list. @Tags Users @Produce json @Security BearerAuth @Success 200 {object} SuccessResponse[ListUsersResponse] @Failure 401 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/users [get]

func (*Handler) Login

func (h *Handler) Login(w http.ResponseWriter, r *http.Request)

Login godoc @Summary User login @Description Authenticate user and return JWT token. @Tags Auth @Accept json @Produce json @Param request body LoginRequest true "Login payload" @Success 200 {object} SuccessResponse[LoginResponse] @Failure 400 {object} ErrorResponse @Failure 422 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/auth/login [post]

func (*Handler) ResetPassword

func (h *Handler) ResetPassword(w http.ResponseWriter, r *http.Request)

ResetPassword godoc @Summary Reset user password @Description Reset another user's password. @Tags Users @Accept json @Produce json @Security BearerAuth @Param request body ResetPasswordRequest true "Reset payload" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/users/password [put]

func (*Handler) SetClaimsInContext

func (h *Handler) SetClaimsInContext(ctx context.Context, claims domain.Claims) context.Context

func (*Handler) SetRolePolicyInContext

func (h *Handler) SetRolePolicyInContext(ctx context.Context, rolePolicy domain.RolePolicy) context.Context

func (*Handler) SetupRoutes

func (h *Handler) SetupRoutes(engine *echo.Echo)

func (*Handler) UpdateRole

func (h *Handler) UpdateRole(w http.ResponseWriter, r *http.Request)

UpdateRole godoc @Summary Update role @Description Update role information or policies. @Tags Roles @Accept json @Produce json @Security BearerAuth @Param request body UpdateRoleRequest true "Role payload" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/roles [put]

func (*Handler) UpdateUserPermissions

func (h *Handler) UpdateUserPermissions(w http.ResponseWriter, r *http.Request)

UpdateUserPermissions godoc @Summary Update user roles and status @Description Update a user's roles or status. @Tags Users @Accept json @Produce json @Security BearerAuth @Param request body UpdateUserPermissionsRequest true "Permissions payload" @Success 200 {object} SuccessResponse[EmptyResponse] @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/users/permissions [put]

func (*Handler) VerifyResourcePolicy

func (h *Handler) VerifyResourcePolicy(ctx context.Context, resourceOwnerID string) error

func (*Handler) Version

func (h *Handler) Version(w http.ResponseWriter, r *http.Request)

Version godoc @Summary Get service version @Description Returns service version and exposed endpoints. @Tags System @Produce json @Success 200 {object} VersionResponse @Router /version [get]

type HealthResponse

type HealthResponse struct {
	Status    string `json:"status"`
	Timestamp string `json:"timestamp"`
	Service   string `json:"service"`
}

HealthResponse describes the health check payload.

type LabelSelector

type LabelSelector struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

type ListNodesResponse added in v1.2.0

type ListNodesResponse struct {
	Nodes []NodeInfo `json:"nodes"`
}

ListNodesResponse is the response structure for the GET /api/v1/nodes endpoint

type ListPermissionsResponse

type ListPermissionsResponse struct {
	Permissions []struct {
		Key         domain.PermissionKey `json:"key"`
		Description string               `json:"description"`
	} `json:"permissions"`
}

type ListRolesResponse

type ListRolesResponse struct {
	Roles []struct {
		ID          string       `json:"id"`
		Name        string       `json:"name"`
		Description string       `json:"description"`
		RolePolicy  []RolePolicy `json:"rolePolicy"`
	} `json:"roles"`
}

type ListScheduleIntentsResponse

type ListScheduleIntentsResponse struct {
	Intents []*ScheduleIntent `json:"intents"`
}

type ListSchedulerStrategiesResponse

type ListSchedulerStrategiesResponse struct {
	Strategies []*ScheduleStrategy `json:"strategies"`
}

type ListUsersResponse

type ListUsersResponse struct {
	Users []struct {
		ID       string            `json:"id"`
		UserName string            `json:"username"`
		Roles    []string          `json:"roles"`
		Status   domain.UserStatus `json:"status"`
	} `json:"users"`
}

type LoginRequest

type LoginRequest struct {
	UserName string `json:"username"`
	Password string `json:"password"`
}

type LoginResponse

type LoginResponse struct {
	Token string `json:"token"`
}

type NodeInfo added in v1.2.0

type NodeInfo struct {
	Name   string `json:"name"`
	Status string `json:"status"`
}

NodeInfo represents node information for API response

type Params

type Params struct {
	fx.In
	Svc domain.Service
}

type PodPIDInfo added in v1.2.0

type PodPIDInfo struct {
	PodUID    string          `json:"pod_uid"`
	PodID     string          `json:"pod_id,omitempty"`
	Processes []PodPIDProcess `json:"processes"`
}

PodPIDInfo represents pod information with associated processes (for API response)

type PodPIDProcess added in v1.2.0

type PodPIDProcess struct {
	PID         int    `json:"pid"`
	Command     string `json:"command"`
	PPID        int    `json:"ppid,omitempty"`
	ContainerID string `json:"container_id,omitempty"`
}

PodPIDProcess represents a process information within a pod (for API response)

type ResetPasswordRequest

type ResetPasswordRequest struct {
	UserID      string `json:"userID"`
	NewPassword string `json:"newPassword"`
}

type RolePolicy

type RolePolicy struct {
	PermissionKey   domain.PermissionKey `json:"permissionKey"`
	Self            bool                 `json:"self"`
	K8SNamespace    string               `json:"k8sNamespace"`
	PolicyNamespace string               `json:"policyNamespace"`
}

type ScheduleIntent

type ScheduleIntent struct {
	ID            bson.ObjectID      `bson:"_id,omitempty"`
	StrategyID    bson.ObjectID      `bson:"strategyID,omitempty"`
	PodID         string             `bson:"podID,omitempty"`
	NodeID        string             `bson:"nodeID,omitempty"`
	K8sNamespace  string             `bson:"k8sNamespace,omitempty"`
	CommandRegex  string             `bson:"commandRegex,omitempty"`
	Priority      int                `bson:"priority,omitempty"`
	ExecutionTime int64              `bson:"executionTime,omitempty"`
	PodLabels     map[string]string  `bson:"podLabels,omitempty"`
	State         domain.IntentState `bson:"state,omitempty"`
}

type ScheduleStrategy

type ScheduleStrategy struct {
	ID                bson.ObjectID   `bson:"_id,omitempty"`
	StrategyNamespace string          `bson:"strategyNamespace,omitempty"`
	LabelSelectors    []LabelSelector `bson:"labelSelectors,omitempty"`
	K8sNamespace      []string        `bson:"k8sNamespace,omitempty"`
	CommandRegex      string          `bson:"commandRegex,omitempty"`
	Priority          int             `bson:"priority,omitempty"`
	ExecutionTime     int64           `bson:"executionTime,omitempty"`
}

type SuccessResponse

type SuccessResponse[T any] struct {
	Success   bool   `json:"success"`
	Data      *T     `json:"data,omitempty"`
	Timestamp string `json:"timestamp"`
}

SuccessResponse represents the success response structure

func NewSuccessResponse

func NewSuccessResponse[T any](data *T) SuccessResponse[T]

type UpdateRoleRequest

type UpdateRoleRequest struct {
	ID          string        `json:"id"`
	Name        *string       `json:"name,omitempty"`
	Description *string       `json:"description,omitempty"`
	RolePolicy  *[]RolePolicy `json:"rolePolicy,omitempty"`
}

type UpdateUserPermissionsRequest

type UpdateUserPermissionsRequest struct {
	UserID string             `json:"userID"`
	Roles  *[]string          `json:"roles,omitempty"`
	Status *domain.UserStatus `json:"status,omitempty"`
}

type VersionResponse

type VersionResponse struct {
	Message   string `json:"message"`
	Version   string `json:"version"`
	Endpoints string `json:"endpoints"`
}

VersionResponse describes the version endpoint payload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL