Skip to content

Commit

Permalink
Clarify help about wildcards
Browse files Browse the repository at this point in the history
This commit improves the help texts that describe when you can use
wildcards. It also automatically wraps the parameters in wildcards in
some cases.
Finally, it adds a few commands to the test suite,

Partially takes care of #136.
  • Loading branch information
oyvindhagberg committed Jun 7, 2023
1 parent 1261bbc commit 7cbbd65
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 10 deletions.
4 changes: 3 additions & 1 deletion ci/testsuite
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ network remove 2001:db8::/64 -f
# - excluded ip ranges
# - network info
# - setting network category, location, vlan
#TODO: network find
network create -network 10.0.1.0/24 -desc "Frozzzen" # frozen network
network set_frozen 10.0.1.0/24
host add somehost -ip 10.0.1.0/24 -contact [email protected] # should require force, because net's frozen
Expand All @@ -56,6 +55,7 @@ network set_description 10.0.1.0/24 "Frozen but has one host"
#network set_location 10.0.1.0/24 Oslo_Norway
network set_vlan 10.0.1.0/24 1234
network info 10.0.1.0/24
network find -network 10.0.1.0/24 -description '*one host*' -vlan 1234 -frozen 1 -reserved 6 -dns_delegated 0 -category Yellow -location Somewhere
host remove somehost
network unset_frozen 10.0.1.0/24
host add otherhost -ip 10.0.1.20 -contact [email protected] # fails because reserved range
Expand Down Expand Up @@ -124,8 +124,10 @@ zone delegation_delete example.org wut.example.org
policy atom_create apple "Here's the description"
policy atom_create -created 2018-07-07 orange "Round and orange"
policy list_atoms *
policy list_atoms ppl
policy role_create fruit "5 a day"
policy list_roles *
policy list_roles fru
policy add_atom fruit apple
policy add_atom fruit orange
policy info orange
Expand Down
74 changes: 74 additions & 0 deletions ci/testsuite-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -5664,6 +5664,24 @@
"10.0.1.255"
]
},
{
"command": "network find -network 10.0.1.0/24 -description '*one host*' -vlan 1234 -frozen 1 -reserved 6 -dns_delegated 0 -category Yellow -location Somewhere\n"
},
{
"method": "GET",
"url": "/api/v1/networks/?network=10.0.1.0%2F24&description__regex=.%2Aone+host.%2A&vlan=1234&dns_delegated=0&category=Yellow&location=Somewhere&frozen=1&reserved=6",
"data": {},
"status": 200,
"response": {
"count": 0,
"next": null,
"previous": null,
"results": []
}
},
{
"output": "WARNING: : No networks matching the query were found."
},
{
"command": "host remove somehost\n"
},
Expand Down Expand Up @@ -8132,6 +8150,27 @@
]
}
},
{
"command": "policy list_atoms ppl\n"
},
{
"method": "GET",
"url": "/api/v1/hostpolicy/atoms/?name__regex=.%2Appl.%2A",
"data": {},
"status": 200,
"response": {
"count": 1,
"next": null,
"previous": null,
"results": [
{
"roles": [],
"description": "Here's the description",
"name": "apple"
}
]
}
},
{
"command": "policy role_create fruit \"5 a day\"\n"
},
Expand Down Expand Up @@ -8194,6 +8233,41 @@
"results": []
}
},
{
"command": "policy list_roles fru\n"
},
{
"method": "GET",
"url": "/api/v1/hostpolicy/roles/?name__regex=.%2Afru.%2A",
"data": {},
"status": 200,
"response": {
"count": 1,
"next": null,
"previous": null,
"results": [
{
"hosts": [],
"atoms": [],
"description": "5 a day",
"name": "fruit",
"labels": []
}
]
}
},
{
"method": "GET",
"url": "/api/v1/labels/",
"data": {},
"status": 200,
"response": {
"count": 0,
"next": null,
"previous": null,
"results": []
}
},
{
"command": "policy add_atom fruit apple\n"
},
Expand Down
5 changes: 1 addition & 4 deletions mreg_cli/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,7 @@ def find(args):
"""

def _add_param(param, value):
if '*' not in value:
value = f'*{value}*'

param, value = convert_wildcard_to_regex(param, value)
param, value = convert_wildcard_to_regex(param, value, True)
params[param] = value

if not any([args.name, args.comment, args.contact]):
Expand Down
2 changes: 1 addition & 1 deletion mreg_cli/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def find(args: Namespace):
),
Flag(
"-description",
description="Description",
description="Description. Supports * as a wildcard",
metavar="DESCRIPTION",
),
Flag(
Expand Down
8 changes: 4 additions & 4 deletions mreg_cli/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def _print(key, value, padding=20):
print("{1:<{0}} {2}".format(padding, key, value))

params = {}
param, value = convert_wildcard_to_regex('name', args.name)
param, value = convert_wildcard_to_regex('name', args.name, True)
params[param] = value
info = get_list("/api/v1/hostpolicy/atoms/", params=params)
if info:
Expand All @@ -402,7 +402,7 @@ def _print(key, value, padding=20):
callback=list_atoms,
flags=[
Flag('name',
description='Atom name filter (regexp)',
description='Atom name, or part of name. You can use * as a wildcard.',
metavar='FILTER'),
]
)
Expand All @@ -414,7 +414,7 @@ def list_roles(args):
"""

params = {}
param, value = convert_wildcard_to_regex('name', args.name)
param, value = convert_wildcard_to_regex('name', args.name, True)
params[param] = value
info = get_list("/api/v1/hostpolicy/roles/", params=params)
if not info:
Expand Down Expand Up @@ -445,7 +445,7 @@ def list_roles(args):
callback=list_roles,
flags=[
Flag('name',
description='Role name filter (regexp)',
description='Role name, or part of name. You can use * as a wildcard.',
metavar='FILTER'),
]
)
Expand Down

0 comments on commit 7cbbd65

Please sign in to comment.