Skip to content

Commit 7457a36

Browse files
karthik-gumpuKarthik Gumpu (from Dev Box)
andauthored
Add commands for NSP Logging configuration - Microsoft.Network (#8137)
* Add commands for NSP Loggign configuration * Update change history * Add tests * Updated commands * Add examples * Updated contract * Remove default value in Update command * Update tests --------- Co-authored-by: Karthik Gumpu (from Dev Box) <karthikgumpu@microsoft.com>
1 parent 242851d commit 7457a36

File tree

16 files changed

+1885
-307
lines changed

16 files changed

+1885
-307
lines changed

src/nsp/HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Release History
44
===============
55
===============
66

7+
##### 1.0.0b3
8+
++++++
9+
New commands added:
10+
* perimeter logging-configuration: create, delete, show, update
11+
712
##### 1.0.0b2
813
++++++
914
No new commands added. Flatten false the properties of the command output.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"network perimeter logging-configuration",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage Network Security Perimeter Logging Configuration
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from .__cmd_group import *
12+
from ._create import *
13+
from ._delete import *
14+
from ._show import *
15+
from ._update import *
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command(
15+
"network perimeter logging-configuration create",
16+
)
17+
class Create(AAZCommand):
18+
"""Create NSP logging configuration.
19+
20+
:example: Create Nsp Logging Configuration
21+
az network perimeter logging-configuration create --perimeter-name nsp1 --resource-group rg1 --enabled-log-categories "[NspPublicInboundPerimeterRulesDenied,NspPublicOutboundPerimeterRulesDenied]"
22+
"""
23+
24+
_aaz_info = {
25+
"version": "2023-08-01-preview",
26+
"resources": [
27+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/networksecurityperimeters/{}/loggingconfigurations/{}", "2023-08-01-preview"],
28+
]
29+
}
30+
31+
def _handler(self, command_args):
32+
super()._handler(command_args)
33+
self._execute_operations()
34+
return self._output()
35+
36+
_args_schema = None
37+
38+
@classmethod
39+
def _build_arguments_schema(cls, *args, **kwargs):
40+
if cls._args_schema is not None:
41+
return cls._args_schema
42+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
43+
44+
# define Arg Group ""
45+
46+
_args_schema = cls._args_schema
47+
_args_schema.logging_configuration_name = AAZStrArg(
48+
options=["-n", "--name", "--logging-configuration-name"],
49+
help="The name of the NSP logging configuration. Accepts 'instance' as name.",
50+
required=True,
51+
default="instance",
52+
)
53+
_args_schema.perimeter_name = AAZStrArg(
54+
options=["--perimeter-name"],
55+
help="The name of the network security perimeter.",
56+
required=True,
57+
)
58+
_args_schema.resource_group = AAZResourceGroupNameArg(
59+
required=True,
60+
)
61+
62+
# define Arg Group "Properties"
63+
64+
_args_schema = cls._args_schema
65+
_args_schema.enabled_log_categories = AAZListArg(
66+
options=["--enabled-log-categories"],
67+
arg_group="Properties",
68+
help="The log categories to enable in the NSP logging configuration.",
69+
)
70+
_args_schema.version = AAZStrArg(
71+
options=["--version"],
72+
arg_group="Properties",
73+
help="The version of the NSP logging configuration.",
74+
)
75+
76+
enabled_log_categories = cls._args_schema.enabled_log_categories
77+
enabled_log_categories.Element = AAZStrArg()
78+
return cls._args_schema
79+
80+
def _execute_operations(self):
81+
self.pre_operations()
82+
self.NspLoggingConfigurationCreateOrUpdate(ctx=self.ctx)()
83+
self.post_operations()
84+
85+
@register_callback
86+
def pre_operations(self):
87+
pass
88+
89+
@register_callback
90+
def post_operations(self):
91+
pass
92+
93+
def _output(self, *args, **kwargs):
94+
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
95+
return result
96+
97+
class NspLoggingConfigurationCreateOrUpdate(AAZHttpOperation):
98+
CLIENT_TYPE = "MgmtClient"
99+
100+
def __call__(self, *args, **kwargs):
101+
request = self.make_request()
102+
session = self.client.send_request(request=request, stream=False, **kwargs)
103+
if session.http_response.status_code in [200]:
104+
return self.on_200(session)
105+
106+
return self.on_error(session.http_response)
107+
108+
@property
109+
def url(self):
110+
return self.client.format_url(
111+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkSecurityPerimeters/{networkSecurityPerimeterName}/loggingConfigurations/{loggingConfigurationName}",
112+
**self.url_parameters
113+
)
114+
115+
@property
116+
def method(self):
117+
return "PUT"
118+
119+
@property
120+
def error_format(self):
121+
return "ODataV4Format"
122+
123+
@property
124+
def url_parameters(self):
125+
parameters = {
126+
**self.serialize_url_param(
127+
"loggingConfigurationName", self.ctx.args.logging_configuration_name,
128+
required=True,
129+
),
130+
**self.serialize_url_param(
131+
"networkSecurityPerimeterName", self.ctx.args.perimeter_name,
132+
required=True,
133+
),
134+
**self.serialize_url_param(
135+
"resourceGroupName", self.ctx.args.resource_group,
136+
required=True,
137+
),
138+
**self.serialize_url_param(
139+
"subscriptionId", self.ctx.subscription_id,
140+
required=True,
141+
),
142+
}
143+
return parameters
144+
145+
@property
146+
def query_parameters(self):
147+
parameters = {
148+
**self.serialize_query_param(
149+
"api-version", "2023-08-01-preview",
150+
required=True,
151+
),
152+
}
153+
return parameters
154+
155+
@property
156+
def header_parameters(self):
157+
parameters = {
158+
**self.serialize_header_param(
159+
"Content-Type", "application/json",
160+
),
161+
**self.serialize_header_param(
162+
"Accept", "application/json",
163+
),
164+
}
165+
return parameters
166+
167+
@property
168+
def content(self):
169+
_content_value, _builder = self.new_content_builder(
170+
self.ctx.args,
171+
typ=AAZObjectType,
172+
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
173+
)
174+
_builder.set_prop("properties", AAZObjectType)
175+
176+
properties = _builder.get(".properties")
177+
if properties is not None:
178+
properties.set_prop("enabledLogCategories", AAZListType, ".enabled_log_categories")
179+
properties.set_prop("version", AAZStrType, ".version")
180+
181+
enabled_log_categories = _builder.get(".properties.enabledLogCategories")
182+
if enabled_log_categories is not None:
183+
enabled_log_categories.set_elements(AAZStrType, ".")
184+
185+
return self.serialize_content(_content_value)
186+
187+
def on_200(self, session):
188+
data = self.deserialize_http_content(session)
189+
self.ctx.set_var(
190+
"instance",
191+
data,
192+
schema_builder=self._build_schema_on_200
193+
)
194+
195+
_schema_on_200 = None
196+
197+
@classmethod
198+
def _build_schema_on_200(cls):
199+
if cls._schema_on_200 is not None:
200+
return cls._schema_on_200
201+
202+
cls._schema_on_200 = AAZObjectType()
203+
204+
_schema_on_200 = cls._schema_on_200
205+
_schema_on_200.etag = AAZStrType(
206+
flags={"read_only": True},
207+
)
208+
_schema_on_200.id = AAZStrType(
209+
flags={"read_only": True},
210+
)
211+
_schema_on_200.name = AAZStrType(
212+
flags={"read_only": True},
213+
)
214+
_schema_on_200.properties = AAZObjectType()
215+
_schema_on_200.type = AAZStrType(
216+
flags={"read_only": True},
217+
)
218+
219+
properties = cls._schema_on_200.properties
220+
properties.enabled_log_categories = AAZListType(
221+
serialized_name="enabledLogCategories",
222+
)
223+
properties.version = AAZStrType()
224+
225+
enabled_log_categories = cls._schema_on_200.properties.enabled_log_categories
226+
enabled_log_categories.Element = AAZStrType()
227+
228+
return cls._schema_on_200
229+
230+
231+
class _CreateHelper:
232+
"""Helper class for Create"""
233+
234+
235+
__all__ = ["Create"]

0 commit comments

Comments
 (0)