queries

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessLogCountryStat

type AccessLogCountryStat struct {
	CountryCode   string
	CountryName   string
	ContinentCode string
	Total         int64
	Allowed       int64
	Denied        int64
}

AccessLogCountryStat holds aggregated request counts for a single country.

type AccessLogQuery

type AccessLogQuery struct {
	From          time.Time
	To            time.Time
	BeforeID      *int64 // cursor: return rows with id < BeforeID; nil for first page
	ClientIP      *string
	Outcome       *bool
	DenyReason    *string
	DeviceID      *device.DeviceID
	TargetHost    *string
	CountryCode   *string
	ContinentCode *string
	Limit         int
}

func NewAccessLogQuery

func NewAccessLogQuery(params httpapi.GetAccessLogParams) AccessLogQuery

type AccessLogView

type AccessLogView struct {
	ID            int64
	ClientIP      string
	Outcome       bool
	DenyReason    *string
	DeviceID      *device.DeviceID
	DeviceName    *string
	AddressID     *device.AddressID
	CreatedAt     time.Time
	DurationUs    int64
	XFFChain      *string
	TargetHost    *string
	TargetURI     *string
	HTTPMethod    *string
	Headers       map[string][]string
	CountryCode   *string
	CountryName   *string
	ContinentCode *string
	ASN           *int64
	ASNOrg        *string
}

type AddressView

type AddressView struct {
	ID        device.AddressID `db:"id"`
	DeviceID  device.DeviceID  `db:"device_id"`
	IP        string           `db:"ip"`
	IsEnabled bool             `db:"is_enabled"`
	Source    string           `db:"source"`
	UpdatedAt time.Time        `db:"updated_at"`
	CreatedAt time.Time        `db:"created_at"`
	ExpiresAt *time.Time       `db:"expires_at"`
}

type DeviceDetail added in v0.3.0

type DeviceDetail struct {
	ID           device.DeviceID   `db:"id"`
	Name         string            `db:"name"`
	DeviceType   device.DeviceType `db:"device_type"`
	Description  *string           `db:"description"`
	Icon         *string           `db:"icon"`
	CreatedAt    time.Time         `db:"created_at"`
	UpdatedAt    time.Time         `db:"updated_at"`
	KeyPrefix    *string           `db:"key_prefix"`
	AddressCount int               `db:"address_count"`
	LastSeenAt   *database.DBTime  `db:"last_seen_at"`
	OwnerID      auth.UserID       `db:"owner_id"`
	OwnerName    string            `db:"owner_name"`
}

type DeviceView

type DeviceView struct {
	ID           device.DeviceID   `db:"id"`
	Name         string            `db:"name"`
	DeviceType   device.DeviceType `db:"device_type"`
	Description  *string           `db:"description"`
	Icon         *string           `db:"icon"`
	CreatedAt    time.Time         `db:"created_at"`
	UpdatedAt    time.Time         `db:"updated_at"`
	KeyPrefix    *string           `db:"key_prefix"`
	AddressCount int               `db:"address_count"`
	LastSeenAt   *database.DBTime  `db:"last_seen_at"`
	OwnerID      auth.UserID       `db:"owner_id"`
	OwnerName    string            `db:"owner_name"`
}

type GroupRef added in v0.3.0

type GroupRef struct {
	ID   hostaccess.HostGroupID
	Name string
}

type HTTPHandler

type HTTPHandler struct {
	// contains filtered or unexported fields
}

func NewHTTPHandler

func NewHTTPHandler(repo *Repository, policyReader PolicyMapReader, logger *slog.Logger) *HTTPHandler

func (*HTTPHandler) GetAccessLog

func (*HTTPHandler) GetDevice added in v0.3.0

func (*HTTPHandler) GetDevicesByUser added in v0.3.0

func (*HTTPHandler) GetPolicyUserMap added in v0.3.0

GetPolicyUserMap returns the user-pivoted policy cache audit view.

func (*HTTPHandler) GetUserHostDetails added in v0.3.0

func (*HTTPHandler) ListHostGroups added in v0.3.0

func (*HTTPHandler) ListHostSuggestions added in v0.3.0

func (*HTTPHandler) ListKnownHosts added in v0.3.0

func (*HTTPHandler) ListUsers added in v0.3.0

func (*HTTPHandler) ListUsersHostAccess added in v0.3.0

type HostAccessKind added in v0.3.0

type HostAccessKind string

HostAccessKind is the computed access state for a single host in the drawer.

const (
	HostAccessNone         HostAccessKind = "none"
	HostAccessDirect       HostAccessKind = "direct"
	HostAccessViaGroup     HostAccessKind = "via_group"
	HostAccessDirectAndVia HostAccessKind = "direct_and_via_group"
	HostAccessAllowAll     HostAccessKind = "allow_all"
)

type HostGroupWithMembers added in v0.3.0

type HostGroupWithMembers struct {
	ID          hostaccess.HostGroupID
	Name        string
	Color       *string
	Description *string
	Icon        *string
	CreatedAt   time.Time
	Hosts       []hostaccess.KnownHostRef
	MemberIDs   []hostaccess.KnownHostID
}

type HostSuggestion added in v0.3.0

type HostSuggestion struct {
	FQDN        string          `db:"fqdn"`
	FirstSeen   database.DBTime `db:"first_seen"`
	AllowedHits int             `db:"allowed_hits"`
	DeniedHits  int             `db:"denied_hits"`
}

type HostSuggestionsPage added in v0.3.0

type HostSuggestionsPage struct {
	Suggestions []HostSuggestion
	Ignored     []hostaccess.IgnoredHostSuggestion
}

type KnownHostStats added in v0.3.0

