Documentation
¶
Overview ¶
The commmon package provides structs and functions for external code to interact with this gateway service.
Index ¶
- Constants
- Variables
- func GetMessageBusAddress(runtimePath string) (string, error)
- func GetPublicKey(runtimePath string) (*ecdsa.PublicKey, error)
- func InternalAuthorization(runtimePath string) string
- func InternalRequestEditor(runtimePath string) func(ctx context.Context, req *http.Request) error
- func IsInternalRequest(realIP, authorization, runtimePath string) bool
- func ListenGatewayPortChanges(ctx context.Context, callback GatewayPortChangeCallback, ...) error
- func MessageBusSocketPath(runtimePath string) string
- func PrintEventTypesAsMarkdown(sourceID, version string, eventTypes []EventType)
- func PublishEventInSocket(ctx context.Context, runtimePath, sourceID, name string, ...) (*http.Response, error)
- func WriteInternalSecret(runtimePath string) error
- type AppManageService
- type EventType
- type GatewayPortChangeCallback
- type GatewayPortConfig
- type GatewayPortWatcher
- type GatewayPortWatcherOption
- type ManagementService
- type NotifyService
- type NvidiaGPUInfo
- type ParsedToken
- type PropertyType
- type ShareService
Constants ¶
const ( AppManageURLFilename = "app-management.url" APIComposeInfo = "/v2/app_management/compose" APIComposeStatus = "/v2/app_management/compose" )
const ( ManagementURLFilename = "management.url" StaticURLFilename = "static.url" APIGatewayRoutes = "/v1/gateway/routes" APIGatewayPort = "/v1/gateway/port" )
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 )
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" )
const ( CasaOSURLFilename = "casaos.url" APICasaOSNotify = "/v1/notify" )
const ( UserServiceAddressFilename = "user-service.url" GatewaySockFilename = "zimaos-gateway.sock" )
const (
)
const InternalSecretFilename = "internal.secret"
InternalSecretFilename is the file in the runtime path that holds the secret of this boot.
Variables ¶
var ( // DefaultGatewayConfigPath is the default gateway config file path. DefaultGatewayConfigPath = filepath.Join(constants.DefaultConfigPath, GatewayConfigFilename) )
Functions ¶
func GetMessageBusAddress ¶
func GetPublicKey ¶
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
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
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
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
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 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
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.
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 ShareService ¶
type ShareService interface {
}
func NewShareService ¶
func NewShareService(runtimePath string) ShareService