Skip to content

add alias for functionparameter #12085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/OperationalInsights/OperationalInsights/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- Additional information about change #1
-->
## Upcoming Release
* Added alias "FunctionParameters" for parameter "FunctionParameter" to
- `New-AzOperationalInsightsSavedSearch`
- `Set-AzOperationalInsightsSavedSearch`

## Version 2.1.0
* Upgraded SDK to 0.21.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,43 @@ public virtual PSSearchGetSchemaResponse GetSchema(string resourceGroupName, str
return schemaResponse;
}

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)
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)
{
PSSearchGetSavedSearchResponse ExistingSearch;
bool existed;

try
{
ExistingSearch = GetSavedSearch(resourceGroupName, workspaceName, savedSearchId);
}
catch (Rest.Azure.CloudException)
{
ExistingSearch = null;
}

existed = ExistingSearch == null ? false : true;

HttpStatusCode status = HttpStatusCode.Ambiguous;
Action createSavedSearch = () =>
{
if (ETag != null && ETag != "")
{
if (ETag != null && ETag != "")
{
properties.ETag = ETag;
}
Rest.Azure.AzureOperationResponse<SavedSearch> result = OperationalInsightsManagementClient.SavedSearches.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, savedSearchId, properties).GetAwaiter().GetResult();
status = result.Response.StatusCode;
};
properties.ETag = ETag;
}
Rest.Azure.AzureOperationResponse<SavedSearch> result = OperationalInsightsManagementClient.SavedSearches.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, savedSearchId, properties).GetAwaiter().GetResult();
status = result.Response.StatusCode;
};

Action updateSavedSearch = () =>
{
if (ETag != null && ETag != "")
{
properties.ETag = ETag;
}
properties.FunctionParameters = ExistingSearch.Properties.FunctionParameters;
Rest.Azure.AzureOperationResponse<SavedSearch> result = OperationalInsightsManagementClient.SavedSearches.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, savedSearchId, properties).GetAwaiter().GetResult();
status = result.Response.StatusCode;
};

ConfirmAction(
force, // prompt only if the saved search exists
Expand All @@ -77,8 +102,8 @@ public virtual HttpStatusCode CreateOrUpdateSavedSearch(string resourceGroupName
savedSearchId,
workspaceName),
savedSearchId,
createSavedSearch,
() => CheckSavedSearchExists(resourceGroupName, workspaceName, savedSearchId));
(patch && existed) ? updateSavedSearch : createSavedSearch ,
() => existed);
return status;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected override void ProcessRecord()
Tags = new List<Tag>() { new Tag() { Name = "Group", Value = "Computer" } }
};

WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true);
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, false, Force, ConfirmAction), true);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.Azure.Management.OperationalInsights.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using System.Net;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.OperationalInsights
{
Expand Down Expand Up @@ -73,7 +74,8 @@ public class NewAzureOperationalInsightsSavedSearchCommand : OperationalInsights

[Parameter(Position = 9, Mandatory = false,
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.")]
[ValidateNotNullOrEmpty]
[ValidateNotNull]
[Alias("FunctionParameters")]
public string FunctionParameter { get; set; }

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

bool patch = this.IsParameterBound(c => c.FunctionParameter);

properties.Tags = SearchCommandHelper.PopulateAndValidateTagsForProperties(this.Tag, properties.Query);
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true);
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, patch, Force, ConfirmAction), true);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.Azure.Management.OperationalInsights.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using System.Net;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.OperationalInsights
{
Expand Down Expand Up @@ -78,7 +79,8 @@ public class SetAzureOperationalInsightsSavedSearchCommand : OperationalInsights

[Parameter(Position = 10, Mandatory = false,
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.")]
[ValidateNotNullOrEmpty]
[ValidateNotNull]
[Alias("FunctionParameters")]
public string FunctionParameter { get; set; }

protected override void ProcessRecord()
Expand All @@ -93,8 +95,10 @@ protected override void ProcessRecord()
FunctionParameters = this.FunctionParameter
};

bool patch = this.IsParameterBound(c => c.FunctionParameter);

properties.Tags = SearchCommandHelper.PopulateAndValidateTagsForProperties(this.Tag, properties.Query);
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, true, ConfirmAction, ETag), true);
WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, patch, true, ConfirmAction, ETag), true);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Creates a new saved search with the specified parameters.
```
New-AzOperationalInsightsSavedSearch [-ResourceGroupName] <String> [-WorkspaceName] <String>
[-SavedSearchId] <String> [-DisplayName] <String> [-Category] <String> [-Query] <String> [[-Tag] <Hashtable>]
[[-Version] <Int64>] [[-FunctionAlias] <String>] [[-FunctionParameters] <String>] [-Force]
[[-Version] <Int64>] [[-FunctionAlias] <String>] [[-FunctionParameter] <String>] [-Force]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand Down Expand Up @@ -109,13 +109,13 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -FunctionParameters
### -FunctionParameter
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.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Aliases: FunctionParameters

Required: False
Position: 9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Updates a saved search that already exists.
```
Set-AzOperationalInsightsSavedSearch [-ResourceGroupName] <String> [-WorkspaceName] <String>
[-SavedSearchId] <String> [-DisplayName] <String> [-Category] <String> [-Query] <String> [[-Tag] <Hashtable>]
[[-Version] <Int64>] [[-ETag] <String>] [[-FunctionAlias] <String>] [[-FunctionParameters] <String>]
[[-Version] <Int64>] [[-ETag] <String>] [[-FunctionAlias] <String>] [[-FunctionParameter] <String>]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

Expand Down Expand Up @@ -109,13 +109,13 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -FunctionParameters
### -FunctionParameter
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.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Aliases: FunctionParameters

Required: False
Position: 10
Expand Down