databag/net/server/internal/configUtil.go

128 lines
3.6 KiB
Go
Raw Normal View History

2022-01-12 21:12:40 +00:00
package databag
import (
2022-07-22 19:28:14 +00:00
"databag/internal/store"
"errors"
"gorm.io/gorm"
)
2022-01-12 21:12:40 +00:00
2022-11-09 22:38:45 +00:00
//CNFPushSupported for allowing push notifications
const CNFPushSupported = "push_notifications"
2023-07-18 05:39:38 +00:00
//CNFEnableOpenAccess for allowing for public account creation
const CNFEnableOpenAccess = "open_access"
2022-07-23 04:39:44 +00:00
2023-07-18 05:39:38 +00:00
//CNFOpenAccessLimit for limiting number of accounts for public creation
const CNFOpenAccessLimit = "account_limit"
2022-07-23 04:39:44 +00:00
//CNFConfigured set when admin token has been set
2022-07-22 18:01:29 +00:00
const CNFConfigured = "configured"
2022-07-23 04:39:44 +00:00
//CNFToken identifies the admin token
2022-07-22 18:01:29 +00:00
const CNFToken = "token"
2022-07-23 04:39:44 +00:00
//CNFDomain identifies the configured server hostname
2022-07-22 18:01:29 +00:00
const CNFDomain = "domain"
2022-07-23 04:39:44 +00:00
//CNFStorage specifies the storage limit per account
2022-07-22 18:01:29 +00:00
const CNFStorage = "storage"
2022-07-23 04:39:44 +00:00
//CNFAssetPath specifies the path to store assets
2022-07-22 18:01:29 +00:00
const CNFAssetPath = "asset_path"
2022-07-23 04:39:44 +00:00
//CNFScriptPath specifies the path where transform scripts are found
2022-07-22 18:01:29 +00:00
const CNFScriptPath = "script_path"
2022-01-17 05:55:25 +00:00
//CNFAllowUnsealed specified if plantext channels can be created
const CNFAllowUnsealed = "allow_unsealed"
//CNFEnableImage specifies whether node can process image assets
const CNFEnableImage = "enable_image"
//CNFEnableAudio specifies whether node can process audio assets
const CNFEnableAudio = "enable_audio"
//CNFEnableVideo specifies whether node can process video assets
const CNFEnableVideo = "enable_video"
//CNFEnableBinary specifies whether node can attach binary asset
const CNFEnableBinary = "enable_binary"
//CNFKeyType specifies the type of key to use for identity
const CNFKeyType = "key_type"
2023-04-13 07:39:14 +00:00
//CNFEnableIce specifies whether webrtc is enabled
const CNFEnableIce = "enable_ice"
2024-05-30 06:43:16 +00:00
//CNFIceMode specifies if turn service is used
const CNFIceService = "ice_service"
2023-04-13 07:39:14 +00:00
//CNFIceUrl specifies the ice candidate url
const CNFIceUrl = "ice_url"
//CNFIceUrl specifies the ice candidate username
const CNFIceUsername = "ice_username"
//CNFIceUrl specifies the ice candidate url
const CNFIcePassword = "ice_password"
2024-05-21 07:56:25 +00:00
//CNFMFAFailedTime start of mfa failure window
const CNFMFAFailedTime = "mfa_failed_time"
//CNFMFAFailedCount number of failures in window
const CNFMFAFailedCount = "mfa_failed_count"
//CNFMFARequired specified if mfa enabled for admin
const CNFMFAEnabled = "mfa_enabled"
//CNFMFAConfirmed specified if mfa has been confirmed for admin
const CNFMFAConfirmed = "mfa_confirmed"
//CNFMFASecret specified the mfa secret
const CNFMFASecret = "mfa_secret"
//CNFAdminSession sepcifies the admin session token
const CNFAdminSession = "admin_session"
2023-04-13 07:39:14 +00:00
//CNFWebPrivateKey specifies private key for webpush notifications
const CNFWebPrivateKey = "web_private_key"
//CNFWebPublicKey specifies public key for webpush notifications
const CNFWebPublicKey = "web_public_key"
func getStrConfigValue(configID string, empty string) string {
2022-07-22 19:28:14 +00:00
var config store.Config
err := store.DB.Where("config_id = ?", configID).First(&config).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return empty
}
return config.StrValue
2022-01-12 21:12:40 +00:00
}
func getNumConfigValue(configID string, empty int64) int64 {
2022-07-22 19:28:14 +00:00
var config store.Config
err := store.DB.Where("config_id = ?", configID).First(&config).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return empty
}
return config.NumValue
2022-01-12 21:12:40 +00:00
}
func getBoolConfigValue(configID string, empty bool) bool {
2022-07-22 19:28:14 +00:00
var config store.Config
err := store.DB.Where("config_id = ?", configID).First(&config).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return empty
}
return config.BoolValue
2022-01-12 21:12:40 +00:00
}
func getBinConfigValue(configID string, empty []byte) []byte {
2022-07-22 19:28:14 +00:00
var config store.Config
err := store.DB.Where("config_id = ?", configID).First(&config).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return empty
}
return config.BinValue
2022-01-12 21:12:40 +00:00
}