1
0
mirror of https://github.com/rancher/cli.git synced 2026-02-05 09:48:36 +01:00

Merge pull request #304 from StrongMonkey/fix-regex

Add c-m- provisioing v2 format to regex for context
This commit is contained in:
Daishan Peng
2021-09-16 13:13:43 -07:00
committed by GitHub
3 changed files with 5 additions and 2 deletions

View File

@@ -532,8 +532,9 @@ func parseClusterAndProjectID(id string) (string, string, error) {
// Examples:
// c-qmpbm:p-mm62v
// c-qmpbm:project-mm62v
// c-m-j2s7m6lq:p-mm62v
// See https://github.com/rancher/rancher/issues/14400
if match, _ := regexp.MatchString("((local)|(c-[[:alnum:]]{5})):(p|project)-[[:alnum:]]{5}", id); match {
if match, _ := regexp.MatchString("((local)|(c-[[:alnum:]]{5})|(c-m-[[:alnum:]]{8})):(p|project)-[[:alnum:]]{5}", id); match {
parts := SplitOnColon(id)
return parts[0], parts[1], nil
}

View File

@@ -26,6 +26,8 @@ func (s *CommonTestSuite) TestParseClusterAndProjectID(c *check.C) {
testParse(c, "cocal:p-12345", "", "", true)
testParse(c, "c-123:p-123", "", "", true)
testParse(c, "", "", "", true)
testParse(c, "c-m-12345678:p-12345", "c-m-12345678", "p-12345", false)
testParse(c, "c-m-123:p-12345", "", "", true)
}
func testParse(c *check.C, testID, expectedCluster, expectedProject string, errorExpected bool) {

View File

@@ -152,7 +152,7 @@ func getProjectContext(ctx *cli.Context, c *cliclient.MasterClient) (string, err
// Check if given context is in valid format
_, _, err := parseClusterAndProjectID(context)
if err != nil {
return "", fmt.Errorf("Unable to parse context (%s). Please provide context as local:p-xxxxx, c-xxxxx:p-xxxxx, or c-xxxxx:project-xxxxx", context)
return "", fmt.Errorf("Unable to parse context (%s). Please provide context as local:p-xxxxx, c-xxxxx:p-xxxxx, c-xxxxx:project-xxxxx, c-m-xxxxxxxx:p-xxxxx or c-m-xxxxxxxx:project-xxxxx", context)
}
// Check if context exists
_, err = Lookup(c, context, "project")