Skip to content

Dev #191

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 8 commits into from
Nov 13, 2015
Merged

Dev #191

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 @@ -236,6 +236,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests.KeyVaultManagementTests\TestGetVaultByNameAndResourceGroupPositionalParams.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests.KeyVaultManagementTests\TestGetVaultByNameCapitalized.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests.KeyVaultManagementTests\TestGetVaultFromUnknownResourceGroupFails.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ public void TestGetVaultByName()
);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetVaultByNameCapitalized()
{
KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
() => new[] { string.Format("{0} {1}", "Test-GetVaultByName", _data.preCreatedVault.ToUpper()) },
env => Initialize(),
null,
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName()
);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetUnknownVaultFails()
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class AddAzureKeyVaultKey : KeyVaultCmdletBase
[Parameter(Mandatory = false,
ParameterSetName = ImportParameterSet,
HelpMessage = "Specifies whether to add the key as a software-protected key or an HSM-protected key in the Key Vault service. Valid values are: HSM and Software. ")]
[ValidateSetAttribute(new string[] { HsmDestination, SoftwareDestination })]
[ValidateSetAttribute(HsmDestination, SoftwareDestination)]
public string Destination { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Microsoft.Azure.Commands.KeyVault
{
public static class Constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Management.KeyVault;
using PSKeyVaultModels = Microsoft.Azure.Commands.KeyVault.Models;
using PSKeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;

Expand Down Expand Up @@ -89,8 +88,7 @@ protected override void ProcessRecord()
ActiveDirectoryClient);
if (vault == null)
throw new ArgumentException(string.Format(PSKeyVaultProperties.Resources.VaultNotFound, VaultName, ResourceGroupName));
else
WriteObject(vault);
WriteObject(vault);
break;

case ListVaultsByRGParameterSet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ protected override void ProcessRecord()
WriteObject(keyBundle);
break;
case ByKeyVersionsParameterSet:
keyBundle = DataServiceClient.GetKey(VaultName, Name, null);
keyBundle = DataServiceClient.GetKey(VaultName, Name, null);
if (keyBundle != null)
{
WriteObject(new KeyIdentityItem(keyBundle));
GetAndWriteKeyVersions(VaultName, Name, keyBundle.Version);
GetAndWriteKeyVersions(VaultName, Name, keyBundle.Version);
}
break;
case ByVaultNameParameterSet:
GetAndWriteKeys(VaultName);
Expand All @@ -123,7 +125,7 @@ private void GetAndWriteKeys(string vaultName)
{
KeyVaultObjectFilterOptions options = new KeyVaultObjectFilterOptions
{
VaultName = VaultName,
VaultName = vaultName,
NextLink = null
};

Expand All @@ -138,7 +140,7 @@ private void GetAndWriteKeyVersions(string vaultName, string name, string curren
{
KeyVaultObjectFilterOptions options = new KeyVaultObjectFilterOptions
{
VaultName = VaultName,
VaultName = vaultName,
NextLink = null,
Name = name
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ protected override void ProcessRecord()
case BySecretVersionsParameterSet:
secret = DataServiceClient.GetSecret(VaultName, Name, null);
if (secret != null)
{
WriteObject(new SecretIdentityItem(secret));
GetAndWriteSecretVersions(VaultName, Name, secret.Version);
GetAndWriteSecretVersions(VaultName, Name, secret.Version);
}
break;
case ByVaultNameParameterSet:
GetAndWriteSecrets(VaultName);
Expand All @@ -119,9 +121,9 @@ protected override void ProcessRecord()

private void GetAndWriteSecrets(string vaultName)
{
KeyVaultObjectFilterOptions options = new KeyVaultObjectFilterOptions
var options = new KeyVaultObjectFilterOptions
{
VaultName = VaultName,
VaultName = vaultName,
NextLink = null
};
do
Expand All @@ -132,9 +134,9 @@ private void GetAndWriteSecrets(string vaultName)

private void GetAndWriteSecretVersions(string vaultName, string name, string currentSecretVersion)
{
KeyVaultObjectFilterOptions options = new KeyVaultObjectFilterOptions
var options = new KeyVaultObjectFilterOptions
{
VaultName = VaultName,
VaultName = vaultName,
Name = name,
NextLink = null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System;
using System.Collections;
using System.Management.Automation;
using Microsoft.Azure.Management.KeyVault;
using PSKeyVaultModels = Microsoft.Azure.Commands.KeyVault.Models;
using PSKeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System;
using System.Globalization;
using System.Management.Automation;
using Microsoft.Azure.Management.KeyVault;
using PSKeyVaultModels = Microsoft.Azure.Commands.KeyVault.Models;
using PSKeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System;
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Management.KeyVault;
using PSKeyVaultModels = Microsoft.Azure.Commands.KeyVault.Models;
using PSKeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;

Expand Down Expand Up @@ -152,7 +151,7 @@ protected override void ProcessRecord()

// Update vault policies
var updatedPolicies = existingVault.AccessPolicies;
if (!string.IsNullOrEmpty(UserPrincipalName) || !string.IsNullOrEmpty(ServicePrincipalName) || (ObjectId != null && ObjectId != Guid.Empty))
if (!string.IsNullOrEmpty(UserPrincipalName) || !string.IsNullOrEmpty(ServicePrincipalName) || (ObjectId != Guid.Empty))
{
Guid objId = GetObjectId(this.ObjectId, this.UserPrincipalName, this.ServicePrincipalName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Management.Automation;
using Microsoft.Azure.Commands.KeyVault.Models;
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Management.Automation;
using Microsoft.Azure.Commands.KeyVault.Models;
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.KeyVault.Models;
using System;
using System.IO;
using System.Management.Automation;
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System;
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Management.KeyVault;
using PSKeyVaultModels = Microsoft.Azure.Commands.KeyVault.Models;
using PSKeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;

Expand Down Expand Up @@ -199,17 +198,15 @@ protected override void ProcessRecord()
throw new ArgumentException(string.Format(PSKeyVaultProperties.Resources.PermissionSetIncludesAllPlusOthers, "secrets"));

//Is there an existing policy for this policy identity?
var existingPolicy = vault.AccessPolicies.Where(ap => MatchVaultAccessPolicyIdentity(ap, objId, ApplicationId)).FirstOrDefault();
var existingPolicy = vault.AccessPolicies.FirstOrDefault(ap => MatchVaultAccessPolicyIdentity(ap, objId, ApplicationId));

//New policy will have permission arrays that are either from cmdlet input
//or if that's null, then from the old policy for this object ID if one existed
var keys = PermissionsToKeys != null ? PermissionsToKeys :
(existingPolicy != null && existingPolicy.PermissionsToKeys != null ?
var keys = PermissionsToKeys ?? (existingPolicy != null && existingPolicy.PermissionsToKeys != null ?
existingPolicy.PermissionsToKeys.ToArray() : null);

var secrets = PermissionsToSecrets != null ? PermissionsToSecrets :
(existingPolicy != null && existingPolicy.PermissionsToSecrets != null ?
existingPolicy.PermissionsToSecrets.ToArray() : null);
var secrets = PermissionsToSecrets ?? (existingPolicy != null && existingPolicy.PermissionsToSecrets != null ?
existingPolicy.PermissionsToSecrets.ToArray() : null);

//Remove old policies for this policy identity and add a new one with the right permissions, iff there were some non-empty permissions
updatedListOfAccessPolicies = vault.AccessPolicies.Where(ap => !MatchVaultAccessPolicyIdentity(ap, objId, this.ApplicationId)).ToArray();
Expand All @@ -224,7 +221,7 @@ protected override void ProcessRecord()

// Update the vault
var updatedVault = KeyVaultManagementClient.UpdateVault(vault, updatedListOfAccessPolicies,
this.EnabledForDeployment.IsPresent ? true : vault.EnabledForDeployment,
EnabledForDeployment.IsPresent || vault.EnabledForDeployment,
EnabledForTemplateDeployment.IsPresent ? true : vault.EnabledForTemplateDeployment,
EnabledForDiskEncryption.IsPresent ? true : vault.EnabledForDiskEncryption,
ActiveDirectoryClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using System;
using System.Collections;
using System.Security;
using System.Management.Automation;
using Microsoft.Azure.Commands.KeyVault.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public DataServiceCredential(IAuthenticationFactory authFactory, AzureContext co

var bundle = GetToken(authFactory, context);
this.token = bundle.Item1;
this.resourceId = bundle.Item2;
}

/// <summary>
Expand Down Expand Up @@ -82,8 +81,6 @@ private Tuple<IAccessToken, string> GetToken(IAuthenticationFactory authFactory,
}

private IAccessToken token;
private string resourceId;

private const AzureEnvironment.Endpoint ResourceIdEndpoint = AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.IO;
using System.Security;
using Microsoft.Azure.KeyVault.WebKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Azure.KeyVault;

namespace Microsoft.Azure.Commands.KeyVault.Models
{
Expand Down Expand Up @@ -82,9 +81,9 @@ public Dictionary<string, string> TagsDirectionary
}
}

public static explicit operator Microsoft.Azure.KeyVault.KeyAttributes(KeyAttributes attr)
public static explicit operator Azure.KeyVault.KeyAttributes(KeyAttributes attr)
{
return new Microsoft.Azure.KeyVault.KeyAttributes()
return new Azure.KeyVault.KeyAttributes()
{
Enabled = attr.Enabled,
NotBefore = attr.NotBefore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using System;
using Microsoft.Azure.KeyVault.WebKey;
using Microsoft.Azure.KeyVault;
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;

namespace Microsoft.Azure.Commands.KeyVault.Models
Expand All @@ -24,7 +23,7 @@ public class KeyBundle : ObjectIdentifier
public KeyBundle()
{ }

internal KeyBundle(Microsoft.Azure.KeyVault.KeyBundle keyBundle, VaultUriHelper vaultUriHelper)
internal KeyBundle(Azure.KeyVault.KeyBundle keyBundle, VaultUriHelper vaultUriHelper)
{
if (keyBundle == null)
throw new ArgumentNullException("keyBundle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@

using System;
using System.Collections;
using Microsoft.Azure.KeyVault.WebKey;
using Microsoft.Azure.KeyVault;
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;

namespace Microsoft.Azure.Commands.KeyVault.Models
{
public class KeyIdentityItem : ObjectIdentifier
{
internal KeyIdentityItem(Microsoft.Azure.KeyVault.KeyItem keyItem, VaultUriHelper vaultUriHelper)
internal KeyIdentityItem(Azure.KeyVault.KeyItem keyItem, VaultUriHelper vaultUriHelper)
{
if (keyItem == null)
throw new ArgumentNullException("keyItem");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Common.Authentication;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.IO;
using System.Net.Http;
using Microsoft.Azure.Commands.ResourceManager.Common;

namespace Microsoft.Azure.Commands.KeyVault.Models
{
public class KeyVaultCmdletBase : AzureRMCmdlet
{
public KeyVaultCmdletBase()
{
}

{
internal IKeyVaultDataServiceClient DataServiceClient
{
get
Expand Down
Loading