Skip to content
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

Adding back alias and script cmdlet definitions for resource and sql modules #1082

Merged
merged 3 commits into from
Oct 8, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@

using Microsoft.Azure.Commands.Resources.Models;
using System.Collections.Generic;
using System.IO;
using System.Management.Automation;
using System.Reflection;
using Microsoft.Azure.Common.Authentication;

namespace Microsoft.Azure.Commands.Resources
{
/// <summary>
/// Filters resource groups.
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureRmResourceGroup", DefaultParameterSetName = ResourceGroupNameParameterSet), OutputType(typeof(List<PSResourceGroup>))]
public class GetAzureResourceGroupCommand : ResourcesBaseCmdlet
public class GetAzureResourceGroupCommand : ResourcesBaseCmdlet, IModuleAssemblyInitializer
{
/// <summary>
/// List resources group by name parameter set.
Expand Down Expand Up @@ -57,5 +60,25 @@ protected override void ProcessRecord()
ResourcesClient.FilterResourceGroups(name: this.Name, tag: null, detailed: false, location: this.Location),
true);
}

/// <summary>
/// Load global aliases and script cmdlets for ARM
/// </summary>
public void OnImport()
{
try
{
System.Management.Automation.PowerShell invoker = null;
invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"ResourceManagerStartup.ps1")));
invoker.Invoke();
}
catch
{
// This may throw exception for tests, ignore.
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@
# limitations under the License.
# ----------------------------------------------------------------------------------

@{
# Sql aliases
"Get-AzureRmSqlDatabaseServerAuditingPolicy" = "Get-AzureRmSqlServerAuditingPolicy";
"Remove-AzureRmSqlDatabaseServerAuditing" = "Remove-AzureRmSqlServerAuditing";
"Set-AzureRmSqlDatabaseServerAuditingPolicy" = "Set-AzureRmSqlServerAuditingPolicy";
"Use-AzureRmSqlDatabaseServerAuditingPolicy" = "Use-AzureRmSqlServerAuditingPolicy";

# Storage aliases
"Get-AzureRmStorageContainerAcl" = "Get-AzureRmStorageContainer";
"Start-CopyAzureStorageBlob" = "Start-AzureRmStorageBlobCopy";
"Stop-CopyAzureStorageBlob" = "Stop-AzureRmStorageBlobCopy";
}.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"


# Authorization script commandlet that builds on top of existing Insights comandlets.
# This commandlet gets all events for the "Microsoft.Authorization" resource provider by calling the "Get-AzureRmResourceProviderLog" commandlet

Expand Down
3 changes: 3 additions & 0 deletions src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@
<Compile Include="TransparentDataEncryption\Model\AzureSqlDatabaseTransparentDataEncryptionModel.cs" />
<Compile Include="TransparentDataEncryption\Services\AzureSqlDatabaseTransparentDataEncryptionAdapter.cs" />
<Compile Include="TransparentDataEncryption\Services\AzureSqlDatabaseTransparentDataEncryptionCommunicator.cs" />
<None Include="SqlStartup.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using System.IO;
using System.Management.Automation;
using System.Reflection;
using Microsoft.Azure.Commands.Sql.Server.Model;
using Microsoft.Azure.Common.Authentication;

namespace Microsoft.Azure.Commands.Sql.Server.Cmdlet
{
/// <summary>
/// Defines the Get-AzureRmSqlServer cmdlet
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureRmSqlServer", ConfirmImpact = ConfirmImpact.None)]
public class GetAzureSqlServer : AzureSqlServerCmdletBase
public class GetAzureSqlServer : AzureSqlServerCmdletBase, IModuleAssemblyInitializer
{
/// <summary>
/// Gets or sets the name of the database server to use.
Expand Down Expand Up @@ -74,5 +77,25 @@ protected override IEnumerable<AzureSqlServerModel> ApplyUserInputToModel(IEnume
{
return model;
}

/// <summary>
/// Add Sql aliases
/// </summary>
public void OnImport()
{
try
{
System.Management.Automation.PowerShell invoker = null;
invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"SqlStartup.ps1")));
invoker.Invoke();
}
catch
{
// This may throw exception for tests, ignore.
}
}
}
}
22 changes: 22 additions & 0 deletions src/ResourceManager/Sql/Commands.Sql/SqlStartup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

@{
# Sql aliases
"Get-AzureRmSqlDatabaseServerAuditingPolicy" = "Get-AzureRmSqlServerAuditingPolicy";
"Remove-AzureRmSqlDatabaseServerAuditing" = "Remove-AzureRmSqlServerAuditing";
"Set-AzureRmSqlDatabaseServerAuditingPolicy" = "Set-AzureRmSqlServerAuditingPolicy";
"Use-AzureRmSqlDatabaseServerAuditingPolicy" = "Use-AzureRmSqlServerAuditingPolicy";
}.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"