Skip to content

Commit

Permalink
Fix ShareLink sample to be able to build again (Azure#21170)
Browse files Browse the repository at this point in the history
* Fix ShareLink sample to be able to build again

Relates to Azure#21074

* Build Key Vault samples in CI
  • Loading branch information
heaths authored May 19, 2021
1 parent 558de77 commit 2103c38
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 135 deletions.
1 change: 1 addition & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<PackageReference Update="Azure.Identity" Version="1.2.1" />
<PackageReference Update="Azure.Security.KeyVault.Secrets" Version="4.0.2" />
<PackageReference Update="Azure.Security.KeyVault.Keys" Version="4.0.2" />
<PackageReference Update="Azure.Security.KeyVault.Certificates" Version="4.0.2" />
<PackageReference Update="Azure.Storage.Blobs" Version="12.8.0" />

<!-- Other approved packages -->
Expand Down
8 changes: 6 additions & 2 deletions sdk/keyvault/samples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ExcludeFromCodeCoverage>true</ExcludeFromCodeCoverage>
<ImportRepoCommonSettings>true</ImportRepoCommonSettings>
<!-- Signal that samples are building in the repo as opposed to a standalone download from Samples Browser -->
<IsClientLibrary>true</IsClientLibrary>
<IsPackable>true</IsPackable>
<IsSample>true</IsSample>
<IsPackable>false</IsPackable>
<ExcludeFromCodeCoverage>true</ExcludeFromCodeCoverage>
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
</PropertyGroup>

<Import Project="..\Directory.Build.props" />

<PropertyGroup>
<DefineConstants>STRONGNAME_SIGNED</DefineConstants>
<InheritDocEnabled>false</InheritDocEnabled>
<IsShippingLibrary>false</IsShippingLibrary>
</PropertyGroup>
</Project>
14 changes: 14 additions & 0 deletions sdk/keyvault/samples/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>

<PropertyGroup>
<TargetFrameworks Condition="'$(TargetFramework)' != ''">$(TargetFramework)</TargetFrameworks>
</PropertyGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.targets))\Directory.Build.targets"
Condition="'$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.targets))' != ''" />

<!-- Disable targets not necessary for samples -->
<Target Name="ValidateTargetFrameworks" />
<Target Name="VerifyProjectReferencesReferences" />

</Project>
21 changes: 17 additions & 4 deletions sdk/keyvault/samples/getcert/getcert.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NoWarn>
$(NoWarn);
CA1810;
AZC0100;
</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.2.2" />
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.1.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.1.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20371.2" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Security.KeyVault.Certificates" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
<PackageReference Include="System.CommandLine" VersionOverride="2.0.0-beta1.21216.1" />
</ItemGroup>

<!-- Use decentralized package references when building outside https://github.com/Azure/azure-sdk-for-net -->
<ItemGroup Condition="'$(IsSample)' != 'true'">
<PackageReference Update="Azure.Identity" Version="1.4.0" />
<PackageReference Update="Azure.Security.KeyVault.Certificates" Version="4.1.1" />
<PackageReference Update="Azure.Security.KeyVault.Secrets" Version="4.1.1" />
<PackageReference Update="System.CommandLine" Version="%(VersionOverride)" />
</ItemGroup>

</Project>
11 changes: 0 additions & 11 deletions sdk/keyvault/samples/keyvaultproxy/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<Project>
<PropertyGroup>
<ImportRepoCommonSettings>true</ImportRepoCommonSettings>
<IsClientLibrary>true</IsClientLibrary>
</PropertyGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props"
Condition="'$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))' != ''" />

Expand All @@ -14,11 +9,5 @@
$(NoWarn);
AZC0001
</NoWarn>
<IsShippingLibrary>false</IsShippingLibrary>
</PropertyGroup>

