Documentation ¶
Index ¶
- Constants
- Variables
- func LoadRooms() ([]string, error)
- func Password(length int) string
- func Uptime() time.Duration
- type APIServerCreateKeyOptions
- type APIServerOptions
- type ChatBotOptions
- type GlobalDBOptions
- type GlobalMatrixOptions
- type GlobalOptions
- type SetupOptions
- type SetupRateLimitOptions
- type SetupSkipOptions
- type SetupUserOptions
- type UserEntry
- type VersionOptions
Constants ¶
const ( ConfigDir = "." DefaultConfigFile = "config" )
Default configuration settings.
const ( Title = "Imperva Unity - Matrix Chat Demo" ShortTitle = "Matrix Chat Demo" Copyright = "Copyright (c) 2021 Imperva, Inc. All rights reserved." EnvVarPrefix = "MATRIX_CHAT_DEMO_" APIVendorPrefix = "imperva" APIAppPrefix = "matrix-chat-demo" JWTClaimIssuer = "matrix-chat-demo" )
General app settings.
const ( DefaultAccessTokenDuration = "8h" DefaultAPIKeyExpriationDate = "2049-12-31T23:59:59Z" DefaultCreateRoomsRateLimit = 10 DefaultCreateUsersRateLimit = 10 DefaultDBConnectTimeout = 10 DefaultDBName = "matrix-chat-demo" DefaultJoinUsersToDemoRoomsRateLimit = 1 DefaultJoinRandomUsersToRoomsRateLimit = 20 DefaultLogLevel = "info" DefaultMatrixAdminUsername = "admin" DefaultMaxRandomUsersPerRoom = 25 DefaultServerHTTPPort = 8080 DefaultServerHTTPSPort = 8443 DefaultServerListenAddress = "0.0.0.0" )
Default configuration settings.
Variables ¶
var ( // Build is the first 8 characters of the git commit hash. Build string // CodeName is the "code name" for the major release of the product. CodeName string // Config holds the application configuration settings. Config *config // DBClient is the database client object. DBClient *mongo.Client // DBConnection is the handle to the actual database. DBConnection *mongo.Database // DevBuild is a flag to indicate if this is a developer build. DevBuild bool // DevBuildStr is the string version of DevBuild which is passed in at compile-time. DevBuildStr string // MatrixAccessToken holds the access token for the session to the Matrix server. MatrixAccessToken string // SemanticVersion is the actual semantic version of the product. SemanticVersion *semver.Version // Version is the current semver-compatible version of the product. Version string )
var ( DefaultClientProxyHeaders = []string{"True-Client-IP", "X-Forwarded-For"} DefaultDataDir = fmt.Sprintf("%s/data", ConfigDir) DefaultServerSSLCertificateFile = fmt.Sprintf("%s/api_server.crt", ConfigDir) DefaultServerSSLCertificateKeyFile = fmt.Sprintf("%s/api_server.key", ConfigDir) )
Default configuration settings.
Functions ¶
func LoadRooms ¶
LoadRooms returns a list of rooms from the rooms data file.
The following errors are returned by this function: ConfigLoadFailure, ConfigParseFailure
Types ¶
type APIServerCreateKeyOptions ¶
type APIServerCreateKeyOptions struct { // ExpirationTime holds the Unix representation of when the key expires. ExpirationTime int64 // Expires holds the RFC3339 date on which the key expires. Expires string `mapstructure:"expires"` }
APIServerCreateKeyOptions holds specific settings for API key creation requests.
func (*APIServerCreateKeyOptions) Validate ¶
func (o *APIServerCreateKeyOptions) Validate() error
Validate checks and saves any configuration settings from viper and ensures that all values are sane.
The following errors are returned by this function: ConfigValidateFailure
type APIServerOptions ¶
type APIServerOptions struct { // AccessTokenAuthService is used to generate and verify JWT access tokens. AccessTokenAuthService *crypto.JWTAuthHMACService // AccessTokenDuration is the amount of time a JWT access token is valid. AccessTokenDuration time.Duration // AccessTokenSecret is the shared secret used to sign JWT access tokens. AccessTokenSecret string `mapstructure:"access_token_secret"` // ClientProxyHeaders is a list of request headers which may contain the true client IP address. ClientProxyHeaders []string `mapstructure:"client_proxy_headers"` // CreateKey holds any options for the create-key command. CreateKey APIServerCreateKeyOptions `mapstructure:"create_key"` // DoNotLogRequests will not log any of the matching HTTP requests in the list. DoNotLogRequests middleware.ExcludeHTTPRequests `mapstructure:"do_not_log_requests"` // EnableHTTPS indicates whether or not to listen for HTTPS connections. EnableHTTPS bool `mapstructure:"enable_https"` // HTTPPort is the port on which to listen for HTTP connections. HTTPPort uint16 `mapstructure:"http_port"` // HTTPSPort is the port on which to listen for HTTPS connections. HTTPSPort uint16 `mapstructure:"https_port"` // ListenAddress is the IP address on which to listen for connections. ListenAddress string `mapstructure:"listen_address"` // SSLCertificateFile is the public certificate file to use for enabling HTTPS. SSLCertificateFile string `mapstructure:"ssl_certificate_file"` // SSLCertificateFile is the private key file to use for enabling HTTPS. SSLCertificateKeyFile string `mapstructure:"ssl_certificate_key_file"` // StrAccessTokenDuration is the amount of time a JWT access token is valid. StrAccessTokenDuration string `mapstructure:"access_token_duration"` // TrustedProxies is a list of IP addresses or CIDRs of trusted proxies. TrustedProxies []string `mapstructure:"trusted_proxies"` }
APIServerOptions holds specific settings for the demo API server.
func (*APIServerOptions) Validate ¶
func (o *APIServerOptions) Validate() error
Validate checks and saves any configuration settings from viper and ensures that all values are sane.
The following errors are returned by this function: ConfigValidateFailure
type ChatBotOptions ¶
type ChatBotOptions struct { }
ChatBotOptions holds specific settings for the chatbot conversation generator.
func (*ChatBotOptions) Validate ¶
func (o *ChatBotOptions) Validate() error
Validate checks and saves any configuration settings from viper and ensures that all values are sane.
The following errors are returned by this function: ConfigValidateFailure
type GlobalDBOptions ¶
type GlobalDBOptions struct { // ConnectTimeout is the number of seconds to wait when attempting to connect to the api_server. ConnectTimeout uint16 `mapstructure:"connect_timeout"` // DatabaseName is the name of the database in which the actual data is stored. DatabaseName string `mapstructure:"database_name"` // ServerURL holds the URL string for the server connection. ServerURL string `mapstructure:"server_url"` // RedactedServerURL holds the URL for the server connection with the credentials redacted. RedactedServerURL string }
GlobalDBOptions holds specific settings for the database client.
func (*GlobalDBOptions) Validate ¶
func (o *GlobalDBOptions) Validate() error
Validate checks and saves any configuration settings from viper and ensures that all values are sane.
The following errors are returned by this function: ConfigValidateFailure
type GlobalMatrixOptions ¶
type GlobalMatrixOptions struct { // Admin holds admin credentials for setup. Admin struct { // Password is the password for the admin account. Password string `mapstruture:"password"` // Username is the name of the admin account. Username string `mapstruture:"username"` } `mapstructure:"admin"` // ServerURL is the base URL for the Synapse server for API calls. ServerURL string `mapstructure:"server_url"` // UserDomain is the domain in which all users are registered. UserDomain string `mapstructure:"user_domain"` }
GlobalMatrixOptions holds configuration settings for the Matrix server.
func (*GlobalMatrixOptions) Validate ¶
func (o *GlobalMatrixOptions) Validate() error
Validate checks and saves any configuration settings from viper and ensures that all values are sane.
The following errors are returned by this function: ConfigValidateFailure
type GlobalOptions ¶
type GlobalOptions struct { // ConfigDir is the directory in which the configuration file is located. ConfigDir string // DataDir is the location from which to load users, rooms, conversations, etc. DataDir string `mapstructure:"data_dir"` // Database holds the options for the backend database. Database GlobalDBOptions `mapstructure:"db"` // EnableJSONLogging is flag which determines whether or not to log output as JSON instead of text. EnableJSONLogging bool `mapstructure:"enable_json_logging"` // LogLevel holds the the minimum level of events to log. LogLevel zerolog.Level // Matrix holds the Matrix server configuration settings. Matrix GlobalMatrixOptions `mapstructure:"matrix"` // StrLogLevel holds the the minimum level of events to log as a string. StrLogLevel string `mapstructure:"log_level"` }
GlobalOptions holds the global configuration settings.
func (*GlobalOptions) Validate ¶
func (o *GlobalOptions) Validate() error
Validate checks and saves any configuration settings from viper and ensures that all values are sane.
The following errors are returned by this function: ConfigValidateFailure
type SetupOptions ¶
type SetupOptions struct { // BotUsers is a list of bot users to have join the demo rooms. BotUsers []SetupUserOptions `mapstructure:"bot_users"` // DemoRooms is a list of room names to have the demo and bot users join during setup. DemoRooms []string `mapstructure:"demo_rooms"` // DemoUsers is a list of demo users to have join the demo rooms. DemoUsers []SetupUserOptions `mapstructure:"demo_users"` // MaxRandomUsersPerRoom indicates a maximum number of users to randomly join to a room. MaxRandomUsersPerRoom uint16 `mapstructure:"max_random_users_per_room"` // RateLimits is a set of options which specify the maximum number of goroutines to launch to perform a task. RateLimits SetupRateLimitOptions `mapstructure:"rate_limits"` // RegistrationSecret is the name of the shared secret required to register new users through the API. RegistrationSecret string `mapstructure:"registration_secret"` // Skip is a set of options which specify which setup tasks to skip. Skip SetupSkipOptions `mapstructure:"skip"` }
SetupOptions holds configuration settings used for setup.
func (*SetupOptions) Validate ¶
func (o *SetupOptions) Validate() error
Validate checks and saves any configuration settings from viper and ensures that all values are sane.
The following errors are returned by this function: ConfigValidateFailure
type SetupRateLimitOptions ¶
type SetupRateLimitOptions struct { // CreateRooms indicates the maximum number of go routines to use when creating rooms. CreateRooms uint16 `mapstructure:"create_rooms"` // CreateUsers indicates the maximum number of go routines to use when creating users. CreateUsers uint16 `mapstructure:"create_users"` // JoinBotUsersToDemoRooms indicates the maximum number of go routines to use when joining bot users to // demo rooms. JoinBotUsersToDemoRooms uint16 `mapstructure:"join_bot_users_to_demo_rooms"` // JoinDemoUsersToDemoRooms indicates the maximum number of go routines to use when joining demo users // to demo rooms. JoinDemoUsersToDemoRooms uint16 `mapstructure:"join_demo_users_to_demo_rooms"` // JoinRandomUsersToRooms indicates the maximum number of go routines to use when joining random users // to rooms. JoinRandomUsersToRooms uint16 `mapstructure:"join_random_users_to_rooms"` }
SetupRateLimitOptions holds specific configuration settings for how to rate limit setup tasks.
type SetupSkipOptions ¶
type SetupSkipOptions struct { // CreateRooms indicates whether or not to skip creating rooms. CreateRooms bool `mapstructure:"create_rooms"` // CreateUsers indicates whether or not to skip creating users. CreateUsers bool `mapstructure:"create_users"` // JoinBotUsersToDemoRooms indicates whether or not to skip joining bot users to demo rooms. JoinBotUsersToDemoRooms bool `mapstructure:"join_bot_users_to_demo_rooms"` // JoinDemoUsersToDemoRooms indicates whether or not to skip joining demo users to demo rooms. JoinDemoUsersToDemoRooms bool `mapstructure:"join_demo_users_to_demo_rooms"` // JoinRandomUsersToRooms indicates whether or not to skip joining random users to rooms. JoinRandomUsersToRooms bool `mapstructure:"join_random_users_to_rooms"` }
SetupSkipOptions holds specific configuration settings for which setup tasks to skip.
type SetupUserOptions ¶
type SetupUserOptions struct { // DisplayName is the name displayed in the chat rooms. DisplayName string `mapstructure:"display_name"` // Password is the user's password. Password string `mapstructure:"password"` // Username is the local portion of the user ID. Username string `mapstructure:"username"` }
SetupUserOptions holds specific user configuration settings for setup.
type UserEntry ¶
type UserEntry struct { Username string `json:"username"` DisplayName string `json:"display_name"` Password string `json:"password"` }
UserEntry represents a single user to create on the Matrix server.
type VersionOptions ¶
type VersionOptions struct { // Short represents a flag used to determine whether to show just the version or not. Short bool `mapstructure:"short"` // Verbose represents a flag used to determine whether to show verbose version details or not. Verbose bool `mapstructure:"verbose"` }
VersionOptions holds specific settings for the version command.
func (*VersionOptions) Validate ¶
func (o *VersionOptions) Validate() error
Validate checks and saves any configuration settings from viper and ensures that all values are sane.
The following errors are returned by this function: ConfigValidateFailure