external

package
v0.4.27 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

The commmon package provides structs and functions for external code to interact with this gateway service.

Index

Constants

View Source
const (
	AppManageURLFilename = "app-management.url"
	APIComposeInfo       = "/v2/app_management/compose"
	APIComposeStatus     = "/v2/app_management/compose"
)
View Source
const (
	ManagementURLFilename = "management.url"
	StaticURLFilename     = "static.url"
	APIGatewayRoutes      = "/v1/gateway/routes"
	APIGatewayPort        = "/v1/gateway/port"
)
View Source
const (
	// GatewayConfigFilename is the gateway config file name under /etc/casaos.
	GatewayConfigFilename = "gateway.ini"
	// DefaultGatewayPortWatcherPollInterval is used when fsnotify is unavailable.
	DefaultGatewayPortWatcherPollInterval = 10 * time.Second
)
View Source
const (
	MessageBusAddressFilename = "message-bus.url"
	APIMessageBus             = "/v2/message_bus"

	// MessageBusSocketFilename is the unix socket, in the runtime path, where
	// the message bus takes events.
	MessageBusSocketFilename = "message-bus.sock"
)
View Source
const (
	CasaOSURLFilename = "casaos.url"
	APICasaOSNotify   = "/v1/notify"
)
View Source
const (
	UserServiceAddressFilename = "user-service.url"
	GatewaySockFilename        = "zimaos-gateway.sock"
)
View Source
const (
	APICasaOSShare = "/v1/samba/shares"
)
View Source
const InternalSecretFilename = "internal.secret"

InternalSecretFilename is the file in the runtime path that holds the secret of this boot.

Variables

View Source
var (
	// DefaultGatewayConfigPath is the default gateway config file path.
	DefaultGatewayConfigPath = filepath.Join(constants.DefaultConfigPath, GatewayConfigFilename)
)

Functions

func GetMessageBusAddress

func GetMessageBusAddress(runtimePath string) (string, error)

func GetPublicKey

func GetPublicKey(runtimePath string) (*ecdsa.PublicKey, error)

GetPublicKey is the key user-service signs tokens with: asked for every ten seconds, and the key last seen in between. When user-service does not answer -- restarting, or held still for a backup of the box -- the key last seen goes on validating: the key does not change while it is down, and a dashboard that was logged in a second ago has no reason to be logged out by a restart. A service that never saw a key has nothing to check with, and says so.

func InternalAuthorization added in v0.4.27

func InternalAuthorization(runtimePath string) string

InternalAuthorization returns the Authorization value that makes a request internal, "Internal <secret>", or "" when the secret cannot be read. It is for what a request editor does not fit, such as the Config.Header of a websocket handshake. Send it to loopback addresses only.

func InternalRequestEditor added in v0.4.26

func InternalRequestEditor(runtimePath string) func(ctx context.Context, req *http.Request) error

InternalRequestEditor is for the API clients oapi-codegen generates, which do not go through the HTTP helpers of this module and so never sent the secret: pass it to their WithRequestEditorFn, and a request to one of this box's services carries it like every other internal call. Only loopback destinations get it, and a request that already has an Authorization header keeps its own.

func IsInternalRequest added in v0.4.24

func IsInternalRequest(realIP, authorization, runtimePath string) bool

IsInternalRequest reports whether a request comes from one of this box's services: from loopback, with the secret of this boot.

func ListenGatewayPortChanges

func ListenGatewayPortChanges(ctx context.Context, callback GatewayPortChangeCallback, opts ...GatewayPortWatcherOption) error

ListenGatewayPortChanges watches gateway.ini until ctx is canceled.

func MessageBusSocketPath added in v0.4.27

func MessageBusSocketPath(runtimePath string) string

MessageBusSocketPath is where the message bus listens for events over a unix socket: in the runtime path, which only root can write. It used to be /tmp/message-bus.sock, a name any local user could take first.

func PrintEventTypesAsMarkdown

func PrintEventTypesAsMarkdown(sourceID, version string, eventTypes []EventType)

func PublishEventInSocket

func PublishEventInSocket(ctx context.Context, runtimePath, sourceID, name string, properties map[string]string) (*http.Response, error)

