Skip to content

Commit

Permalink
Azure.Template | Don't generate public client (#12840)
Browse files Browse the repository at this point in the history
* don't generate public client

* remove public-clients
  • Loading branch information
annelo-msft authored Jun 17, 2020
1 parent d15c59a commit 9caad5f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 83 deletions.
75 changes: 0 additions & 75 deletions sdk/template/Azure.Template/src/Generated/MiniSecretClient.cs

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 61 additions & 3 deletions sdk/template/Azure.Template/src/MiniSecretClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
// Licensed under the MIT License.

using System;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.Template.Models;

namespace Azure.Template
{
/// <summary>
/// The sample secrets client.
/// </summary>
[CodeGenClient("ServiceClient")]
public partial class MiniSecretClient
public class MiniSecretClient
{
private readonly ClientDiagnostics _clientDiagnostics;
private readonly HttpPipeline _pipeline;
internal ServiceRestClient RestClient { get; }

/// <summary>
/// Initializes a new instance of the <see cref="MiniSecretClient"/>.
/// </summary>
Expand All @@ -30,5 +36,57 @@ public MiniSecretClient(Uri endpoint, TokenCredential credential, MiniSecretClie
options.Version)
{
}

/// <summary> Initializes a new instance of MiniSecretClient for mocking. </summary>
protected MiniSecretClient()
{
}
/// <summary> Initializes a new instance of MiniSecretClient. </summary>
/// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
/// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
/// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
/// <param name="apiVersion"> Api Version. </param>
internal MiniSecretClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string vaultBaseUrl, string apiVersion = "7.0")
{
RestClient = new ServiceRestClient(clientDiagnostics, pipeline, vaultBaseUrl, apiVersion);
_clientDiagnostics = clientDiagnostics;
_pipeline = pipeline;
}

/// <summary> The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission. </summary>
/// <param name="secretName"> The name of the secret. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SecretBundle>> GetSecretAsync(string secretName, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MiniSecretClient.GetSecret");
scope.Start();
try
{
return await RestClient.GetSecretAsync(secretName, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}

/// <summary> The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission. </summary>
/// <param name="secretName"> The name of the secret. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SecretBundle> GetSecret(string secretName, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MiniSecretClient.GetSecret");
scope.Start();
try
{
return RestClient.GetSecret(secretName, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
}
}
}
2 changes: 0 additions & 2 deletions sdk/template/Azure.Template/src/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ Run `dotnet msbuild /t:GenerateCode` to generate code.
``` yaml
input-file:
- $(this-folder)/swagger/mini-secrets.json

public-clients: true
```

0 comments on commit 9caad5f

Please sign in to comment.