Skip to content

Commit

Permalink
Keyvault: Managed Storage Account Keys Samples (#3306)
Browse files Browse the repository at this point in the history
  • Loading branch information
rijethma authored and shahabhijeet committed Jun 7, 2017
1 parent 82bb16b commit 525efc1
Show file tree
Hide file tree
Showing 14 changed files with 520 additions and 80 deletions.
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<appSettings>
<!-- Update these settings for your test environment -->
<add key="VaultUrl" value="URL to your Vault" />
<add key="AuthClientId" value="Client Id of your Service Principal" />
<add key="AuthCertThumbprint" value="Thumbprint of the certificate used for authentication" />
<add key="ArmStorageAccountResourceId" value="Resource Id of your storage account" />
<add key="TracingEnabled" value="false" />
</appSettings>
<runtime>
Expand All @@ -18,4 +19,4 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</configuration>
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HelloKeyVault</RootNamespace>
<AssemblyName>HelloKeyVault</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<PublishUrl>publish\</PublishUrl>
Expand All @@ -29,6 +29,7 @@
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>4c02428b</NuGetPackageImportStamp>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -51,12 +52,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Azure.KeyVault, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\Packages\Microsoft.Azure.KeyVault.2.0.1-preview\lib\net45\Microsoft.Azure.KeyVault.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.Azure.KeyVault, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\Packages\Microsoft.Azure.KeyVault.2.3.0-preview\lib\net452\Microsoft.Azure.KeyVault.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.KeyVault.WebKey, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\Packages\Microsoft.Azure.KeyVault.WebKey.2.0.0-preview\lib\net45\Microsoft.Azure.KeyVault.WebKey.dll</HintPath>
<Reference Include="Microsoft.Azure.KeyVault.WebKey">
<HintPath>..\..\Packages\Microsoft.Azure.KeyVault.WebKey.2.0.6\lib\net452\Microsoft.Azure.KeyVault.WebKey.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.22.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand All @@ -68,12 +68,10 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\Packages\Microsoft.Rest.ClientRuntime.2.3.2\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
<HintPath>..\..\Packages\Microsoft.Rest.ClientRuntime.2.3.8\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\Packages\Microsoft.Rest.ClientRuntime.Azure.3.3.1\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
<Private>True</Private>
<HintPath>..\..\Packages\Microsoft.Rest.ClientRuntime.Azure.3.3.7\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down
Expand Up @@ -66,6 +66,17 @@ public List<KeyOperationType> GetKeyOperations()
keyOperations.Add( KeyOperationType.LIST_CERTIFICATEVERSIONS );
keyOperations.Add( KeyOperationType.LIST_CERTIFICATES );
keyOperations.Add( KeyOperationType.DELETE_CERTIFICATE );
keyOperations.Add(KeyOperationType.CREATE_STORAGE_ACCOUNT);
keyOperations.Add(KeyOperationType.GET_STORAGE_ACCOUNT);
keyOperations.Add(KeyOperationType.UPDATE_STORAGE_ACCOUNT);
keyOperations.Add(KeyOperationType.LIST_STORAGE_ACCOUNT);
keyOperations.Add(KeyOperationType.REGENERATE_STORAGE_ACCOUNT_KEY);
keyOperations.Add(KeyOperationType.CREATE_STORAGE_SAS_DEFINITION);
keyOperations.Add(KeyOperationType.GET_STORAGE_SAS_DEFINITION);
keyOperations.Add(KeyOperationType.UPDATE_STORAGE_SAS_DEFINITION);
keyOperations.Add(KeyOperationType.LIST_STORAGE_SAS_DEFINITION);
keyOperations.Add(KeyOperationType.DELETE_STORAGE_SAS_DEFINITION);
keyOperations.Add(KeyOperationType.DELETE_STORAGE_ACCOUNT);
}
return keyOperations;
}
Expand Down Expand Up @@ -297,6 +308,58 @@ public string GetCertificateName(bool mandatory = false, bool allowDefault = tru
return name;
}

/// <summary>
/// Get storage account name from argument list.
/// </summary>
/// <param name="mandatory">Whether the cli parameter is mandatory or not </param>
/// <returns>The name of the storage account.</returns>
public string GetStorageAccountName(bool mandatory = false, bool allowDefault = true)
{
var tag = "-storageaccountname";
string name = GetArgumentValue(tag);

if (name == string.Empty)
{
if (mandatory == true)
{
throw new Exception(tag + " argument is missing");
}
if (allowDefault)
{
name = "storage" + new Random().Next(0, 9999);
Console.Out.WriteLine(tag + " is not provided. Using default value: " + name);
}
}

return name;
}

/// <summary>
/// Get sas definition name from argument list.
/// </summary>
/// <param name="mandatory">Whether the cli parameter is mandatory or not </param>
/// <returns>The name of the sas definition.</returns>
public string GetSasDefinitionName(bool mandatory = false, bool allowDefault = true)
{
var tag = "-sasdefinitionname";
string name = GetArgumentValue(tag);

if (name == string.Empty)
{
if (mandatory == true)
{
throw new Exception(tag + " argument is missing");
}
if (allowDefault)
{
name = "storagesas" + new Random().Next(0, 9999);
Console.Out.WriteLine(tag + " is not provided. Using default value: " + name);
}
}

return name;
}

/// <summary>
/// Get certificate name from argument list
/// </summary>
Expand Down
Expand Up @@ -28,6 +28,17 @@ enum KeyOperationType
EXPORT_CERTIFICATE,
LIST_CERTIFICATEVERSIONS,
LIST_CERTIFICATES,
DELETE_CERTIFICATE
DELETE_CERTIFICATE,
CREATE_STORAGE_ACCOUNT,
GET_STORAGE_ACCOUNT,
UPDATE_STORAGE_ACCOUNT,
DELETE_STORAGE_ACCOUNT,
LIST_STORAGE_ACCOUNT,
REGENERATE_STORAGE_ACCOUNT_KEY,
CREATE_STORAGE_SAS_DEFINITION,
GET_STORAGE_SAS_DEFINITION,
UPDATE_STORAGE_SAS_DEFINITION,
DELETE_STORAGE_SAS_DEFINITION,
LIST_STORAGE_SAS_DEFINITION
}
}

0 comments on commit 525efc1

Please sign in to comment.