1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-07 18:31:13 +00:00

#48673 - Added Timestamp Cache Handling to metadata.fields (#648)

* added timestamp convertion to metadata.fields

* fixed duration parsing

* fixed tests

* removed tags file

* added comments

* added better error handling

* changed ParseHumanDuration to use Fscanf

* added builtins handling

* adding mock updates

* fixing tests

* another try

* added timestamp convertion to metadata.fields

* addressing comments from @ericpromislow

* converting error to warning

* added template options
This commit is contained in:
Felipe Gehrke
2025-06-16 19:33:28 -03:00
committed by GitHub
parent 2e8a0f2851
commit b3539616e0
13 changed files with 513 additions and 33 deletions

View File

@@ -0,0 +1,41 @@
package common
import (
"strconv"
"strings"
"github.com/rancher/apiserver/pkg/types"
"github.com/rancher/steve/pkg/attributes"
)
// GetIndexValueFromString looks for values between [ ].
// e.g: $.metadata.fields[2], in this case it would return 2
// In case it doesn't find any value between brackets it returns -1
func GetIndexValueFromString(pathString string) int {
idxStart := strings.Index(pathString, "[")
if idxStart == -1 {
return -1
}
idxEnd := strings.Index(pathString[idxStart+1:], "]")
if idxEnd == -1 {
return -1
}
idx, err := strconv.Atoi(pathString[idxStart+1 : idxStart+1+idxEnd])
if err != nil {
return -1
}
return idx
}
// GetColumnDefinitions returns ColumnDefinitions from an APISchema
func GetColumnDefinitions(schema *types.APISchema) []ColumnDefinition {
columns := attributes.Columns(schema)
if columns == nil {
return nil
}
colDefs, ok := columns.([]ColumnDefinition)
if !ok {
return nil
}
return colDefs
}