-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[KeyVault] az keyvault create: support --network-acls
, --network-acls-ips
and --network-acls-vnets
for specifying network rules while creating vault
#12716
Conversation
network_acls_json = json.load(f) | ||
|
||
try: | ||
network_acls_json = json.loads(json.dumps(network_acls_json)) |
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.
why load again?
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.
why load again?
@yungezz Good point, actually I added this sentence in order to make sure the input is a valid JSON. But later I modified the code that makes this part useless... I will remove this part.
for vnet_rule in network_acls_json.get('vnet', []): | ||
items = vnet_rule.split('/') | ||
if len(items) != 2: | ||
raise CLIError('Invalid VNet rule: {}. Format: {{vnet}}/{{subnet}}'.format(vnet_rule)) |
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.
can user input resource id directly?
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.
can user input resource id directly?
@yungezz It should be supported, I will update the code.
keyvault |
2ecfd43
to
f00c115
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, one comment left
az keyvault create --location westus2 --name MyKeyVault --resource-group MyResourceGroup --network-acls network-acls-example.json | ||
- name: Create a key vault with network ACLs specified (use --network-acls, --network-acls-ips and --network-acls-vnets at the same time). | ||
text: | | ||
az keyvault create --location westus2 --name MyKeyVault --resource-group MyResourceGroup --network-acls network-acls-example.json --network-acls-ips 3.4.5.0/24 4.5.6.0/24 --network-acls-vnets vnet1/subnet1 vnet2/subnet2 /subscriptions/000000-0000-0000/resourceGroups/MyResourceGroup/providers/Microsoft.Network/virtualNetworks/vnet3/subnets/subnet3 |
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.
thanks @bim-msft for quick change. Should we fail validation when json and flatten params from user at same time?
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.
thanks @bim-msft for quick change. Should we fail validation when json and flatten params from user at same time?
@yungezz I think it's safe to pass validation for this case which all three params are specified at the same time. As far as I can see, there is one scenario may benefits from this: user has one basic network rules json file, and this file is always applied to a new created vault, also there are different additional rules for each new vault.
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 would think user would like to put all configure rules in one place either one json file or params value. anyway, the validation could be added later after get some feedback
--network-acls
for specifying network rules while creating vault--network-acls
, --network-acls-ips
and --network-acls-vnets
for specifying network rules while creating vault
|
||
- name: Create a key vault with network ACLs specified (use --network-acls to specify IP and VNet rules by using a JSON file). | ||
text: | | ||
az keyvault create --location westus2 --name MyKeyVault --resource-group MyResourceGroup --network-acls network-acls-example.json |
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.
No @
prefix for file?
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.
No
@
prefix for file?
@fengzhou-msft Is @
a convention? I think in this case users don't need to specify the marker explicitly, the program can detect whether it's a JSON string or a JSON filename.
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.
It seems json str or @file.json is a convention, and type=validate_file_or_dict
can be used. @Juliehzl @myronfanqiu any guideline for this?
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.
Tested with validate_file_or_dict, it can support json string and file path with or without @ prefix.
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.
@fengzhou-msft That's good, I will use type=validate_file_or_dict
to refine the code.
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.
@fengzhou-msft For the help messages and examples, I decided not to add @
as a prefix since this is not mandatory and may cause confusion.
Support for AB#1150
Usage:
Use JSON string directly, for the
vnet
field,{vnet_name}/{subnet_name}
and{subnet_id}
are both supported:Use JSON file:
Use flattened parameters (IP rule):
Virtual network rule:
Also, the three parameters
--network-acls
,--network-acls-ips
and--network-acls-vnets
are all optional and they can be used together:This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.