mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
K8s: Update stack id validation (#82275)
This commit is contained in:
parent
c9593531ef
commit
87c3d0fb6a
@ -67,10 +67,12 @@ func ParseNamespace(ns string) (NamespaceInfo, error) {
|
||||
}
|
||||
|
||||
if strings.HasPrefix(ns, "stack-") {
|
||||
info.StackID = ns[6:]
|
||||
if len(info.StackID) < 1 {
|
||||
stackIDStr := ns[6:]
|
||||
stackID, err := strconv.Atoi(stackIDStr)
|
||||
if err != nil || stackID < 1 {
|
||||
return info, fmt.Errorf("invalid stack id")
|
||||
}
|
||||
info.StackID = stackIDStr
|
||||
info.OrgID = 1
|
||||
return info, nil
|
||||
}
|
||||
|
@ -77,15 +77,15 @@ func TestParseNamespace(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid stack",
|
||||
name: "invalid stack id (must be an int)",
|
||||
expectErr: true,
|
||||
namespace: "stack-abcdef",
|
||||
expected: request.NamespaceInfo{
|
||||
OrgID: 1,
|
||||
StackID: "abcdef",
|
||||
OrgID: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid stack id",
|
||||
name: "invalid stack id (must be provided)",
|
||||
namespace: "stack-",
|
||||
expectErr: true,
|
||||
expected: request.NamespaceInfo{
|
||||
@ -93,12 +93,19 @@ func TestParseNamespace(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid stack id (too short)",
|
||||
namespace: "stack-",
|
||||
name: "invalid stack id (cannot be 0)",
|
||||
namespace: "stack-0",
|
||||
expectErr: true,
|
||||
expected: request.NamespaceInfo{
|
||||
OrgID: -1,
|
||||
StackID: "",
|
||||
OrgID: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid stack",
|
||||
namespace: "stack-1",
|
||||
expected: request.NamespaceInfo{
|
||||
OrgID: 1,
|
||||
StackID: "1",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user