type KnownHostStats struct {
	ID        hostaccess.KnownHostID `db:"id"`
	FQDN      string                 `db:"fqdn"`
	Icon      *string                `db:"icon"`
	CreatedAt time.Time              `db:"created_at"`
	UserCount int                    `db:"user_count"`
	Groups    []GroupRef
}

type PolicyMapReader added in v0.3.0

type PolicyMapReader interface {
	GetPolicyMap() policy.PolicyMapSnapshot
}

PolicyMapReader is the cross-domain interface consumed by the queries package. Implemented by policy.Service.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(db *database.DB) *Repository

func (*Repository) BuildPolicyUserMap added in v0.3.0

func (r *Repository) BuildPolicyUserMap(
	ctx context.Context,
	reader PolicyMapReader,
) (httpapi.PolicyUserMapAudit, error)

BuildPolicyUserMap is the single business-logic entry point for the user-pivoted policy audit view. The handler is a thin wrapper around it. This is the integration-test target for orchestration; pure assembly is tested separately via assemblePolicyUserMap.

func (*Repository) DeviceExists

func (r *Repository) DeviceExists(ctx context.Context, deviceID device.DeviceID) (bool, error)

func (*Repository) GetAllUsers added in v0.3.0

func (r *Repository) GetAllUsers(ctx context.Context) ([]UserView, error)

func (*Repository) GetDeviceAddresses

func (r *Repository) GetDeviceAddresses(ctx context.Context, deviceID device.DeviceID) ([]AddressView, error)

func (*Repository) GetDeviceDetail added in v0.3.0

func (r *Repository) GetDeviceDetail(ctx context.Context, id device.DeviceID) (*DeviceDetail, error)

func (*Repository) GetDevices

func (r *Repository) GetDevices(ctx context.Context, ownerID *auth.UserID) ([]DeviceView, error)

GetDevices retrieves devices for a specific user or all users when ownerID is nil

func (*Repository) GetDevicesByUser added in v0.3.0

func (r *Repository) GetDevicesByUser(ctx context.Context, targetUserID auth.UserID) ([]DeviceView, error)

func (*Repository) GetHostGroupsWithMembers added in v0.3.0

func (r *Repository) GetHostGroupsWithMembers(ctx context.Context) ([]HostGroupWithMembers, error)

func (*Repository) GetHostSuggestionsPage added in v0.3.0

func (r *Repository) GetHostSuggestionsPage(ctx context.Context) (HostSuggestionsPage, error)

func (*Repository) GetKnownHostsWithStats added in v0.3.0

func (r *Repository) GetKnownHostsWithStats(ctx context.Context) ([]KnownHostStats, error)

func (*Repository) GetUserAccessEditor added in v0.3.0

func (r *Repository) GetUserAccessEditor(ctx context.Context, userID auth.UserID) (UserAccessEditor, error)

func (*Repository) ListAccessLog

func (r *Repository) ListAccessLog(ctx context.Context, q AccessLogQuery) ([]AccessLogView, int, error)

func (*Repository) ListAccessLogStatsByCountry

func (r *Repository) ListAccessLogStatsByCountry(ctx context.Context, from, to time.Time) ([]AccessLogCountryStat, error)

ListAccessLogStatsByCountry returns request counts grouped by country for all rows within the [from, to] time window. Only rows with GeoIP data are included.

func (*Repository) ListUserAccessRows added in v0.3.0

func (r *Repository) ListUserAccessRows(ctx context.Context) ([]UserAccessRow, error)

type UserAccessEditor added in v0.3.0

type UserAccessEditor struct {
	User          UserSummary
	AllowAllHosts bool
	Summary       UserAccessSummary
	GroupOptions  []UserAccessGroupOption
	HostOptions   []UserAccessHostOption
}

type UserAccessGroupOption added in v0.3.0

type UserAccessGroupOption struct {
	ID       hostaccess.HostGroupID
	Name     string
	Icon     *string
	Selected bool
	Hosts    []hostaccess.KnownHostRef
}

type UserAccessHostOption added in v0.3.0

type UserAccessHostOption struct {
	ID             hostaccess.KnownHostID
	FQDN           string
	Icon           *string
	DirectSelected bool
	Effective      bool
	GrantingGroups []GroupRef
	AccessKind     HostAccessKind
}

type UserAccessRow added in v0.3.0

type UserAccessRow struct {
	ID                 auth.UserID
	DisplayName        string
	Email              string
	Role               auth.Role
	AllowAllHosts      bool
	EffectiveHostCount int
	GrantedGroups      []GroupRef
}

type UserAccessSummary added in v0.3.0

type UserAccessSummary struct {
	TotalHosts     int
	EffectiveHosts int
	DirectHosts    int
	// GroupOnlyHosts counts hosts reachable exclusively via a granted group (not also directly).
	// Useful for "you would lose access to N hosts if all groups were revoked."
	GroupOnlyHosts int
}

type UserSummary added in v0.3.0

type UserSummary struct {
	ID          auth.UserID
	DisplayName string
	Email       string
	Role        auth.Role
}

type UserView added in v0.3.0

type UserView struct {
	ID                  auth.UserID  `db:"id"`
	Username            string       `db:"username"`
	DisplayName         string       `db:"display_name"`
	Email               string       `db:"email"`
	Role                auth.Role    `db:"role"`
	MustChangePassword  bool         `db:"must_change_password"`
	BypassHostAllowlist bool         `db:"bypass_host_allowlist"`
	CreatedBy           *auth.UserID `db:"created_by"`
	CreatedAt           time.Time    `db:"created_at"`
}

Jump to

Keyboard shortcuts

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