From 1148304a67206e71d1ebc37f24cac5a0700356b2 Mon Sep 17 00:00:00 2001 From: Ace Eldeib Date: Mon, 15 Apr 2019 18:37:38 -0700 Subject: [PATCH] App Insights control plane (#600) --- .../_client_factory.py | 4 + .../azext_applicationinsights/_help.py | 146 ++++++ .../azext_applicationinsights/_params.py | 36 +- .../azext_applicationinsights/commands.py | 36 +- .../azext_applicationinsights/custom.py | 67 ++- .../tests/latest/recordings/test_api_key.yaml | 487 ++++++++++++++++++ .../latest/recordings/test_component.yaml | 423 +++++++++++++++ .../latest/test_applicationinsights_mgmt.py | 83 +++ .../azext_applicationinsights/util.py | 35 ++ src/application-insights/setup.py | 4 +- src/index.json | 10 +- 11 files changed, 1318 insertions(+), 13 deletions(-) create mode 100644 src/application-insights/azext_applicationinsights/tests/latest/recordings/test_api_key.yaml create mode 100644 src/application-insights/azext_applicationinsights/tests/latest/recordings/test_component.yaml create mode 100644 src/application-insights/azext_applicationinsights/tests/latest/test_applicationinsights_mgmt.py diff --git a/src/application-insights/azext_applicationinsights/_client_factory.py b/src/application-insights/azext_applicationinsights/_client_factory.py index 501f62e56c6..4f6ff66d372 100644 --- a/src/application-insights/azext_applicationinsights/_client_factory.py +++ b/src/application-insights/azext_applicationinsights/_client_factory.py @@ -49,3 +49,7 @@ def cf_events(cli_ctx, _, subscription=None): def cf_components(cli_ctx, _, subscription=None): return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).components + + +def cf_api_key(cli_ctx, _, subscription=None): + return applicationinsights_mgmt_plane_client(cli_ctx, _, subscription=subscription).api_keys diff --git a/src/application-insights/azext_applicationinsights/_help.py b/src/application-insights/azext_applicationinsights/_help.py index f0c47370546..a85f5f1adcb 100644 --- a/src/application-insights/azext_applicationinsights/_help.py +++ b/src/application-insights/azext_applicationinsights/_help.py @@ -21,6 +21,126 @@ provided, then --offset will be ignored. """ +helps['monitor app-insights component'] = """ + type: group + short-summary: Manage an Application Insights component or its subcomponents. +""" + +helps['monitor app-insights component create'] = """ + type: command + short-summary: Create a new Application Insights resource. + parameters: + - name: --application-type + type: string + short-summary: Type of application being monitored. Possible values include 'web', 'other'. Default value is'web' . + - name: --kind -k + type: string + short-summary: The kind of application that this component refers to, used to customize UI. This value is a freeform string, values should typically be one of web, ios, other, store, java, phone. + examples: + - name: Create a component with kind web and location. + text: | + az monitor app-insights component create --app demoApp --location westus2 --kind web -g demoRg --application-type web +""" + +helps['monitor app-insights component update'] = """ + type: command + short-summary: Update properties on an existing Application Insights resource. The primary value which can be updated is kind, which customizes the UI experience. + parameters: + - name: --kind -k + type: string + short-summary: The kind of application that this component refers to, used to customize UI. This value is a freeform string, values should typically be one of web, ios, other, store, java, phone. + examples: + - name: Update a component with kind web. + text: | + az monitor app-insights component update --app demoApp -k web -g demoRg +""" + +helps['monitor app-insights component update-tags'] = """ + type: command + short-summary: Update tags on an existing Application Insights resource. + examples: + - name: Update the tag 'name' to equal 'value'. + text: | + az monitor app-insights component update-tags --app demoApp --tags name=value -g demoRg +""" + +helps['monitor app-insights component show'] = """ + type: command + short-summary: Get an Application Insights resource. + examples: + - name: Get a component by name. + text: | + az monitor app-insights component show --app demoApp -g demoRg + - name: List components in a resource group. + text: | + az monitor app-insights component show -g demoRg + - name: List components in the currently selected subscription. + text: | + az monitor app-insights component show +""" + +helps['monitor app-insights component delete'] = """ + type: command + short-summary: Create a new Application Insights resource. + examples: + - name: Create a component with kind web and location. + text: | + az monitor app-insights component delete --app demoApp -g demoRg +""" + +helps['monitor app-insights api-key'] = """ + type: group + short-summary: Operations on API keys associated with an Application Insights component. +""" + +helps['monitor app-insights api-key show'] = """ + type: command + short-summary: Get all keys or a specific API key associated with an Application Insights resource. + parameters: + - name: --api-key + type: string + short-summary: name of the API key to fetch. Can be found using `api-keys show`. + examples: + - name: Fetch API Key. + text: | + az monitor app-insights api-key show --app demoApp -g demoRg --api-key demo-key + - name: Fetch API Keys. + text: | + az monitor app-insights api-key show --app demoApp -g demoRg +""" + +helps['monitor app-insights api-key delete'] = """ + type: command + short-summary: Delete an API key from an Application Insights resource. + parameters: + - name: --api-key + type: string + short-summary: Name of the API key to delete. Can be found using `api-keys show`. + examples: + - name: Delete API Key. + text: | + az monitor app-insights api-key delete --app demoApp -g demoRg --api-key demo-key +""" + +helps['monitor app-insights api-key create'] = """ + type: command + short-summary: Create a new API key for use with an Application Insights resource. + parameters: + - name: --api-key + type: string + short-summary: Name of the API key to create. + - name: --read-properties + type: list + short-summary: A space seperated list of names of read Roles for this API key to inherit. Possible values include ReadTelemetry and AuthenticateSDKControlChannel. + - name: --write-properties + type: list + short-summary: A space seperated list of names of write Roles for this API key to inherit. Possible values include WriteAnnotations. + examples: + - name: Create a component with kind web and location. + text: | + az monitor app-insights api-key create --api-key cli-demo --read-properties ReadTelemetry -g demoRg --app testApp +""" + helps['monitor app-insights metrics'] = """ type: group short-summary: Retrieve metrics from an application. @@ -34,6 +154,15 @@ helps['monitor app-insights query'] = """ type: command short-summary: Execute a query over data in your application. + parameters: + - name: --offset + short-summary: > + Time offset of the query range, in ##d##h format. + long-summary: > + Can be used with either --start-time or --end-time. If used with --start-time, then + the end time will be calculated by adding the offset. If used with --end-time (default), then + the start time will be calculated by subtracting the offset. If --start-time and --end-time are + provided, then --offset will be ignored. examples: - name: Execute a simple query over past 3.5 days. text: | @@ -47,6 +176,14 @@ - name: --interval short-summary: > The interval over which to aggregate metrics, in ##h##m format. + - name: --offset + short-summary: > + Time offset of the query range, in ##d##h format. + long-summary: > + Can be used with either --start-time or --end-time. If used with --start-time, then + the end time will be calculated by adding the offset. If used with --end-time (default), then + the start time will be calculated by subtracting the offset. If --start-time and --end-time are + provided, then --offset will be ignored. examples: - name: View the count of availabilityResults events. text: | @@ -65,6 +202,15 @@ helps['monitor app-insights events show'] = """ type: command short-summary: List events by type or view a single event from an application, specified by type and ID. + parameters: + - name: --offset + short-summary: > + Time offset of the query range, in ##d##h format. + long-summary: > + Can be used with either --start-time or --end-time. If used with --start-time, then + the end time will be calculated by adding the offset. If used with --end-time (default), then + the start time will be calculated by subtracting the offset. If --start-time and --end-time are + provided, then --offset will be ignored. examples: - name: Get an availability result by ID. text: | diff --git a/src/application-insights/azext_applicationinsights/_params.py b/src/application-insights/azext_applicationinsights/_params.py index 1a28cd7b90c..0c17ce7cc1c 100644 --- a/src/application-insights/azext_applicationinsights/_params.py +++ b/src/application-insights/azext_applicationinsights/_params.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- # pylint: disable=line-too-long -from azure.cli.core.commands.parameters import get_datetime_type +from azure.cli.core.commands.parameters import get_datetime_type, get_location_type, tags_type from azure.cli.command_modules.monitor.actions import get_period_type from ._validators import validate_applications @@ -12,9 +12,28 @@ def load_arguments(self, _): with self.argument_context('monitor app-insights') as c: c.argument('application', options_list=['--app', '-a'], id_part='name', help='GUID, app name, or fully-qualified Azure resource name of Application Insights component. The application GUID may be acquired from the API Access menu item on any Application Insights resource in the Azure portal. If using an application name, please specify resource group.') - c.argument('start_time', arg_type=get_datetime_type(help='Start-time of time range for which to retrieve data.')) - c.argument('end_time', arg_type=get_datetime_type(help='End of time range for current operation. Defaults to the current time.')) - c.argument('offset', help='Filter results based on UTC hour offset.', type=get_period_type(as_timedelta=True)) + + with self.argument_context('monitor app-insights component create') as c: + c.argument('location', arg_type=get_location_type(self.cli_ctx)) + c.argument('application-type', options_list=['application-type', '--type', '-t'], help="Type of application being monitored. Possible values include: 'web', 'other'. Default value: 'web' .") + c.argument('kind', options_list=['--kind', '-k'], help='The kind of application that this component refers to, used to customize UI. This value is a freeform string, values should typically be one of the following: web, ios, other, store, java, phone.') + c.argument('tags', tags_type) + + with self.argument_context('monitor app-insights component update') as c: + c.argument('location', arg_type=get_location_type(self.cli_ctx)) + c.argument('application-type', options_list=['application-type', '--type', '-t'], help="Type of application being monitored. Possible values include: 'web', 'other'. Default value: 'web' .") + c.argument('kind', options_list=['--kind', '-k'], help='The kind of application that this component refers to, used to customize UI. This value is a freeform string, values should typically be one of the following: web, ios, other, store, java, phone.') + + with self.argument_context('monitor app-insights component update-tags') as c: + c.argument('tags', tags_type) + + with self.argument_context('monitor app-insights api-key create') as c: + c.argument('api_key', help='The name of the API key to create.') + c.argument('read_properties', nargs='+', options_list=['--read-properties']) + c.argument('write_properties', nargs='+') + + with self.argument_context('monitor app-insights api-key show') as c: + c.argument('api_key', help='The name of the API key to fetch.') with self.argument_context('monitor app-insights metrics show') as c: c.argument('metric', options_list=['--metrics', '-m'], help='The metric to retrieve. May be either a standard AI metric or an application-specific custom metric.') @@ -24,11 +43,20 @@ def load_arguments(self, _): c.argument('segment', help='The name of the dimension to segment the metric values by. This dimension must be applicable to the metric you are retrieving. To segment by more than one dimension at a time, separate them with a comma (,). In this case, the metric data will be segmented in the order the dimensions are listed in the parameter.') c.argument('top', help='The number of segments to return. This value is only valid when segment is specified.') c.argument('filter_arg', options_list=['--filter'], help=' An expression used to filter the results. This value should be a valid OData filter expression where the keys of each clause should be applicable dimensions for the metric you are retrieving.') + c.argument('start_time', arg_type=get_datetime_type(help='Start-time of time range for which to retrieve data.')) + c.argument('end_time', arg_type=get_datetime_type(help='End of time range for current operation. Defaults to the current time.')) + c.argument('offset', help='Filter results based on UTC hour offset.', type=get_period_type(as_timedelta=True)) with self.argument_context('monitor app-insights events show') as c: c.argument('event_type', options_list=['--type'], help='The type of events to retrieve.') c.argument('event', options_list=['--event'], help='GUID of the event to retrieve. This could be obtained by first listing and filtering events, then selecting an event of interest.') + c.argument('start_time', arg_type=get_datetime_type(help='Start-time of time range for which to retrieve data.')) + c.argument('end_time', arg_type=get_datetime_type(help='End of time range for current operation. Defaults to the current time.')) + c.argument('offset', help='Filter results based on UTC hour offset.', type=get_period_type(as_timedelta=True)) with self.argument_context('monitor app-insights query') as c: c.argument('application', validator=validate_applications, options_list=['--apps', '-a'], nargs='+', id_part='name', help='GUID, app name, or fully-qualified Azure resource name of Application Insights component. The application GUID may be acquired from the API Access menu item on any Application Insights resource in the Azure portal. If using an application name, please specify resource group.') c.argument('analytics_query', help='Query to execute over Application Insights data.') + c.argument('start_time', arg_type=get_datetime_type(help='Start-time of time range for which to retrieve data.')) + c.argument('end_time', arg_type=get_datetime_type(help='End of time range for current operation. Defaults to the current time.')) + c.argument('offset', help='Filter results based on UTC hour offset.', type=get_period_type(as_timedelta=True)) diff --git a/src/application-insights/azext_applicationinsights/commands.py b/src/application-insights/azext_applicationinsights/commands.py index adf15c2b1bc..51919463287 100644 --- a/src/application-insights/azext_applicationinsights/commands.py +++ b/src/application-insights/azext_applicationinsights/commands.py @@ -8,7 +8,9 @@ from azext_applicationinsights._client_factory import ( cf_events, cf_metrics, - cf_query + cf_query, + cf_components, + cf_api_key ) from azure.cli.core.commands import CliCommandType @@ -31,6 +33,38 @@ def load_command_table(self, _): client_factory=cf_query ) + components_sdk = CliCommandType( + operations_tmpl='azext_applicationinsights.vendored_sdks.mgmt_applicationinsights.operations.components_operations#ComponentsOperations.{}', + client_factory=cf_components + ) + + components_custom_sdk = CliCommandType( + operations_tmpl='azext_applicationinsights.custom#{}', + client_factory=cf_components + ) + + api_key_sdk = CliCommandType( + operations_tmpl='azext_applicationinsights.vendored_sdks.mgmt_applicationinsights.operations.api_keys_operations#APIKeysOperations.{}', + client_factory=cf_api_key + ) + + api_key_custom_sdk = CliCommandType( + operations_tmpl='azext_applicationinsights.custom#{}', + client_factory=cf_api_key + ) + + with self.command_group('monitor app-insights component', command_type=components_sdk, custom_command_type=components_custom_sdk) as g: + g.custom_command('create', 'create_or_update_component') + g.custom_command('update', 'update_component') + g.custom_command('show', 'show_components') + g.custom_command('delete', 'delete_component') + g.custom_command('update-tags', 'update_component_tags') + + with self.command_group('monitor app-insights api-key', command_type=api_key_sdk, custom_command_type=api_key_custom_sdk) as g: + g.custom_command('create', 'create_api_key') + g.custom_command('show', 'show_api_key') + g.custom_command('delete', 'delete_api_key') + with self.command_group('monitor app-insights metrics', metrics_sdk) as g: g.custom_command('show', 'get_metric') g.custom_command('get-metadata', 'get_metrics_metadata') diff --git a/src/application-insights/azext_applicationinsights/custom.py b/src/application-insights/azext_applicationinsights/custom.py index 18f7d98c17e..c641662f401 100644 --- a/src/application-insights/azext_applicationinsights/custom.py +++ b/src/application-insights/azext_applicationinsights/custom.py @@ -5,8 +5,9 @@ # pylint: disable=line-too-long +from knack.util import CLIError from knack.log import get_logger -from .util import get_id_from_azure_resource, get_query_targets, get_timespan +from .util import get_id_from_azure_resource, get_query_targets, get_timespan, get_linked_properties logger = get_logger(__name__) @@ -31,3 +32,67 @@ def get_metric(cmd, client, application, metric, start_time=None, end_time=None, def get_metrics_metadata(cmd, client, application, resource_group_name=None): return client.metrics.get_metadata(get_id_from_azure_resource(cmd.cli_ctx, application, resource_group=resource_group_name)) + + +def create_or_update_component(client, application, resource_group_name, location, tags=None, kind="web", application_type='web'): + from .vendored_sdks.mgmt_applicationinsights.models import ApplicationInsightsComponent + component = ApplicationInsightsComponent(location, kind, application_type=application_type, tags=tags) + return client.create_or_update(resource_group_name, application, component) + + +def update_component(client, application, resource_group_name, kind=None): + existing_component = client.get(resource_group_name, application) + if kind: + existing_component.kind = kind + return client.create_or_update(resource_group_name, application, existing_component) + + +def update_component_tags(client, application, resource_group_name, tags): + return client.update_tags(resource_group_name, application, tags) + + +def get_component(client, application, resource_group_name): + return client.get(resource_group_name, application) + + +def show_components(client, application=None, resource_group_name=None): + if application: + if resource_group_name: + return client.get(resource_group_name, application) + raise CLIError("Application provided without resource group. Either specify app with resource group, or remove app.") + if resource_group_name: + return client.list_by_resource_group(resource_group_name) + return client.list() + + +def delete_component(client, application, resource_group_name): + return client.delete(resource_group_name, application) + + +def create_api_key(cmd, client, application, resource_group_name, api_key, read_properties=None, write_properties=None): + from .vendored_sdks.mgmt_applicationinsights.models import APIKeyRequest + if read_properties is None: + read_properties = ['ReadTelemetry', 'AuthenticateSDKControlChannel'] + if write_properties is None: + write_properties = ['WriteAnnotations'] + linked_read_properties, linked_write_properties = get_linked_properties(cmd.cli_ctx, application, resource_group_name, read_properties, write_properties) + api_key_request = APIKeyRequest(api_key, linked_read_properties, linked_write_properties) + return client.create(resource_group_name, application, api_key_request) + + +def show_api_key(client, application, resource_group_name, api_key=None): + if api_key is None: + return client.list(resource_group_name, application) + result = list(filter(lambda result: result.name == api_key, client.list(resource_group_name, application))) + if len(result) == 1: + return result[0] + elif len(result) > 1: + return result + return None + + +def delete_api_key(client, application, resource_group_name, api_key): + existing_key = list(filter(lambda result: result.name == api_key, client.list(resource_group_name, application))) + if existing_key != []: + return client.delete(resource_group_name, application, existing_key[0].id.split('/')[-1]) + raise CLIError('--api-key provided but key not found for deletion.') diff --git a/src/application-insights/azext_applicationinsights/tests/latest/recordings/test_api_key.yaml b/src/application-insights/azext_applicationinsights/tests/latest/recordings/test_api_key.yaml new file mode 100644 index 00000000000..4279e07c0dd --- /dev/null +++ b/src/application-insights/azext_applicationinsights/tests/latest/recordings/test_api_key.yaml @@ -0,0 +1,487 @@ +interactions: +- request: + body: '{"location": "westus", "tags": {"product": "azurecli", "cause": "automation", + "date": "2019-04-05T23:50:26Z"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - group create + Connection: + - keep-alive + Content-Length: + - '110' + Content-Type: + - application/json; charset=utf-8 + ParameterSetName: + - --location --name --tag + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + resourcemanagementclient/2.1.0 Azure-SDK-For-Python AZURECLI/2.0.59 + accept-language: + - en-US + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001?api-version=2018-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001","name":"clitest.rg000001","location":"westus","tags":{"product":"azurecli","cause":"automation","date":"2019-04-05T23:50:26Z"},"properties":{"provisioningState":"Succeeded"}}' + headers: + cache-control: + - no-cache + content-length: + - '384' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:27 GMT + expires: + - '-1' + pragma: + - no-cache + strict-transport-security: + - max-age=31536000; includeSubDomains + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1196' + status: + code: 201 + message: Created +- request: + body: '{"location": "westus", "kind": "web", "properties": {"Application_Type": + "web", "Flow_Type": "Bluefield", "Request_Source": "rest"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '132' + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp?api-version=2015-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp","name":"demoApp","type":"microsoft.insights/components","location":"westus","tags":{},"kind":"web","etag":"\"0b00a10c-0000-0000-0000-5ca7e9c50000\"","properties":{"Ver":"v2","ApplicationId":"demoApp","AppId":"876fe109-41ae-49e2-90c4-c237645bb695","Application_Type":"web","Flow_Type":"Bluefield","Request_Source":"rest","InstrumentationKey":"57a389ef-e681-496e-bb69-32f1d566ead7","Name":"demoApp","CreationDate":"2019-04-05T23:50:29.5773546+00:00","PackageId":null,"TenantId":"056f3d78-504f-4b60-b19a-276b6f1687db","HockeyAppId":null,"HockeyAppToken":null,"provisioningState":"Succeeded","SamplingPercentage":null,"CustomMetricsOptedInType":null,"Retention":null}}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '863' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:31 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1198' + x-powered-by: + - ASP.NET + status: + code: 200 + message: OK +- request: + body: 'b''{"name": "demoKey", "linkedReadProperties": ["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"], + "linkedWriteProperties": ["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"]}''' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '682' + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/ApiKeys?api-version=2015-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/apikeys/9af593a1-b8f9-4a1d-bbd3-367d2f0e9ce8","name":"demoKey","linkedReadProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"],"linkedWriteProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"],"apiKey":"bdcs2jjndbjc8dsxhb12foam3czjs4ethl0cdboc","createdDate":"Fri, + 05 Apr 2019 23:50:32 GMT","integrationType":null,"integrationProperty":null}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '1067' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:32 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1199' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/ApiKeys?api-version=2015-05-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/apikeys/9af593a1-b8f9-4a1d-bbd3-367d2f0e9ce8","name":"demoKey","linkedReadProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/draft","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/extendqueries","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/search","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/aggregate","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"],"linkedWriteProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"],"createdDate":"Fri, + 05 Apr 2019 23:50:32 GMT","integrationType":null,"integrationProperty":null}]}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '1836' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:32 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + status: + code: 200 + message: OK +- request: + body: 'b''{"name": "otherKey", "linkedReadProperties": ["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"], + "linkedWriteProperties": ["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"]}''' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '683' + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/ApiKeys?api-version=2015-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/apikeys/38e424c5-c18f-490c-a1fb-092dbe55475a","name":"otherKey","linkedReadProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"],"linkedWriteProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"],"apiKey":"dqtvx11pknw2v6frpp87orwh4fo3snduuw4st7j2","createdDate":"Fri, + 05 Apr 2019 23:50:33 GMT","integrationType":null,"integrationProperty":null}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '1068' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:33 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1198' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/ApiKeys?api-version=2015-05-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/apikeys/9af593a1-b8f9-4a1d-bbd3-367d2f0e9ce8","name":"demoKey","linkedReadProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/draft","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/extendqueries","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/search","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/aggregate","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"],"linkedWriteProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"],"createdDate":"Fri, + 05 Apr 2019 23:50:32 GMT","integrationType":null,"integrationProperty":null},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/apikeys/38e424c5-c18f-490c-a1fb-092dbe55475a","name":"otherKey","linkedReadProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/draft","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/extendqueries","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/search","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/aggregate","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"],"linkedWriteProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"],"createdDate":"Fri, + 05 Apr 2019 23:50:33 GMT","integrationType":null,"integrationProperty":null}]}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '3662' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:34 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/ApiKeys?api-version=2015-05-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/apikeys/9af593a1-b8f9-4a1d-bbd3-367d2f0e9ce8","name":"demoKey","linkedReadProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/draft","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/extendqueries","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/search","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/aggregate","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"],"linkedWriteProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"],"createdDate":"Fri, + 05 Apr 2019 23:50:32 GMT","integrationType":null,"integrationProperty":null},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/apikeys/38e424c5-c18f-490c-a1fb-092dbe55475a","name":"otherKey","linkedReadProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/draft","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/extendqueries","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/search","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/aggregate","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"],"linkedWriteProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"],"createdDate":"Fri, + 05 Apr 2019 23:50:33 GMT","integrationType":null,"integrationProperty":null}]}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '3662' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:35 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: DELETE + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/APIKeys/38e424c5-c18f-490c-a1fb-092dbe55475a?api-version=2015-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/apikeys/38e424c5-c18f-490c-a1fb-092dbe55475a","name":"otherKey","linkedReadProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/api","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/draft","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/extendqueries","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/search","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/aggregate","/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/agentconfig"],"linkedWriteProperties":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp/annotations"],"createdDate":"Fri, + 05 Apr 2019 23:50:33 GMT","integrationType":null,"integrationProperty":null}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '1825' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:35 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-deletes: + - '14999' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - group delete + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - --name --yes --no-wait + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + resourcemanagementclient/2.1.0 Azure-SDK-For-Python AZURECLI/2.0.59 + accept-language: + - en-US + method: DELETE + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001?api-version=2018-05-01 + response: + body: + string: '' + headers: + cache-control: + - no-cache + content-length: + - '0' + date: + - Fri, 05 Apr 2019 23:50:37 GMT + expires: + - '-1' + location: + - https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1DTElURVNUOjJFUkdPWlAzNElMUTZYWE1ZQVFVUUFVSExOR0JZQTIzVlJNSEVONnwxRjFGNzYxOEMyNTY1NTYxLVdFU1RVUyIsImpvYkxvY2F0aW9uIjoid2VzdHVzIn0?api-version=2018-05-01 + pragma: + - no-cache + strict-transport-security: + - max-age=31536000; includeSubDomains + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-deletes: + - '14999' + status: + code: 202 + message: Accepted +version: 1 diff --git a/src/application-insights/azext_applicationinsights/tests/latest/recordings/test_component.yaml b/src/application-insights/azext_applicationinsights/tests/latest/recordings/test_component.yaml new file mode 100644 index 00000000000..0f4bf42f4d8 --- /dev/null +++ b/src/application-insights/azext_applicationinsights/tests/latest/recordings/test_component.yaml @@ -0,0 +1,423 @@ +interactions: +- request: + body: '{"location": "westus", "tags": {"product": "azurecli", "cause": "automation", + "date": "2019-04-05T23:50:26Z"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - group create + Connection: + - keep-alive + Content-Length: + - '110' + Content-Type: + - application/json; charset=utf-8 + ParameterSetName: + - --location --name --tag + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + resourcemanagementclient/2.1.0 Azure-SDK-For-Python AZURECLI/2.0.59 + accept-language: + - en-US + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001?api-version=2018-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001","name":"clitest.rg000001","location":"westus","tags":{"product":"azurecli","cause":"automation","date":"2019-04-05T23:50:26Z"},"properties":{"provisioningState":"Succeeded"}}' + headers: + cache-control: + - no-cache + content-length: + - '384' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:27 GMT + expires: + - '-1' + pragma: + - no-cache + strict-transport-security: + - max-age=31536000; includeSubDomains + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1196' + status: + code: 201 + message: Created +- request: + body: '{"location": "westus", "kind": "web", "properties": {"Application_Type": + "web", "Flow_Type": "Bluefield", "Request_Source": "rest"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '132' + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp?api-version=2015-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp","name":"demoApp","type":"microsoft.insights/components","location":"westus","tags":{},"kind":"web","etag":"\"0b00a70c-0000-0000-0000-5ca7e9c70000\"","properties":{"Ver":"v2","ApplicationId":"demoApp","AppId":"94d9436c-d92b-4bd6-9de0-d38ba2b89ea2","Application_Type":"web","Flow_Type":"Bluefield","Request_Source":"rest","InstrumentationKey":"b878989e-3676-4266-bc56-999f05166e7d","Name":"demoApp","CreationDate":"2019-04-05T23:50:31.1529+00:00","PackageId":null,"TenantId":"056f3d78-504f-4b60-b19a-276b6f1687db","HockeyAppId":null,"HockeyAppToken":null,"provisioningState":"Succeeded","SamplingPercentage":null,"CustomMetricsOptedInType":null,"Retention":null}}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '860' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:33 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1197' + x-powered-by: + - ASP.NET + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp?api-version=2015-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp","name":"demoApp","type":"microsoft.insights/components","location":"westus","tags":{},"kind":"web","etag":"\"0b00a70c-0000-0000-0000-5ca7e9c70000\"","properties":{"Ver":"v2","ApplicationId":"demoApp","AppId":"94d9436c-d92b-4bd6-9de0-d38ba2b89ea2","Application_Type":"web","Flow_Type":"Bluefield","Request_Source":"rest","InstrumentationKey":"b878989e-3676-4266-bc56-999f05166e7d","Name":"demoApp","CreationDate":"2019-04-05T23:50:31.1529+00:00","PackageId":null,"TenantId":"056f3d78-504f-4b60-b19a-276b6f1687db","HockeyAppId":null,"HockeyAppToken":null,"provisioningState":"Succeeded","SamplingPercentage":null,"CustomMetricsOptedInType":null,"Retention":null}}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '860' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:33 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-powered-by: + - ASP.NET + status: + code: 200 + message: OK +- request: + body: '{"location": "westus", "tags": {}, "kind": "ios", "properties": {"Application_Type": + "web", "Flow_Type": "Bluefield", "Request_Source": "rest"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '144' + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp?api-version=2015-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp","name":"demoApp","type":"microsoft.insights/components","location":"westus","tags":{},"kind":"ios","etag":"\"0b00b30c-0000-0000-0000-5ca7e9ca0000\"","properties":{"Ver":"v2","ApplicationId":"demoApp","AppId":"94d9436c-d92b-4bd6-9de0-d38ba2b89ea2","Application_Type":"web","Flow_Type":"Bluefield","Request_Source":"rest","InstrumentationKey":"b878989e-3676-4266-bc56-999f05166e7d","Name":"demoApp","CreationDate":"2019-04-05T23:50:31.1529+00:00","PackageId":null,"TenantId":"056f3d78-504f-4b60-b19a-276b6f1687db","HockeyAppId":null,"HockeyAppToken":null,"provisioningState":"Succeeded","SamplingPercentage":null,"CustomMetricsOptedInType":null,"Retention":null}}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '860' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:35 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1197' + x-powered-by: + - ASP.NET + status: + code: 200 + message: OK +- request: + body: '{"location": "westus", "kind": "ios", "properties": {"Application_Type": + "web", "Flow_Type": "Bluefield", "Request_Source": "rest"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '132' + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/testApp?api-version=2015-05-01 + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/testApp","name":"testApp","type":"microsoft.insights/components","location":"westus","tags":{},"kind":"ios","etag":"\"0b00be0c-0000-0000-0000-5ca7e9cd0000\"","properties":{"Ver":"v2","ApplicationId":"testApp","AppId":"ee01e352-6667-4d87-b0f3-9cd059232011","Application_Type":"web","Flow_Type":"Bluefield","Request_Source":"rest","InstrumentationKey":"ae983405-f618-405b-8742-f8eb12fd4543","Name":"testApp","CreationDate":"2019-04-05T23:50:37.6336705+00:00","PackageId":null,"TenantId":"056f3d78-504f-4b60-b19a-276b6f1687db","HockeyAppId":null,"HockeyAppToken":null,"provisioningState":"Succeeded","SamplingPercentage":null,"CustomMetricsOptedInType":null,"Retention":null}}' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '863' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:38 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1198' + x-powered-by: + - ASP.NET + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components?api-version=2015-05-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp","name":"demoApp","type":"microsoft.insights/components","location":"westus","tags":{},"kind":"ios","etag":"\"0b00b30c-0000-0000-0000-5ca7e9ca0000\"","properties":{"ApplicationId":"demoApp","AppId":"94d9436c-d92b-4bd6-9de0-d38ba2b89ea2","Application_Type":"web","Flow_Type":"Bluefield","Request_Source":"rest","InstrumentationKey":"b878989e-3676-4266-bc56-999f05166e7d","Name":"demoApp","CreationDate":"2019-04-05T23:50:31.1529+00:00","PackageId":null,"TenantId":"056f3d78-504f-4b60-b19a-276b6f1687db","HockeyAppId":null,"HockeyAppToken":null,"provisioningState":"Succeeded","SamplingPercentage":null,"CustomMetricsOptedInType":null,"Retention":null}},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/testApp","name":"testApp","type":"microsoft.insights/components","location":"westus","tags":{},"kind":"ios","etag":"\"0b00be0c-0000-0000-0000-5ca7e9cd0000\"","properties":{"ApplicationId":"testApp","AppId":"ee01e352-6667-4d87-b0f3-9cd059232011","Application_Type":"web","Flow_Type":"Bluefield","Request_Source":"rest","InstrumentationKey":"ae983405-f618-405b-8742-f8eb12fd4543","Name":"testApp","CreationDate":"2019-04-05T23:50:37.6336705+00:00","PackageId":null,"TenantId":"056f3d78-504f-4b60-b19a-276b6f1687db","HockeyAppId":null,"HockeyAppToken":null,"provisioningState":"Succeeded","SamplingPercentage":null,"CustomMetricsOptedInType":null,"Retention":null}}]}' + headers: + cache-control: + - no-cache + content-length: + - '1714' + content-type: + - application/json; charset=utf-8 + date: + - Fri, 05 Apr 2019 23:50:38 GMT + expires: + - '-1' + pragma: + - no-cache + strict-transport-security: + - max-age=31536000; includeSubDomains + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-original-request-ids: + - 9d6e357e-57fd-11e9-abee-9457a5f1c0e8 + - 9d6e357e-57fd-11e9-abee-9457a5f1c0e8 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + azure-mgmt-applicationinsights/0.1.1 Azure-SDK-For-Python + accept-language: + - en-US + method: DELETE + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/microsoft.insights/components/demoApp?api-version=2015-05-01 + response: + body: + string: '' + headers: + access-control-expose-headers: + - Request-Context + cache-control: + - no-cache + content-length: + - '0' + date: + - Fri, 05 Apr 2019 23:50:40 GMT + expires: + - '-1' + pragma: + - no-cache + request-context: + - appId=cid-v1:920e14b1-13f3-461a-a4bb-b4fe6f1a4525 + server: + - Microsoft-IIS/10.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-deletes: + - '14998' + x-powered-by: + - ASP.NET + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - group delete + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - --name --yes --no-wait + User-Agent: + - python/3.7.2 (Windows-10-10.0.17763-SP0) msrest/0.6.6 msrest_azure/0.4.34 + resourcemanagementclient/2.1.0 Azure-SDK-For-Python AZURECLI/2.0.59 + accept-language: + - en-US + method: DELETE + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001?api-version=2018-05-01 + response: + body: + string: '' + headers: + cache-control: + - no-cache + content-length: + - '0' + date: + - Fri, 05 Apr 2019 23:50:41 GMT + expires: + - '-1' + location: + - https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1DTElURVNUOjJFUkc0WVhRSFNHNlZZSlc1T0ZRSU5EN1FSS0Y2UUtMQkdGT0NZUHw4NzE3MURDMjQ4MDMyMDU0LVdFU1RVUyIsImpvYkxvY2F0aW9uIjoid2VzdHVzIn0?api-version=2018-05-01 + pragma: + - no-cache + strict-transport-security: + - max-age=31536000; includeSubDomains + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-deletes: + - '14999' + status: + code: 202 + message: Accepted +version: 1 diff --git a/src/application-insights/azext_applicationinsights/tests/latest/test_applicationinsights_mgmt.py b/src/application-insights/azext_applicationinsights/tests/latest/test_applicationinsights_mgmt.py new file mode 100644 index 00000000000..b47188d74c1 --- /dev/null +++ b/src/application-insights/azext_applicationinsights/tests/latest/test_applicationinsights_mgmt.py @@ -0,0 +1,83 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=line-too-long +from azure.cli.testsdk import ResourceGroupPreparer, ScenarioTest + + +class ApplicationInsightsManagementClientTests(ScenarioTest): + """Test class for ApplicationInsights mgmt cli.""" + @ResourceGroupPreparer(parameter_name_for_location='location') + def test_component(self, resource_group, location): + self.kwargs.update({ + 'loc': location, + 'resource_group': resource_group, + 'name_a': 'demoApp', + 'name_b': 'testApp', + 'kind': 'web', + 'application_type': 'web' + }) + + self.cmd('az monitor app-insights component create --app {name_a} --location {loc} --kind {kind} -g {resource_group} --application-type {application_type}', checks=[ + self.check('name', '{name_a}'), + self.check('location', '{loc}'), + self.check('kind', '{kind}'), + self.check('applicationType', '{application_type}'), + self.check('applicationId', '{name_a}'), + self.check('provisioningState', 'Succeeded'), + ]) + + self.kwargs.update({ + 'kind': 'ios' + }) + + self.cmd('az monitor app-insights component update --app {name_a} --kind {kind} -g {resource_group}', checks=[ + self.check('kind', '{kind}') + ]) + + self.cmd('az monitor app-insights component create --app {name_b} --location {loc} --kind {kind} -g {resource_group} --application-type {application_type}', checks=[ + self.check('name', '{name_b}'), + self.check('provisioningState', 'Succeeded'), + ]) + + apps = self.cmd('az monitor app-insights component show -g {resource_group}').get_output_in_json() + assert len(apps) == 2 + + self.cmd('az monitor app-insights component delete --app {name_a} -g {resource_group}', checks=[self.is_empty()]) + return + + """Test class for ApplicationInsights mgmt cli.""" + @ResourceGroupPreparer(parameter_name_for_location='location') + def test_api_key(self, resource_group, location): + self.kwargs.update({ + 'loc': location, + 'resource_group': resource_group, + 'name': 'demoApp', + 'apiKey': 'demoKey', + 'apiKeyB': 'otherKey', + 'kind': 'web', + 'application_type': 'web' + }) + + self.cmd('az monitor app-insights component create --app {name} --location {loc} --kind {kind} -g {resource_group} --application-type {application_type}') + self.cmd('az monitor app-insights api-key create --app {name} -g {resource_group} --api-key {apiKey}', checks=[ + self.check('name', '{apiKey}'), + self.check('resourceGroup', '{resource_group}') + ]) + + api_key = self.cmd('az monitor app-insights api-key show --app {name} -g {resource_group} --api-key {apiKey}').get_output_in_json() + assert len(api_key['linkedReadProperties']) >= 2 # Some are not user configurable but will be added automatically + assert len(api_key['linkedWriteProperties']) == 1 + + api_key = self.cmd('az monitor app-insights api-key create --app {name} -g {resource_group} --api-key {apiKeyB}').get_output_in_json() + assert (api_key['apiKey'] is not None) + + api_keys = self.cmd('az monitor app-insights api-key show --app {name} -g {resource_group}').get_output_in_json() + assert len(api_keys) == 2 + + self.cmd('az monitor app-insights api-key delete --app {name} -g {resource_group} --api-key {apiKeyB}', checks=[ + self.check('name', '{apiKeyB}') + ]) + return diff --git a/src/application-insights/azext_applicationinsights/util.py b/src/application-insights/azext_applicationinsights/util.py index 77fb0eef266..32aa5da5220 100644 --- a/src/application-insights/azext_applicationinsights/util.py +++ b/src/application-insights/azext_applicationinsights/util.py @@ -43,3 +43,38 @@ def get_timespan(_, start_time=None, end_time=None, offset=None): end_time = (dateutil.parser.parse(start_time) + offset).isoformat() timespan = '{}/{}'.format(start_time, end_time) return timespan + + +def get_linked_properties(cli_ctx, app, resource_group, read_properties=None, write_properties=None): + """Maps user-facing role names to strings used to identify them on resources.""" + roles = { + "ReadTelemetry": "api", + "WriteAnnotations": "annotations", + "AuthenticateSDKControlChannel": "agentconfig" + } + + sub_id = get_subscription_id(cli_ctx) + tmpl = '/subscriptions/{}/resourceGroups/{}/providers/microsoft.insights/components/{}'.format( + sub_id, + resource_group, + app + ) + linked_read_properties, linked_write_properties = [], [] + + if isinstance(read_properties, list): + propLen = len(read_properties) + linked_read_properties = ['{}/{}'.format(tmpl, roles[read_properties[i]]) for i in range(propLen)] + else: + linked_read_properties = ['{}/{}'.format(tmpl, roles[read_properties])] + if isinstance(write_properties, list): + propLen = len(write_properties) + linked_write_properties = ['{}/{}'.format(tmpl, roles[write_properties[i]]) for i in range(propLen)] + else: + linked_write_properties = ['{}/{}'.format(tmpl, roles[write_properties])] + return linked_read_properties, linked_write_properties + + +def get_subscription_id(cli_ctx): + from azure.cli.core._profile import Profile + _, sub_id, _ = Profile(cli_ctx=cli_ctx).get_login_credentials(subscription_id=None) + return sub_id diff --git a/src/application-insights/setup.py b/src/application-insights/setup.py index c64bd1f6346..5599cb573c4 100644 --- a/src/application-insights/setup.py +++ b/src/application-insights/setup.py @@ -8,7 +8,7 @@ from codecs import open from setuptools import setup, find_packages -VERSION = "0.1.0" +VERSION = "0.1.1" CLASSIFIERS = [ 'Development Status :: 4 - Beta', @@ -34,7 +34,7 @@ setup( name='application-insights', version=VERSION, - description='Support for querying Azure Application Insights metrics, events, and logs.', + description='Support for managing Application Insights components and querying metrics, events, and logs from such components.', long_description=README + '\n\n' + HISTORY, license='MIT', author='Ace Eldeib', diff --git a/src/index.json b/src/index.json index 0045e1e36d9..51f6b329357 100644 --- a/src/index.json +++ b/src/index.json @@ -369,8 +369,8 @@ ], "application-insights": [ { - "downloadUrl": "https://appinsightscli.blob.core.windows.net/app-insights-cli/application_insights-0.1.0-py2.py3-none-any.whl", - "filename": "application_insights-0.1.0-py2.py3-none-any.whl", + "downloadUrl": "https://appinsightscli.blob.core.windows.net/controlplane-cli/application_insights-0.1.1-py2.py3-none-any.whl", + "filename": "application_insights-0.1.1-py2.py3-none-any.whl", "metadata": { "azext.isPreview": true, "azext.minCliCoreVersion": "2.0.56", @@ -395,10 +395,10 @@ "license": "MIT", "metadata_version": "2.0", "name": "application-insights", - "summary": "Support for querying Azure Application Insights metrics, events, and logs.", - "version": "0.1.0" + "summary": "Support for managing Application Insights components and querying metrics, events, and logs from such components.", + "version": "0.1.1" }, - "sha256Digest": "958fc72e5266ec7c7456a88bf181a7ed66a5be4efe0c6a10de0d1d783c1a628a" + "sha256Digest": "6a03b2b1a78f44e096650870d02fc2d86ee30fb07a42656716f1ced9d8651831" } ], "azure-batch-cli-extensions": [