-
Notifications
You must be signed in to change notification settings - Fork 408
adjust parser for IOSXE 'show running-config aaa username' to be less rigid #937
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
Changes from all commits
bc8d3d7
48376d2
e0e99f3
f8b2db8
823f3ba
6e3bd3e
5359268
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-------------------------------------------------------------------------------- | ||
New | ||
-------------------------------------------------------------------------------- | ||
* IOSXE | ||
* Modified ShowRunningConfigAAAUsernameSchema(MetaParser): | ||
* added: optional 'autocommand' | ||
* added: optional 'nopassword' | ||
|
||
* IOSXE | ||
* Modified ShowRunningConfigAAAUsername(ShowRunningConfigAAAUsernameSchema) | ||
* Added support for 'autocommand' | ||
* Added support for 'nopassword' | ||
* Added support for multiline usernames | ||
* Added logging (warning) for unsupported options | ||
|
||
-------------------------------------------------------------------------------- | ||
Fix | ||
-------------------------------------------------------------------------------- | ||
* IOSXE | ||
* Modified ShowRunningConfigAAAUsername(ShowRunningConfigAAAUsernameSchema) | ||
* Changed how the cli() function parses arguments and parameters. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
expected_output = { | ||
"username": { | ||
"testuser07": { | ||
"nopassword": True, | ||
"privilege": 3 | ||
}, | ||
"testuser08": { | ||
"common_criteria_policy": "Test-CC", | ||
"privilege": 15, | ||
"secret": { | ||
"secret": "$9$oNguEA9um9vRx.$MsDk0DOy1rzBjKAcySWdNjoKcA7GetG9YNnKOs8S67A", | ||
"type": 9 | ||
} | ||
}, | ||
"testuser09": { | ||
"autocommand": "show ip bgp summary", | ||
"privilege": 15, | ||
"secret": { | ||
"secret": "$9$UuxZCcqGu2IgBU$teHrzSPJK5FgLH0YAnUezoA1JwaqGBcJI4Xb6c3S7tU", | ||
"type": 9 | ||
} | ||
}, | ||
"testuser10": { | ||
"common_criteria_policy": "Test-CC", | ||
"password": { | ||
"password": "lab", | ||
"type": 0 | ||
}, | ||
"privilege": 15 | ||
}, | ||
"testuser11": { | ||
"privilege": 15 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
9400-HA#show running-config aaa username | ||
! | ||
! You may also need to setup a common criteria policy for testing: | ||
! aaa new-model | ||
! aaa common-criteria policy Test-CC | ||
! min-length 1 | ||
username testuser07 privilege 3 nopassword | ||
username testuser08 privilege 15 common-criteria-policy Test-CC secret 9 $9$oNguEA9um9vRx.$MsDk0DOy1rzBjKAcySWdNjoKcA7GetG9YNnKOs8S67A | ||
! Some usernames can span multiple lines: | ||
username testuser09 privilege 15 secret 9 $9$UuxZCcqGu2IgBU$teHrzSPJK5FgLH0YAnUezoA1JwaqGBcJI4Xb6c3S7tU | ||
username testuser09 autocommand show ip bgp summary | ||
username testuser10 privilege 15 common-criteria-policy Test-CC password 0 lab | ||
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually interested in this format. Is this entered exactly as the user entered it, or is it rearranged to fit an underlying order. Does the command only allow options to be added in a particular order? If the order is set in stone, then it's actually possible to write a regular expression that should be able to match anything. It gets a bit difficult if say, both of these are valid
But if only one is valid, then a regular express like this becomes possible
Admittedly, that does become a tad tedious to maintain. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took all of the provided text from the running-config of a virtual device. Ordering for these commands does seem to be static. Whether or not it's the same order on all versions of IOS-XE is beyond me. I see your regex and I like where it's going. Consider something like this borked (but accepted) config:
In this case the Alternatively your regex should work with some nesting. Either way the regex would become significantly more complex. Also note the name |
||
! username with privilege and no password can happen if SSH pubkey auth is used: | ||
username testuser11 privilege 15 |
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.
While we typically discourage the use of
re.search
, it might actually be preferable to use it over a while loopThere 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'm not convinced that
re.search
will be able to successfully identify all of the weird user-configurable portions of the line. Consider this abomonation: