forked from secureCodeBox/secureCodeBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl_expiration_duration.go
More file actions
46 lines (39 loc) · 978 Bytes
/
Copy pathurl_expiration_duration.go
File metadata and controls
46 lines (39 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0
package utils
import (
"errors"
"os"
"time"
)
type ControllerType int
const (
ScanController ControllerType = iota
HookController
ParserController
)
func (e ControllerType) String() string {
switch e {
case ScanController:
return "SCAN"
case HookController:
return "HOOK"
case ParserController:
return "PARSER"
default:
return "WRONG_ENUM_NUMBER"
}
}
func GetUrlExpirationDuration(controller ControllerType) (time.Duration, error) {
urlExpirationTimeString, envOk := os.LookupEnv("URL_EXPIRATION_" + controller.String())
if !envOk {
// env varible not set, use an hour as default
return time.Hour, nil
}
urlExpirationDuration, durationOk := time.ParseDuration(urlExpirationTimeString)
if durationOk != nil {
return time.Hour, errors.New("Cannot parse env variable: URL_EXPIRATION_" + controller.String())
}
return urlExpirationDuration, nil
}