PublishEventInSocket posts an event to the message bus through its unix socket in runtimePath. The response comes back with its body closed.

func WriteInternalSecret added in v0.4.24

func WriteInternalSecret(runtimePath string) error

WriteInternalSecret writes a fresh secret for this boot, readable by root only.

Types

type AppManageService

type AppManageService interface {
	GetAppInfo(storeId string) (model.ComposeAppWithStoreInfo, error)
	PutAppStatus(storeId string, status string) (bool, error)
}

func NewAppManageService

func NewAppManageService(RuntimePath string) (AppManageService, error)

type EventType

type EventType struct {
	Name             string
	SourceID         string
	PropertyTypeList []PropertyType
}

type GatewayPortChangeCallback

type GatewayPortChangeCallback func(config GatewayPortConfig)

GatewayPortChangeCallback receives valid gateway port config changes.

type GatewayPortConfig

type GatewayPortConfig struct {
	HTTPEnabled  bool `json:"http_enabled"`
	HTTPPort     int  `json:"http_port"`
	HTTPSPort    int  `json:"https_port"`
	HTTPSEnabled bool `json:"https_enabled"`
}

GatewayPortConfig contains gateway HTTP and HTTPS listen settings.

func ReadGatewayPortConfig

func ReadGatewayPortConfig(configPath string) (GatewayPortConfig, error)

ReadGatewayPortConfig reads HTTP and HTTPS port settings from gateway.ini.

type GatewayPortWatcher

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

GatewayPortWatcher watches gateway.ini with fsnotify first and polling as fallback.

func NewGatewayPortWatcher

func NewGatewayPortWatcher(callback GatewayPortChangeCallback, opts ...GatewayPortWatcherOption) *GatewayPortWatcher

NewGatewayPortWatcher creates a gateway port watcher.

func (*GatewayPortWatcher) Watch

func (w *GatewayPortWatcher) Watch(ctx context.Context) error

Watch blocks until ctx is canceled. It uses fsnotify first, then falls back to polling by mtime and size.

type GatewayPortWatcherOption

type GatewayPortWatcherOption func(*GatewayPortWatcher)

GatewayPortWatcherOption configures GatewayPortWatcher.

func WithGatewayPortConfigPath

func WithGatewayPortConfigPath(configPath string) GatewayPortWatcherOption

WithGatewayPortConfigPath overrides the gateway.ini path.

func WithGatewayPortPollInterval

func WithGatewayPortPollInterval(interval time.Duration) GatewayPortWatcherOption

WithGatewayPortPollInterval overrides the fallback polling interval.

type ManagementService

type ManagementService interface {
	CreateRoute(route *model.Route) error
	ChangePort(request *model.ChangePortRequest) error
	GetPort() (error, string)
}

func NewManagementService

func NewManagementService(RuntimePath string) (ManagementService, error)

type NotifyService

type NotifyService interface {
	SendNotify(path string, message interface{}) error
	SendSystemStatusNotify(message map[string]interface{}) error
}

func NewNotifyService

func NewNotifyService(runtimePath string) NotifyService

type NvidiaGPUInfo

type NvidiaGPUInfo struct {
	Index         int
	UUID          string
	DriverVersion string
	Name          string
	GPUSerial     string
}

func NvidiaGPUInfoList

func NvidiaGPUInfoList() ([]NvidiaGPUInfo, error)

func NvidiaGPUInfoListWithSMI

func NvidiaGPUInfoListWithSMI() ([]NvidiaGPUInfo, error)

type ParsedToken

type ParsedToken struct {
	Valid     bool   `json:"valid"`
	ExpiresAt int64  `json:"expires_at"`
	Username  string `json:"username"`
	Role      string `json:"role"`
	UserID    int    `json:"user_id"`
}

func ParseToken

func ParseToken(token string) (*ParsedToken, error)

type PropertyType

type PropertyType struct {
	Name        string
	Description *string
	Example     *string
}

type ShareService

type ShareService interface {
	DeleteShare(id string) error
}

func NewShareService

func NewShareService(runtimePath string) ShareService

Jump to

Keyboard shortcuts

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