<!-- If building within the Azure/azure-sdk-for-net repo -->
<PropertyGroup Condition="'$(IsSample)' == 'true'">
<DefineConstants>STRONGNAME_SIGNED</DefineConstants>
</PropertyGroup>
</Project>
7 changes: 4 additions & 3 deletions sdk/keyvault/samples/keyvaultproxy/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project>
<!-- Use decentralized package references when building outside https://github.com/Azure/azure-sdk-for-net -->
<ItemGroup Condition="'$(IsSample)' != 'true'">
<PackageReference Update="Azure.Core" Version="1.2.1" />
<PackageReference Update="Azure.Identity" Version="1.1.1" />
<PackageReference Update="Azure.Security.KeyVault.Secrets" Version="4.0.3" />
<PackageReference Update="Azure.Core" Version="1.14.0" />
<PackageReference Update="Azure.Identity" Version="1.4.0" />
<PackageReference Update="Azure.Security.KeyVault.Secrets" Version="4.1.1" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Update="xunit" Version="2.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<Description>A sample pipeline policy to cache secrets, keys, and certificates in-memory.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/keyvault/samples/keyvaultproxy</RepositoryUrl>
<IsPackable>true</IsPackable>
<GenerateDocumentation>true</GenerateDocumentation>
</PropertyGroup>

Expand Down
106 changes: 20 additions & 86 deletions sdk/keyvault/samples/sharelink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,89 +9,11 @@ urlFragment: share-link
name: ShareLink
description: Demonstrates how to generate a client for Key Vault-managed storage accounts and generate SAS tokens.
extendedZipContent:
# Shared/AutoRest
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/ArmOperationHelpers.cs
target: /Shared/AutoRest/ArmOperationHelpers.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/ChangeTrackingDictionary.cs
target: /Shared/AutoRest/ChangeTrackingDictionary.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/ChangeTrackingList.cs
target: /Shared/AutoRest/ChangeTrackingList.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenClientAttribute.cs
target: /Shared/AutoRest/CodeGenClientAttribute.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenMemberAttribute.cs
target: /Shared/AutoRest/CodeGenMemberAttribute.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenModelAttribute.cs
target: /Shared/AutoRest/CodeGenModelAttribute.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenSuppressAttribute.cs
target: /Shared/AutoRest/CodeGenSuppressAttribute.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenTypeAttribute.cs
target: /Shared/AutoRest/CodeGenTypeAttribute.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/IOperationSource.cs
target: /Shared/AutoRest/IOperationSource.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/IUtf8JsonSerializable.cs
target: /Shared/AutoRest/IUtf8JsonSerializable.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/IXmlSerializable.cs
target: /Shared/AutoRest/IXmlSerializable.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/JsonElementExtensions.cs
target: /Shared/AutoRest/JsonElementExtensions.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/ManagementPipelineBuilder.cs
target: /Shared/AutoRest/ManagementPipelineBuilder.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/OperationFinalStateVia.cs
target: /Shared/AutoRest/OperationFinalStateVia.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/Optional.cs
target: /Shared/AutoRest/Optional.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/Page.cs
target: /Shared/AutoRest/Page.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/PageableHelpers.cs
target: /Shared/AutoRest/PageableHelpers.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/RawRequestUriBuilder.cs
target: /Shared/AutoRest/RawRequestUriBuilder.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/RequestHeaderExtensions.cs
target: /Shared/AutoRest/RequestHeaderExtensions.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/RequestUriBuilderExtensions.cs
target: /Shared/AutoRest/RequestUriBuilderExtensions.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/ResponseHeadersExtensions.cs
target: /Shared/AutoRest/ResponseHeadersExtensions.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders.cs
target: /Shared/AutoRest/ResponseWithHeaders.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders{T,THeaders}.cs
target: /Shared/AutoRest/ResponseWithHeaders{T,THeaders}.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders{THeaders}.cs
target: /Shared/AutoRest/ResponseWithHeaders{THeaders}.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/StringRequestContent.cs
target: /Shared/AutoRest/StringRequestContent.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/TypeFormatters.cs
target: /Shared/AutoRest/TypeFormatters.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/Utf8JsonRequestContent.cs
target: /Shared/AutoRest/Utf8JsonRequestContent.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/Utf8JsonWriterExtensions.cs
target: /Shared/AutoRest/Utf8JsonWriterExtensions.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/XElementExtensions.cs
target: /Shared/AutoRest/XElementExtensions.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/XmlWriterContent.cs
target: /Shared/AutoRest/XmlWriterContent.cs
- path: /sdk/core/Azure.Core/src/Shared/AutoRest/XmlWriterExtensions.cs
target: /Shared/AutoRest/XmlWriterExtensions.cs

