Skip to content

Commit

Permalink
allow to set the TTL for keys with int + unit
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Labarussias <[email protected]>
  • Loading branch information
Issif authored and poiana committed Aug 4, 2023
1 parent 76aeb18 commit 22a5b0d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ Usage of Falcosidekick-UI:
Listen Port (default "2802", environment "FALCOSIDEKICK_UI_PORT")
-r string
Redis server address (default "localhost:6379", environment "FALCOSIDEKICK_UI_REDIS_URL")
-t int
TTL for keys (default "0", environment "FALCOSIDEKICK_UI_TTL")
-t string
TTL for keys, the format is X<unit>,
with unit (s, m, h, d, W, M, y)" (default "0", environment "FALCOSIDEKICK_UI_TTL")
-u string
User in format <login>:<password> (default "admin:admin", environment "FALCOSIDEKICK_UI_USER")
-w string
Expand Down
6 changes: 6 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ const docTemplate = `{
"dev-mode": {
"type": "boolean"
},
"disable-auth": {
"type": "boolean"
},
"listen-address": {
"description": "DisplayMode string ` + "`" + `json:\"display-mode\"` + "`" + `",
"type": "string"
Expand All @@ -411,6 +414,9 @@ const docTemplate = `{
"log-level": {
"type": "string"
},
"redis-password": {
"type": "string"
},
"redis-server": {
"type": "string"
},
Expand Down
6 changes: 6 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@
"dev-mode": {
"type": "boolean"
},
"disable-auth": {
"type": "boolean"
},
"listen-address": {
"description": "DisplayMode string `json:\"display-mode\"`",
"type": "string"
Expand All @@ -407,6 +410,9 @@
"log-level": {
"type": "string"
},
"redis-password": {
"type": "string"
},
"redis-server": {
"type": "string"
},
Expand Down
4 changes: 4 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ definitions:
type: string
dev-mode:
type: boolean
disable-auth:
type: boolean
listen-address:
description: DisplayMode string `json:"display-mode"`
type: string
listen-port:
type: integer
log-level:
type: string
redis-password:
type: string
redis-server:
type: string
ttl:
Expand Down
7 changes: 6 additions & 1 deletion internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ func ConvertToSeconds(s string) int {
return n * 30 * 24 * 60 * 60
case "y", "year", "years":
return n * 365 * 24 * 60 * 60
default:
o, err := strconv.Atoi(s)
if err != nil {
WriteLog("fatal", "invalid TTL")
}
return o
}
return 0
}

func RemoveDuplicate(input []string) []string {
Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func init() {
redisserver := utils.GetStringFlagOrEnvParam("r", "FALCOSIDEKICK_UI_REDIS_URL", "localhost:6379", "Redis server address")
redispassword := utils.GetStringFlagOrEnvParam("w", "FALCOSIDEKICK_UI_REDIS_PASSWORD", "", "Redis server password")
port := utils.GetIntFlagOrEnvParam("p", "FALCOSIDEKICK_UI_PORT", 2802, "Listen Port")
ttl := utils.GetIntFlagOrEnvParam("t", "FALCOSIDEKICK_UI_TTL", 0, "TTL for keys")
ttl := utils.GetStringFlagOrEnvParam("t", "FALCOSIDEKICK_UI_TTL", "0s", "TTL for keys, the format is X<unit>, with unit (s, m, h, d, W, M, y)")
version := flag.Bool("v", false, "Print version")
dev := utils.GetBoolFlagOrEnvParam("x", "FALCOSIDEKICK_UI_DEV", false, "Allow CORS for development")
loglevel := utils.GetStringFlagOrEnvParam("l", "FALCOSIDEKICK_UI_LOGLEVEL", "info", "Log Level")
Expand All @@ -50,8 +50,9 @@ func init() {
Listen Port (default "2802", environment "FALCOSIDEKICK_UI_PORT")
-r string
Redis server address (default "localhost:6379", environment "FALCOSIDEKICK_UI_REDIS_URL")
-t int
TTL for keys (default "0", environment "FALCOSIDEKICK_UI_TTL")
-t string
TTL for keys, the format is X<unit>,
with unit (s, m, h, d, W, M, y)" (default "0", environment "FALCOSIDEKICK_UI_TTL")
-u string
User in format <login>:<password> (default "admin:admin", environment "FALCOSIDEKICK_UI_USER")
-w string
Expand Down Expand Up @@ -84,7 +85,7 @@ func init() {
config.RedisServer = *redisserver
config.RedisPassword = *redispassword
config.DevMode = *dev
config.TTL = *ttl
config.TTL = utils.ConvertToSeconds(*ttl)
config.LogLevel = *loglevel
config.Credentials = *user
config.DisableAuth = *disableauth
Expand Down

0 comments on commit 22a5b0d

Please sign in to comment.