utils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplicationJson      = "application/json"
	ClaceServiceLocation = "clace"
)
View Source
const (
	PASSWORD_CHARS  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#%^&*()_-+=<>?/|"
	PASSWORD_LENGTH = 16
	BCRYPT_COST     = 10
)
View Source
const (
	INTERNAL_URL_PREFIX     = "/_clace"
	APP_INTERNAL_URL_PREFIX = "/_clace_app"
)
View Source
const DEFAULT_CONFIG = "clace.default.toml"
View Source
const Scheme = "http+unix"

Scheme is the URL scheme used for HTTP over UNIX domain sockets.

Variables

This section is empty.

Functions

func GenerateRandomPassword

func GenerateRandomPassword() (string, error)

GenerateRandomPassword generates a random password

func GetDefaultConfigs

func GetDefaultConfigs() (*GlobalConfig, *ClientConfig, *ServerConfig, error)

func IsEmptyStarlarkString

func IsEmptyStarlarkString(s starlark.String) bool

IsEmptyStarlarkString checks is a starlark string is empty ("" for a go string) starlark.String.String performs repr-style quotation, which is necessary for the starlark.Value contract but a frequent source of errors in API clients. This helper method makes sure it'll work properly

func KillGroup

func KillGroup(process *os.Process) error

KillGroup kills the process group

func LoadClientConfig

func LoadClientConfig(contents string, config *ClientConfig) error

LoadClientConfig load a ClientConfig from the given contents

func LoadGlobalConfig

func LoadGlobalConfig(contents string, config *GlobalConfig) error

LoadGlobalConfig load a GlobalConfig from the given contents

func LoadServerConfig

func LoadServerConfig(contents string, config *ServerConfig) error

LoadServerConfig loads a ServerConfig from the given contents

func MarshalStarlark

func MarshalStarlark(data interface{}) (v starlark.Value, err error)

MarshalStarlark turns go values into starlark types

func SetProcessGroup

func SetProcessGroup(cmd *exec.Cmd)

SetProcessGroup sets the process group flag for the command

func UnmarshalStarlark

func UnmarshalStarlark(x starlark.Value) (val interface{}, err error)

UnmarshalStarlark decodes a starlark.Value into it's golang counterpart

func UnquoteStarlark

func UnquoteStarlark(x starlark.Value) (string, error)

UnquoteStarlark unquotes a starlark string value

Types

type AppAuthnType

type AppAuthnType string

AppAuthnType is the app level authentication type

const (
	AppAuthnDefault AppAuthnType = "default" // Use whatever auth is the default for the system
	AppAuthnNone    AppAuthnType = "none"    // No auth
)

type AppEntry

type AppEntry struct {
	Id          AppId        `json:"id"`
	Path        string       `json:"path"`
	Domain      string       `json:"domain"`
	SourceUrl   string       `json:"source_url"`
	FsPath      string       `json:"fs_path"`
	IsDev       bool         `json:"is_dev"`
	AutoSync    bool         `json:"auto_sync"`
	AutoReload  bool         `json:"auto_reload"`
	UserID      string       `json:"user_id"`
	CreateTime  *time.Time   `json:"create_time"`
	UpdateTime  *time.Time   `json:"update_time"`
	Rules       Rules        `json:"rules"`
	Metadata    Metadata     `json:"metadata"`
	Loads       []string     `json:"loads"`
	Permissions []Permission `json:"permissions"`
}

AppEntry is the application configuration in the DB

type AppId

type AppId string

AppId is the identifier for an App

type AppPathDomain

type AppPathDomain struct {
	Path   string
	Domain string
}

AppPathDomain is a unique identifier for an app, consisting of the path and domain

func CreateAppPathDomain

func CreateAppPathDomain(path, domain string) AppPathDomain

type AuditResult

type AuditResult struct {
	Id                  AppId        `json:"id"`
	NewLoads            []string     `json:"new_loads"`
	NewPermissions      []Permission `json:"new_permissions"`
	ApprovedLoads       []string     `json:"approved_loads"`
	ApprovedPermissions []Permission `json:"approved_permissions"`
	NeedsApproval       bool         `json:"needs_approval"`
}

AuditResult represents the result of an app audit

type ClientConfig

type ClientConfig struct {
	GlobalConfig
	SkipCertCheck bool   `toml:"skip_cert_check"`
	AdminPassword string `toml:"admin_password"`
}

ClientConfig is the configuration for the Clace Client

func NewClientConfigEmbedded

func NewClientConfigEmbedded() (*ClientConfig, error)

NewClientConfigEmbedded reads the embedded toml file and creates a ClientConfig

type CreateAppRequest

type CreateAppRequest struct {
	SourceUrl  string       `json:"source_url"`
	IsDev      bool         `json:"is_dev"`
	AutoSync   bool         `json:"auto_sync"`
	AutoReload bool         `json:"auto_reload"`
	AppAuthn   AppAuthnType `json:"app_authn"`
}

CreateAppRequest is the request body for creating an app

type GlobalConfig

