Skip to content
Snippets Groups Projects

Resolve "Improve token usage for users"

Merged Neil-Jocelyn Schark requested to merge 378-improve-token-usage-for-users into master
6 files
+ 64
17
Compare changes
  • Side-by-side
  • Inline
Files
6
+ 21
17
@@ -19,6 +19,8 @@ const (
@@ -19,6 +19,8 @@ const (
defaultJWTDuration = time.Hour * 24
defaultJWTDuration = time.Hour * 24
jwtSecretKey = "jwtSecret"
jwtSecretKey = "jwtSecret"
gNMISubscriptionsFilePathKey = "gNMISubscriptionsPath"
gNMISubscriptionsFilePathKey = "gNMISubscriptionsPath"
 
maxTokensPerUserKey = "maxTokensPerUser"
 
maxTokensPerUserDefault = 100
// RabbitMQ Broker.
// RabbitMQ Broker.
amqpPrefixKey = "amqpPrefix"
amqpPrefixKey = "amqpPrefix"
@@ -81,6 +83,9 @@ var CertFilePath string
@@ -81,6 +83,9 @@ var CertFilePath string
// KeyFilePath si the path to the private key that the controller should use for TLS connections.
// KeyFilePath si the path to the private key that the controller should use for TLS connections.
var KeyFilePath string
var KeyFilePath string
 
// MaxTokensPerUser is the maximum number of tokens a user can have. This determiens the maximum of concurrent logged in sessions per user.
 
var MaxTokensPerUser int
 
// Init gets called on module import.
// Init gets called on module import.
func Init() {
func Init() {
err := InitializeConfig()
err := InitializeConfig()
@@ -107,9 +112,9 @@ func InitializeConfig() error {
@@ -107,9 +112,9 @@ func InitializeConfig() error {
setLogLevel()
setLogLevel()
DatabaseConnection = getStringFromViper(databaseConnectionKey)
DatabaseConnection = viper.GetString(databaseConnectionKey)
FilesystemPathToStores = getStringFromViper(filesystemPathToStores)
FilesystemPathToStores = viper.GetString(filesystemPathToStores)
if FilesystemPathToStores == "" {
if FilesystemPathToStores == "" {
FilesystemPathToStores = "stores"
FilesystemPathToStores = "stores"
}
}
@@ -121,15 +126,20 @@ func InitializeConfig() error {
@@ -121,15 +126,20 @@ func InitializeConfig() error {
JWTSecret = viper.GetString(jwtSecretKey)
JWTSecret = viper.GetString(jwtSecretKey)
GNMISubscriptionsFilePath = getStringFromViper(gNMISubscriptionsFilePathKey)
MaxTokensPerUser = viper.GetInt(maxTokensPerUserKey)
 
if MaxTokensPerUser == 0 {
 
MaxTokensPerUser = maxTokensPerUserDefault
 
}
 
 
GNMISubscriptionsFilePath = viper.GetString(gNMISubscriptionsFilePathKey)
loadAMQPConfig()
loadAMQPConfig()
CAFilePath = getStringFromViper(tlsCACertFileKey)
CAFilePath = viper.GetString(tlsCACertFileKey)
CertFilePath = getStringFromViper(tlsCertFileKey)
CertFilePath = viper.GetString(tlsCertFileKey)
KeyFilePath = getStringFromViper(tlsKeyFileKey)
KeyFilePath = viper.GetString(tlsKeyFileKey)
if err := viper.WriteConfig(); err != nil {
if err := viper.WriteConfig(); err != nil {
return err
return err
@@ -161,12 +171,6 @@ func getUUIDFromViper(viperKey string) (uuid.UUID, error) {
@@ -161,12 +171,6 @@ func getUUIDFromViper(viperKey string) (uuid.UUID, error) {
return parsedUUID, nil
return parsedUUID, nil
}
}
func getStringFromViper(viperKey string) string {
stringFromViper := viper.GetString(viperKey)
return stringFromViper
}
func setChangeTimeout() error {
func setChangeTimeout() error {
e := os.Getenv(changeTimeoutKey)
e := os.Getenv(changeTimeoutKey)
if e != "" {
if e != "" {
@@ -202,9 +206,9 @@ func getDurationFromViper(viperKey, unit string) (time.Duration, error) {
@@ -202,9 +206,9 @@ func getDurationFromViper(viperKey, unit string) (time.Duration, error) {
}
}
func loadAMQPConfig() {
func loadAMQPConfig() {
AMQPPrefix = getStringFromViper(amqpPrefixKey)
AMQPPrefix = viper.GetString(amqpPrefixKey)
AMQPUser = getStringFromViper(amqpUserKey)
AMQPUser = viper.GetString(amqpUserKey)
AMQPPassword = getStringFromViper(amqpPasswordKey)
AMQPPassword = viper.GetString(amqpPasswordKey)
AMQPHost = getStringFromViper(amqpHostKey)
AMQPHost = viper.GetString(amqpHostKey)
AMQPPort = getStringFromViper(amqpPortKey)
AMQPPort = viper.GetString(amqpPortKey)
}
}
Loading