generated from ouzi-dev/bigbang
/
util.go
33 lines (27 loc) · 934 Bytes
/
util.go
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
package credstash
import (
"fmt"
"strconv"
)
func formatCredstashVersion(inputVersion string) (string, error) {
_, err := strconv.Atoi(inputVersion)
if err != nil {
log.Error(err, "Could not parse credstash version into number",
"Secret.Version", inputVersion)
return "", err
}
// we already have a padded version so nothing to do
if len(inputVersion) == credstashVersionLength {
return inputVersion, nil
}
// version is too longßß
if len(inputVersion) > credstashVersionLength {
return "", fmt.Errorf("version string is longer than supported. Maximum length is %d characters",
credstashVersionLength)
}
// pad version with leading zeros until we reach credstashVersionLength
// format becomes something like %019s which means pad the string until there's 19 0s
format := fmt.Sprintf("%s%ds", "%0", credstashVersionLength)
newVersion := fmt.Sprintf(format, inputVersion)
return newVersion, nil
}