-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add utility to parse standard policy path #1218
Conversation
@@ -188,6 +188,55 @@ func getResourceIDFromResourcePath(rPath string, rType string) string { | |||
return "" | |||
} | |||
|
|||
func parseStandardPolicyPath(path string) ([]string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you just need to collect the list of identifiers in the policy path, or will it also matter figuring out what is what?
For instance in:
/orgs/myorg/projects/myproj/infra/tier-1s/mygw1"
parent[2] is a router id
but in:
/orgs/myorg/projects/myproj/vpcs/myvpc/tier-1s/mygw1
parent[2] is a VPC id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parent list will be used as parameters for API calls, so in case of orgs/projects/vpc the ids will be used as parameters in API call in the same way as gw id or segment id would be used.
Can we utilize this (or share code with) in nsxtPolicyPathResourceImporterHelper? I've already added VPC support in PR #1217 |
b626744
to
66e3ed1
Compare
Good point, I think |
66e3ed1
to
a5473d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, lmk if we can do a little bit more for testing.
|
||
func TestParseStandardPolicyPath(t *testing.T) { | ||
|
||
testData := []policyPathTest{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add negative test with invalid path and verify code fails as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a negative test below
} | ||
if infraPath { | ||
// continue after infra marker | ||
if segments[idx] != "infra" && segments[idx] != "global-infra" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember a case where we can have global-infra for a project-scoped resource.
At the same time, I don't think that a special case to handle only "infra" when in org scope is mandatory
a5473d2
to
7a02a18
Compare
In addition, add helper to get or generate ID with parent path These helpers will be used in generated resources Signed-off-by: Anna Khmelnitsky <[email protected]>
7a02a18
to
fd8496b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I have already been pedant enough here...
This utility will be used in generated resources