# Shared/Core
- path: /sdk/core/Azure.Core/src/Shared/ClientDiagnostics.cs
target: /Shared/Core/ClientDiagnostics.cs
- path: /sdk/core/Azure.Core/src/Shared/ContentTypeUtilities.cs
target: /Shared/Core/ContentTypeUtilities.cs
- path: /sdk/core/Azure.Core/src/Shared/DiagnosticScope.cs
target: /Shared/Core/DiagnosticScope.cs
- path: /sdk/core/Azure.Core/src/Shared/DiagnosticScopeFactory.cs
target: /Shared/Core/DiagnosticScopeFactory.cs
- path: /sdk/core/Azure.Core/src/Shared/HashCodeBuilder.cs
target: /Shared/Core/HashCodeBuilder.cs
- path: /sdk/core/Azure.Core/src/Shared/HttpMessageSanitizer.cs
target: /Shared/Core/HttpMessageSanitizer.cs
- path: /sdk/core/Azure.Core/src/Shared/OperationHelpers.cs
target: /Shared/Core/OperationHelpers.cs
- path: /sdk/core/Azure.Core/src/Shared/TaskExtensions.cs
target: /Shared/Core/TaskExtensions.cs

# Share
# Package sources for AutoRest support
- path: /nuget.config
target: /nuget.config

