Skip to content

Commit 00d47c8

Browse files
authored
add alias for functionparameter (#12085)
* add alias for functionparameter * update changelog.md * apply patch for saved searches operation when function parameter was not provided
1 parent 1a4fe13 commit 00d47c8

7 files changed

+57
-21
lines changed

src/OperationalInsights/OperationalInsights/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Added alias "FunctionParameters" for parameter "FunctionParameter" to
22+
- `New-AzOperationalInsightsSavedSearch`
23+
- `Set-AzOperationalInsightsSavedSearch`
2124

2225
## Version 2.1.0
2326
* Upgraded SDK to 0.21.0

src/OperationalInsights/OperationalInsights/Client/OperationalInsightsClient.Search.cs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,43 @@ public virtual PSSearchGetSchemaResponse GetSchema(string resourceGroupName, str
5151
return schemaResponse;
5252
}
5353

54-
public virtual HttpStatusCode CreateOrUpdateSavedSearch(string resourceGroupName, string workspaceName, string savedSearchId, SavedSearch properties, bool force, Action<bool, string, string, string, Action, Func<bool>> ConfirmAction, string ETag = null)
54+
public virtual HttpStatusCode CreateOrUpdateSavedSearch(string resourceGroupName, string workspaceName, string savedSearchId, SavedSearch properties, bool patch, bool force, Action<bool, string, string, string, Action, Func<bool>> ConfirmAction, string ETag = null)
5555
{
56+
PSSearchGetSavedSearchResponse ExistingSearch;
57+
bool existed;
58+
59+
try
60+
{
61+
ExistingSearch = GetSavedSearch(resourceGroupName, workspaceName, savedSearchId);
62+
}
63+
catch (Rest.Azure.CloudException)
64+
{
65+
ExistingSearch = null;
66+
}
67+
68+
existed = ExistingSearch == null ? false : true;
69+
5670
HttpStatusCode status = HttpStatusCode.Ambiguous;
5771
Action createSavedSearch = () =>
72+
{
73+
if (ETag != null && ETag != "")
5874
{
59-
if (ETag != null && ETag != "")
60-
{
61-
properties.ETag = ETag;
62-
}
63-
Rest.Azure.AzureOperationResponse<SavedSearch> result = OperationalInsightsManagementClient.SavedSearches.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, savedSearchId, properties).GetAwaiter().GetResult();
64-
status = result.Response.StatusCode;
65-
};
75+
properties.ETag = ETag;
76+
}
77+
Rest.Azure.AzureOperationResponse<SavedSearch> result = OperationalInsightsManagementClient.SavedSearches.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, savedSearchId, properties).GetAwaiter().GetResult();
78+
status = result.Response.StatusCode;
79+
};
80+
81+
Action updateSavedSearch = () =>
82+
{
83+
if (ETag != null && ETag != "")
84+
{
85+
properties.ETag = ETag;
86+
}
87+
properties.FunctionParameters = ExistingSearch.Properties.FunctionParameters;
88+
Rest.Azure.AzureOperationResponse<SavedSearch> result = OperationalInsightsManagementClient.SavedSearches.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, savedSearchId, properties).GetAwaiter().GetResult();
89+
status = result.Response.StatusCode;
90+
};
6691

6792
ConfirmAction(
6893
force, // prompt only if the saved search exists
@@ -77,8 +102,8 @@ public virtual HttpStatusCode CreateOrUpdateSavedSearch(string resourceGroupName
77102
savedSearchId,
78103
workspaceName),
79104
savedSearchId,
80-
createSavedSearch,
81-
() => CheckSavedSearchExists(resourceGroupName, workspaceName, savedSearchId));
105+
(patch && existed) ? updateSavedSearch : createSavedSearch ,
106+
() => existed);
82107
return status;
83108
}
84109

src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsComputerGroupCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected override void ProcessRecord()
7575
Tags = new List<Tag>() { new Tag() { Name = "Group", Value = "Computer" } }
7676
};
7777

78-
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true);
78+
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, false, Force, ConfirmAction), true);
7979
}
8080

8181
}

src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsSavedSearchCommand.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Azure.Management.OperationalInsights.Models;
1818
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1919
using System.Net;
20+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2021

2122
namespace Microsoft.Azure.Commands.OperationalInsights
2223
{
@@ -73,7 +74,8 @@ public class NewAzureOperationalInsightsSavedSearchCommand : OperationalInsights
7374

7475
[Parameter(Position = 9, Mandatory = false,
7576
HelpMessage = "The optional function parameters if query serves as a function. Value should be in the following format: 'param-name1:type1 = default_value1, param-name2:type2 = default_value2'. For more examples and proper syntax please refer to https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions.")]
76-
[ValidateNotNullOrEmpty]
77+
[ValidateNotNull]
78+
[Alias("FunctionParameters")]
7779
public string FunctionParameter { get; set; }
7880

7981
[Parameter(Mandatory = false, HelpMessage = "Don't ask for confirmation.")]
@@ -91,8 +93,10 @@ protected override void ProcessRecord()
9193
FunctionParameters = this.FunctionParameter
9294
};
9395

