|
| 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 | +class QueryExecute(AAZCommand): |
| 15 | + """Executes an Analytics query for data. Doc https://dev.applicationinsights.io/documentation/Using-the-API/Query is an example for using POST with an Analytics query. |
| 16 | + """ |
| 17 | + |
| 18 | + _aaz_info = { |
| 19 | + "version": "v1", |
| 20 | + "resources": [ |
| 21 | + ["data-plane:microsoft.insights", "/apps/{}/query", "v1"], |
| 22 | + ] |
| 23 | + } |
| 24 | + |
| 25 | + def _handler(self, command_args): |
| 26 | + super()._handler(command_args) |
| 27 | + self._execute_operations() |
| 28 | + return self._output() |
| 29 | + |
| 30 | + _args_schema = None |
| 31 | + |
| 32 | + @classmethod |
| 33 | + def _build_arguments_schema(cls, *args, **kwargs): |
| 34 | + if cls._args_schema is not None: |
| 35 | + return cls._args_schema |
| 36 | + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) |
| 37 | + |
| 38 | + # define Arg Group "" |
| 39 | + |
| 40 | + _args_schema = cls._args_schema |
| 41 | + _args_schema.app_id = AAZStrArg( |
| 42 | + options=["--app-id"], |
| 43 | + help="ID of the application. This is Application ID from the API Access settings blade in the Azure portal.", |
| 44 | + required=True, |
| 45 | + ) |
| 46 | + |
| 47 | + # define Arg Group "Body" |
| 48 | + |
| 49 | + _args_schema = cls._args_schema |
| 50 | + _args_schema.applications = AAZListArg( |
| 51 | + options=["--applications"], |
| 52 | + arg_group="Body", |
| 53 | + help="A list of Application IDs for cross-application queries.", |
| 54 | + ) |
| 55 | + _args_schema.query = AAZStrArg( |
| 56 | + options=["--query"], |
| 57 | + arg_group="Body", |
| 58 | + help="The query to execute.", |
| 59 | + required=True, |
| 60 | + ) |
| 61 | + _args_schema.timespan = AAZStrArg( |
| 62 | + options=["--timespan"], |
| 63 | + arg_group="Body", |
| 64 | + help="Optional. The timespan over which to query data. This is an ISO8601 time period value. This timespan is applied in addition to any that are specified in the query expression.", |
| 65 | + ) |
| 66 | + |
| 67 | + applications = cls._args_schema.applications |
| 68 | + applications.Element = AAZStrArg() |
| 69 | + return cls._args_schema |
| 70 | + |
| 71 | + def _execute_operations(self): |
| 72 | + self.pre_operations() |
| 73 | + self.QueryExecute(ctx=self.ctx)() |
| 74 | + self.post_operations() |
| 75 | + |
| 76 | + @register_callback |
| 77 | + def pre_operations(self): |
| 78 | + pass |
| 79 | + |
| 80 | + @register_callback |
| 81 | + def post_operations(self): |
| 82 | + pass |
| 83 | + |
| 84 | + def _output(self, *args, **kwargs): |
| 85 | + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) |
| 86 | + return result |
| 87 | + |
| 88 | + class QueryExecute(AAZHttpOperation): |
| 89 | + CLIENT_TYPE = "AAZMicrosoftInsightsDataPlaneClient_application_insights" |
| 90 | + |
| 91 | + def __call__(self, *args, **kwargs): |
| 92 | + request = self.make_request() |
| 93 | + session = self.client.send_request(request=request, stream=False, **kwargs) |
| 94 | + if session.http_response.status_code in [200]: |
| 95 | + return self.on_200(session) |
| 96 | + |
| 97 | + return self.on_error(session.http_response) |
| 98 | + |
| 99 | + @property |
| 100 | + def url(self): |
| 101 | + return self.client.format_url( |
| 102 | + "/v1/apps/{appId}/query", |
| 103 | + **self.url_parameters |
| 104 | + ) |
| 105 | + |
| 106 | + @property |
| 107 | + def method(self): |
| 108 | + return "POST" |
| 109 | + |
| 110 | + @property |
| 111 | + def error_format(self): |
| 112 | + return "ODataV4Format" |
| 113 | + |
| 114 | + @property |
| 115 | + def url_parameters(self): |
| 116 | + parameters = { |
| 117 | + **self.serialize_url_param( |
| 118 | + "appId", self.ctx.args.app_id, |
| 119 | + required=True, |
| 120 | + ), |
| 121 | + } |
| 122 | + return parameters |
| 123 | + |
| 124 | + @property |
| 125 | + def header_parameters(self): |
| 126 | + parameters = { |
| 127 | + **self.serialize_header_param( |
| 128 | + "Content-Type", "application/json", |
| 129 | + ), |
| 130 | + **self.serialize_header_param( |
| 131 | + "Accept", "application/json", |
| 132 | + ), |
| 133 | + } |
| 134 | + return parameters |
| 135 | + |
| 136 | + @property |
| 137 | + def content(self): |
| 138 | + _content_value, _builder = self.new_content_builder( |
| 139 | + self.ctx.args, |
| 140 | + typ=AAZObjectType, |
| 141 | + typ_kwargs={"flags": {"required": True, "client_flatten": True}} |
| 142 | + ) |
| 143 | + _builder.set_prop("applications", AAZListType, ".applications") |
| 144 | + _builder.set_prop("query", AAZStrType, ".query", typ_kwargs={"flags": {"required": True}}) |
| 145 | + _builder.set_prop("timespan", AAZStrType, ".timespan") |
| 146 | + |
| 147 | + applications = _builder.get(".applications") |
| 148 | + if applications is not None: |
| 149 | + applications.set_elements(AAZStrType, ".") |
| 150 | + |
| 151 | + return self.serialize_content(_content_value) |
| 152 | + |
| 153 | + def on_200(self, session): |
| 154 | + data = self.deserialize_http_content(session) |
| 155 | + self.ctx.set_var( |
| 156 | + "instance", |
| 157 | + data, |
| 158 | + schema_builder=self._build_schema_on_200 |
| 159 | + ) |
| 160 | + |
| 161 | + _schema_on_200 = None |
| 162 | + |
| 163 | + @classmethod |
| 164 | + def _build_schema_on_200(cls): |
| 165 | + if cls._schema_on_200 is not None: |
| 166 | + return cls._schema_on_200 |
| 167 | + |
| 168 | + cls._schema_on_200 = AAZObjectType() |
| 169 | + |
| 170 | + _schema_on_200 = cls._schema_on_200 |
| 171 | + _schema_on_200.tables = AAZListType( |
| 172 | + flags={"required": True}, |
| 173 | + ) |
| 174 | + |
| 175 | + tables = cls._schema_on_200.tables |
| 176 | + tables.Element = AAZObjectType() |
| 177 | + |
| 178 | + _element = cls._schema_on_200.tables.Element |
| 179 | + _element.columns = AAZListType( |
| 180 | + flags={"required": True}, |
| 181 | + ) |
| 182 | + _element.name = AAZStrType( |
| 183 | + flags={"required": True}, |
| 184 | + ) |
| 185 | + _element.rows = AAZListType( |
| 186 | + flags={"required": True}, |
| 187 | + ) |
| 188 | + |
| 189 | + columns = cls._schema_on_200.tables.Element.columns |
| 190 | + columns.Element = AAZObjectType() |
| 191 | + |
| 192 | + _element = cls._schema_on_200.tables.Element.columns.Element |
| 193 | + _element.name = AAZStrType() |
| 194 | + _element.type = AAZStrType() |
| 195 | + |
| 196 | + rows = cls._schema_on_200.tables.Element.rows |
| 197 | + rows.Element = AAZListType() |
| 198 | + |
| 199 | + _element = cls._schema_on_200.tables.Element.rows.Element |
| 200 | + _element.Element = AAZAnyType() |
| 201 | + |
| 202 | + return cls._schema_on_200 |
| 203 | + |
| 204 | + |
| 205 | +class _QueryExecuteHelper: |
| 206 | + """Helper class for QueryExecute""" |
| 207 | + |
| 208 | + |
| 209 | +__all__ = ["QueryExecute"] |
0 commit comments