type GlobalConfig struct {
	ConfigFile string `toml:"config_file"`
	AdminUser  string `toml:"admin_user"`
	ServerUri  string `toml:"server_uri"`
}

Config entries shared between client and server

type HttpClient

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

func NewHttpClient

func NewHttpClient(serverUri, user, password string, skipCertCheck bool) *HttpClient

NewHttpClient creates a new HttpClient instance

func (*HttpClient) Delete

func (h *HttpClient) Delete(url string, params url.Values) error

func (*HttpClient) Get

func (h *HttpClient) Get(url string, params url.Values, output any) error

func (*HttpClient) Post

func (h *HttpClient) Post(url string, params url.Values, input any, output any) error

type HttpConfig

type HttpConfig struct {
	Host string `toml:"host"`
	Port int    `toml:"port"`
}

HttpConfig is the configuration for the HTTP server

type HttpsConfig

type HttpsConfig struct {
	Host             string `toml:"host"`
	Port             int    `toml:"port"`
	EnableCertLookup bool   `toml:"enable_cert_lookup"`
	ServiceEmail     string `toml:"service_email"`
	UseStaging       bool   `toml:"use_staging"`
	StorageLocation  string `toml:"storage_location"`
	CertLocation     string `toml:"cert_location"`
}

HttpsConfig is the configuration for the HTTPs server

type LogConfig

type LogConfig struct {
	Level      string `toml:"level"`
	MaxBackups int    `toml:"max_backups"`
	MaxSizeMB  int    `toml:"max_size_mb"`
	Console    bool   `toml:"console"`
	File       bool   `toml:"file"`
}

LogConfig is the configuration for the Logger

type Logger

type Logger struct {
	*zerolog.Logger
}

func NewLogger

func NewLogger(config *LogConfig) *Logger

type Marshaler

type Marshaler interface {
	// MarshalStarlark marshal a custom type to starlark object.
	MarshalStarlark() (starlark.Value, error)
}

Marshaler is the interface use to marshal starlark custom types.

type Metadata

type Metadata struct {
}

Metadata contains the metadata for an app

type MetadataConfig

type MetadataConfig struct {
	DBConnection string `toml:"db_connection"`
	AutoUpgrade  bool   `toml:"auto_upgrade"`
}

MetadataConfig is the configuration for the Metadata persistence layer

type Permission

type Permission struct {
	Plugin    string
	Method    string
	Arguments []string
}

Permission represents a permission granted to an app to run a plugin method with the given arguments

type RequestError

type RequestError struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

RequestError is the error returned by the API

func CreateRequestError

func CreateRequestError(message string, code int) RequestError

func (RequestError) Error

func (r RequestError) Error() string

type Rules

type Rules struct {
	AuthnType AppAuthnType `json:"authn_type"`
}

Rules contains the authentication and authorization rules for an app

type SecurityConfig

type SecurityConfig struct {
	AdminOverTCP        bool   `toml:"admin_over_tcp"`
	AdminPasswordBcrypt string `toml:"admin_password_bcrypt"`
}

SecurityConfig is the configuration for Inter process communication

type ServerConfig

type ServerConfig struct {
	GlobalConfig
	Http     HttpConfig     `toml:"http"`
	Https    HttpsConfig    `toml:"https"`
	Security SecurityConfig `toml:"security"`
	Metadata MetadataConfig `toml:"metadata"`
	Log      LogConfig      `toml:"logging"`
	System   SystemConfig   `toml:"system"`
}

ServerConfig is the configuration for the Clace Server

func NewServerConfigEmbedded

func NewServerConfigEmbedded() (*ServerConfig, error)

NewServerConfigEmbedded reads the embedded toml file and creates a ServerConfig

type SystemConfig

type SystemConfig struct {
	TailwindCSSCommand        string `toml:"tailwindcss_command"`
	DisableFileHashDevMode    bool   `toml:"disable_file_hash_dev_mode"`
	FileWatcherDebounceMillis int    `toml:"file_watcher_debounce_millis"`
	NodePath                  string `toml:"node_path"`
}

SystemConfig is the system level configuration

type Transport

type Transport struct {
	// DialTimeout is deprecated. Use context instead.
	DialTimeout time.Duration
	// RequestTimeout is deprecated and has no effect.
	RequestTimeout time.Duration
	// ResponseHeaderTimeout is deprecated. Use context instead.
	ResponseHeaderTimeout time.Duration
	// contains filtered or unexported fields
}

Transport is a http.RoundTripper that connects to Unix domain sockets.

func (*Transport) RegisterLocation

func (t *Transport) RegisterLocation(loc string, path string)

RegisterLocation registers an URL location and maps it to the given file system path.

Calling RegisterLocation twice for the same location is a programmer error, and causes a panic.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction. See net/http.RoundTripper.

type Unmarshaler

type Unmarshaler interface {
	// UnmarshalStarlark unmarshal a starlark object to custom type.
	UnmarshalStarlark(starlark.Value) error
}

Unmarshaler is the interface use to unmarshal starlark custom types.

Jump to

Keyboard shortcuts

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