forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Azure sdk support for network acls (Azure#38511)
* refactor code * refactor code * Adding IP based access control to SDK * Added test and change logs * Examples to choose one of three Public network access settings * resolved circular dependency * resolved circular dependency * Added Ip based access control support to hub workspace * updated changelog file * removed ipallowlist dependencey * resolved ManagedServiceIdentity version icompatibility issue * fixed breaking test * reformatted code * reformatted code * removed doc example * code refactor * Fixed Generate API Stubs issue * Fixed Generate API Stubs issue * refactor code * add doc string * add doc string * add doc string * add doc string * add doc string * add doc string
- Loading branch information
1 parent
2faf4cd
commit 75b4da9
Showing
12 changed files
with
280 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
sdk/ml/azure-ai-ml/azure/ai/ml/_schema/workspace/network_acls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# --------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# --------------------------------------------------------- | ||
|
||
from marshmallow import ValidationError, fields, post_load, validates_schema | ||
|
||
from azure.ai.ml._schema.core.schema import PathAwareSchema | ||
from azure.ai.ml.entities._workspace.network_acls import DefaultActionType, IPRule, NetworkAcls | ||
|
||
|
||
class IPRuleSchema(PathAwareSchema): | ||
"""Schema for IPRule.""" | ||
|
||
value = fields.Str(required=True) | ||
|
||
@post_load | ||
def make(self, data, **kwargs): # pylint: disable=unused-argument | ||
"""Create an IPRule object from the marshmallow schema. | ||
:param data: The data from which the IPRule is being loaded. | ||
:type data: OrderedDict[str, Any] | ||
:returns: An IPRule object. | ||
:rtype: azure.ai.ml.entities._workspace.network_acls.NetworkAcls.IPRule | ||
""" | ||
return IPRule(**data) | ||
|
||
|
||
class NetworkAclsSchema(PathAwareSchema): | ||
"""Schema for NetworkAcls. | ||
:param default_action: Specifies the default action when no IP rules are matched. | ||
:type default_action: str | ||
:param ip_rules: Rules governing the accessibility of a resource from a specific IP address or IP range. | ||
:type ip_rules: Optional[List[IPRule]] | ||
""" | ||
|
||
default_action = fields.Str(required=True) | ||
ip_rules = fields.List(fields.Nested(IPRuleSchema), allow_none=True) | ||
|
||
@post_load | ||
def make(self, data, **kwargs): # pylint: disable=unused-argument | ||
"""Create a NetworkAcls object from the marshmallow schema. | ||
:param data: The data from which the NetworkAcls is being loaded. | ||
:type data: OrderedDict[str, Any] | ||
:returns: A NetworkAcls object. | ||
:rtype: azure.ai.ml.entities._workspace.network_acls.NetworkAcls | ||
""" | ||
return NetworkAcls(**data) | ||
|
||
@validates_schema | ||
def validate_schema(self, data, **kwargs): # pylint: disable=unused-argument | ||
"""Validate the NetworkAcls schema. | ||
:param data: The data to validate. | ||
:type data: OrderedDict[str, Any] | ||
:raises ValidationError: If the schema is invalid. | ||
""" | ||
if data["default_action"] not in set([DefaultActionType.DENY, DefaultActionType.ALLOW]): | ||
raise ValidationError("Invalid value for default_action. Must be 'Deny' or 'Allow'.") | ||
|
||
if data["default_action"] == DefaultActionType.DENY and not data.get("ip_rules"): | ||
raise ValidationError("ip_rules must be provided when default_action is 'Deny'.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.