96+
bool patch = this.IsParameterBound(c => c.FunctionParameter);
97+
9498
properties.Tags = SearchCommandHelper.PopulateAndValidateTagsForProperties(this.Tag, properties.Query);
95-
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true);
99+
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, patch, Force, ConfirmAction), true);
96100
}
97101

98102
}

src/OperationalInsights/OperationalInsights/Search/SetAzureOperationalInsightsSavedSearch.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Azure.Management.OperationalInsights.Models;
1818
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1919
using System.Net;
20+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2021

2122
namespace Microsoft.Azure.Commands.OperationalInsights
2223
{
@@ -78,7 +79,8 @@ public class SetAzureOperationalInsightsSavedSearchCommand : OperationalInsights
7879

7980
[Parameter(Position = 10, Mandatory = false,
8081
HelpMessage = "The optional function parameters if query serves as a function. Value should be in the following format: 'param-name1:type1 = default_value1, param-name2:type2 = default_value2'. For more examples and proper syntax please refer to https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions.")]
81-
[ValidateNotNullOrEmpty]
82+
[ValidateNotNull]
83+
[Alias("FunctionParameters")]
8284
public string FunctionParameter { get; set; }
8385

8486
protected override void ProcessRecord()
@@ -93,8 +95,10 @@ protected override void ProcessRecord()
9395
FunctionParameters = this.FunctionParameter
9496
};
9597

98+
bool patch = this.IsParameterBound(c => c.FunctionParameter);
99+
96100
properties.Tags = SearchCommandHelper.PopulateAndValidateTagsForProperties(this.Tag, properties.Query);
97-
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, true, ConfirmAction, ETag), true);
101+
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, patch, true, ConfirmAction, ETag), true);
98102
}
99103

100104
}

src/OperationalInsights/OperationalInsights/help/New-AzOperationalInsightsSavedSearch.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Creates a new saved search with the specified parameters.
1616
```
1717
New-AzOperationalInsightsSavedSearch [-ResourceGroupName] <String> [-WorkspaceName] <String>
1818
[-SavedSearchId] <String> [-DisplayName] <String> [-Category] <String> [-Query] <String> [[-Tag] <Hashtable>]
19-
[[-Version] <Int64>] [[-FunctionAlias] <String>] [[-FunctionParameters] <String>] [-Force]
19+
[[-Version] <Int64>] [[-FunctionAlias] <String>] [[-FunctionParameter] <String>] [-Force]
2020
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2121
```
2222

@@ -109,13 +109,13 @@ Accept pipeline input: False
109109
Accept wildcard characters: False
110110
```
111111
112-
### -FunctionParameters
112+
### -FunctionParameter
113113
The optional function parameters if query serves as a function. Value should be in the following format: 'param-name1:type1 = default_value1, param-name2:type2 = default_value2'. For more examples and proper syntax please refer to https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions.
114114
115115
```yaml
116116
Type: System.String
117117
Parameter Sets: (All)
118-
Aliases:
118+
Aliases: FunctionParameters
119119

120120
Required: False
121121
Position: 9

src/OperationalInsights/OperationalInsights/help/Set-AzOperationalInsightsSavedSearch.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Updates a saved search that already exists.
1616
```
1717
Set-AzOperationalInsightsSavedSearch [-ResourceGroupName] <String> [-WorkspaceName] <String>
1818
[-SavedSearchId] <String> [-DisplayName] <String> [-Category] <String> [-Query] <String> [[-Tag] <Hashtable>]
19-
[[-Version] <Int64>] [[-ETag] <String>] [[-FunctionAlias] <String>] [[-FunctionParameters] <String>]
19+
[[-Version] <Int64>] [[-ETag] <String>] [[-FunctionAlias] <String>] [[-FunctionParameter] <String>]
2020
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2121
```
2222

@@ -109,13 +109,13 @@ Accept pipeline input: False
109109
Accept wildcard characters: False
110110
```
111111
112-
### -FunctionParameters
112+
### -FunctionParameter
113113
The optional function parameters if query serves as a function. Value should be in the following format: 'param-name1:type1 = default_value1, param-name2:type2 = default_value2'. For more examples and proper syntax please refer to https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions.
114114
115115
```yaml
116116
Type: System.String
117117
Parameter Sets: (All)
118-
Aliases:
118+
Aliases: FunctionParameters
119119

120120
Required: False
121121
Position: 10

0 commit comments

Comments
 (0)