# Shared
- path: /sdk/keyvault/Azure.Security.KeyVault.Shared/src/ChallengeBasedAuthenticationPolicy.cs
target: /Shared/ChallengeBasedAuthenticationPolicy.cs
---
Expand All @@ -103,6 +25,12 @@ This sample demonstrates how to generate a client library for [Azure Key Vault-m
> [!NOTE]
> We recommend you use [role-based access control (RBAC)](https://docs.microsoft.com/azure/role-based-access-control/overview) to secure access to your storage accounts. You can centrally manage access for users and applications to resources in a way that is consistent across Azure, and [works with Azure Active Directory](https://docs.microsoft.com/azure/storage/common/storage-auth-aad).
If you want to manage secrets, keys, or certificates, you can use our existing supported SDKs:

- [Azure.Security.KeyVault.Certificates](https://www.nuget.org/packages/Azure.Security.KeyVault.Certificates)
- [Azure.Security.KeyVault.Keys](https://www.nuget.org/packages/Azure.Security.KeyVault.Keys)
- [Azure.Security.KeyVault.Secrets](https://www.nuget.org/packages/Azure.Security.KeyVault.Secrets)

## Getting started

Before you can use this sample to create SAS tokens to share storage objects, you need to register the storage account with Key Vault. The following instructions require installing the [Azure CLI](https://aka.ms/azure-cli).
Expand Down Expand Up @@ -147,13 +75,19 @@ This sample not only demonstrates how to generate SAS definitions and tokens usi
dotnet build
```

We have no plans to ship a package for Key Vault-managed storage accounts since RBAC is recommended, but if you need support for managerd storage accounts you can copy the REST client source into your own projects by running:
We have no plans to ship a package for Key Vault-managed storage accounts since RBAC is recommended, but if you need support for managed storage accounts you can copy the REST client source into your own projects by running:

```bash
dotnet msbuild /t:CopySource /p:Destination=<ProjectDirectory>
dotnet build /t:CopySource /p:Destination=<ProjectDirectory>
```

The sample project file and _Program.cs_ are not copied automatically - only the source necessary to build the REST client. You are welcome to copy and modify the rest of the sample source as needed.
The sample project file and _Program.cs_ are not copied automatically. Only the source necessary to build the REST client is copied. You are welcome to copy and modify the rest of the sample source as needed.

You also need to add a reference to Azure.Core in your project. In your project directory where you just copied source run:

```bash
dotnet add package Azure.Core
```

## Using the sample

Expand Down
44 changes: 17 additions & 27 deletions sdk/keyvault/samples/sharelink/ShareLink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
<RootNamespace>Azure.Security.KeyVault.Storage</RootNamespace>
<NoWarn>
$(NoWarn);
CS1574;
CS8601;
CA1810;
CA1835;
CA2016;
AZC0100;
</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(IsClientLibrary)' != 'true'">
<!-- Define properties when not generating source -->
<AzureCoreSharedSources>$(MSBuildThisFileDirectory)..\..\..\core\Azure.Core\src\Shared\</AzureCoreSharedSources>
<IncludeAzureCoreSharedCode>true</IncludeAzureCoreSharedCode>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
<PackageReference Include="System.CommandLine" VersionOverride="2.0.0-beta1.20371.2" />
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" />
<PackageReference Include="System.CommandLine" VersionOverride="2.0.0-beta1.21216.1" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<ItemGroup Condition="'$(IsSample)' == 'true'">
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" PrivateAssets="All" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\..\..\eng\Packages.Data.props" Condition="'$(IsSample)' == 'true'" />
<ItemGroup Condition="'$(IsSample)' == 'true'">
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(IsClientLibrary)' != 'true'">
<!-- Define package versions when not generating source (uses central package versions) -->

<ItemGroup Condition="'$(IsSample)' != 'true'">
<!-- Use decentralized package references when building outside https://github.com/Azure/azure-sdk-for-net -->
<PackageReference Update="Azure.Core" Version="1.14.0" />
<PackageReference Update="Azure.Identity" Version="1.3.0" />
<PackageReference Update="Azure.Security.KeyVault.Secrets" Version="4.1.0" />
<PackageReference Update="Azure.Identity" Version="1.4.0" />
<PackageReference Update="Azure.Security.KeyVault.Secrets" Version="4.1.1" />
<PackageReference Update="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20210510.2" PrivateAssets="All" />
<PackageReference Update="System.CommandLine" Version="%(VersionOverride)" />
<PackageReference Update="System.Text.Json" Version="4.6.0" />
</ItemGroup>
Expand All @@ -44,13 +44,6 @@
<Compile Include="..\..\Azure.Security.KeyVault.Shared\src\ChallengeBasedAuthenticationPolicy.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup Condition="'$(IsSample)' == 'true'">
<!-- Link files needed by the source generator -->
<Compile Include="$(AzureCoreSharedSources)HashCodeBuilder.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)AuthorizationChallengeParser.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)Base64Url.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
</ItemGroup>

<Target Name="CopySource">
<Error Text="The 'Destination' property must be specified" Condition="'$(Destination)' == ''" />

Expand All @@ -62,10 +55,7 @@
</_Source>
</ItemGroup>

<Copy SourceFiles="@(_Source)"
DestinationFiles="@(_Source->'$(Destination)\%(Link)')"
OverwriteReadOnlyFiles="true"
SkipUnchangedFiles="true" />
<Copy SourceFiles="@(_Source)" DestinationFiles="@(_Source->'$(Destination)\%(Link)')" OverwriteReadOnlyFiles="true" SkipUnchangedFiles="true" />
</Target>

</Project>
2 changes: 1 addition & 1 deletion sdk/keyvault/samples/sharelink/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> see https://aka.ms/autorest
Run `dotnet build /t:GenerateCode /p:IsClientLibrary=true` in src directory to re-generate.
Run `dotnet build /t:GenerateCode` in source directory to re-generate.

``` yaml
title: Azure.Security.KeyVault.Storage
Expand Down

0 comments on commit 2103c38

Please sign in to comment.