Skip to content

Commit

Permalink
Use Uri.AbsoluteUri for Key Vault (#22480)
Browse files Browse the repository at this point in the history
Partial fix for #22413
  • Loading branch information
heaths authored Jul 6, 2021
1 parent 9a498e3 commit e86f662
Show file tree
Hide file tree
Showing 22 changed files with 29 additions and 32 deletions.
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"azsdk",
"blazor",
"contoso",
"deserializable",
"deserializes",
"diagnoser",
"dtmf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<NoWarn>$(NoWarn);3021</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableBannedApiAnalyzers>false</EnableBannedApiAnalyzers>

<!-- Disable warning for missing xml doc comments until we can add all the missing ones -->
<NoWarn>$(NoWarn);1591</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public CertificateOperation(CertificateClient client, string name)

Properties = new CertificateOperationProperties(client.VaultUri, name);

Id = Properties.Id.ToString();
Id = Properties.Id.AbsoluteUri;
_client = client;
}

internal CertificateOperation(Response<CertificateOperationProperties> properties, CertificateClient client)
{
Properties = properties;

Id = Properties.Id.ToString();
Id = Properties.Id.AbsoluteUri;
_client = client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ private CertificatesEventSource() : base(EventSourceName, EventSourceSettings.De

[NonEvent]
public void BeginUpdateStatus(CertificateOperationProperties properties) =>
BeginUpdateStatus(properties?.Id.ToString(), properties?.Status, properties?.Error?.Message);
BeginUpdateStatus(properties?.Id.AbsoluteUri, properties?.Status, properties?.Error?.Message);

[Event(BeginUpdateStatusEvent, Level = EventLevel.Verbose, Message = "Updating certificate operation status: {0}, current status: {1}, error: {2}")]
public void BeginUpdateStatus(string id, string status, string error) => WriteEvent(BeginUpdateStatusEvent, id ?? Deleted, status, error ?? NoError);

[NonEvent]
public void EndUpdateStatus(CertificateOperationProperties properties) =>
EndUpdateStatus(properties?.Id.ToString(), properties?.Status, properties?.Error?.Message);
EndUpdateStatus(properties?.Id.AbsoluteUri, properties?.Status, properties?.Error?.Message);

[Event(EndUpdateStatusEvent, Level = EventLevel.Verbose, Message = "Updated certificate operation status: {0}, ending status: {1}, error: {2}")]
public void EndUpdateStatus(string id, string status, string error) => WriteEvent(EndUpdateStatusEvent, id ?? Deleted, status, error ?? NoError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal DeleteCertificateOperation(KeyVaultPipeline pipeline, Response<DeletedC
protected DeleteCertificateOperation() {}

/// <inheritdoc/>
public override string Id => _value.Id.ToString();
public override string Id => _value.Id.AbsoluteUri;

/// <summary>
/// Gets the <see cref="DeletedCertificate"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal DeletedCertificate(CertificateProperties properties = null) : base(prop
public Uri RecoveryId
{
get => _recoveryId is null ? null : new Uri(_recoveryId);
internal set => _recoveryId = value?.ToString();
internal set => _recoveryId = value?.AbsoluteUri;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal KeyVaultCertificate(CertificateProperties properties = null)
public Uri KeyId
{
get => new Uri(_keyId);
internal set => _keyId = value?.ToString();
internal set => _keyId = value?.AbsoluteUri;
}

/// <summary>
Expand All @@ -48,7 +48,7 @@ public Uri KeyId
public Uri SecretId
{
get => new Uri(_secretId);
internal set => _secretId = value?.ToString();
internal set => _secretId = value?.AbsoluteUri;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal RecoverDeletedCertificateOperation(KeyVaultPipeline pipeline, Response<
protected RecoverDeletedCertificateOperation() {}

/// <inheritdoc/>
public override string Id => _value.Id.ToString();
public override string Id => _value.Id.AbsoluteUri;

/// <summary>
/// Gets the <see cref="KeyVaultCertificate"/> of the certificate being recovered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<NoWarn>$(NoWarn);3021</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableBannedApiAnalyzers>false</EnableBannedApiAnalyzers>

</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal CryptographyClient(Uri keyId, TokenCredential credential, CryptographyC
Argument.AssertNotNull(keyId, nameof(keyId));
Argument.AssertNotNull(credential, nameof(credential));

_keyId = keyId.ToString();
_keyId = keyId.AbsoluteUri;
options ??= new CryptographyClientOptions();

RemoteCryptographyClient remoteClient = new RemoteCryptographyClient(new Uri(_keyId), credential, options);
Expand Down Expand Up @@ -154,7 +154,7 @@ internal CryptographyClient(Uri keyId, KeyVaultPipeline pipeline)
{
Argument.AssertNotNull(keyId, nameof(keyId));

_keyId = keyId.ToString();
_keyId = keyId.AbsoluteUri;

RemoteCryptographyClient remoteClient = new RemoteCryptographyClient(pipeline);

Expand Down Expand Up @@ -1482,8 +1482,8 @@ internal byte[] CreateDigest(SignatureAlgorithm algorithm, byte[] data, string n
{
try
{
using HashAlgorithm hashAlgo = algorithm.GetHashAlgorithm();
return hashAlgo.ComputeHash(data);
using HashAlgorithm hashAlgorithm = algorithm.GetHashAlgorithm();
return hashAlgorithm.ComputeHash(data);
}
catch (InvalidOperationException ex) when (LocalOnly)
{
Expand All @@ -1496,8 +1496,8 @@ internal byte[] CreateDigest(SignatureAlgorithm algorithm, Stream data, string n
{
try
{
using HashAlgorithm hashAlgo = algorithm.GetHashAlgorithm();
return hashAlgo.ComputeHash(data);
using HashAlgorithm hashAlgorithm = algorithm.GetHashAlgorithm();
return hashAlgorithm.ComputeHash(data);
}
catch (InvalidOperationException ex) when (LocalOnly)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public virtual async Task<Response<VerifyResult>> VerifyAsync(SignatureAlgorithm

try
{
return await Pipeline.SendRequestAsync(RequestMethod.Post, parameters, () => new VerifyResult { Algorithm = algorithm, KeyId = _keyId.ToString() }, cancellationToken, "/verify").ConfigureAwait(false);
return await Pipeline.SendRequestAsync(RequestMethod.Post, parameters, () => new VerifyResult { Algorithm = algorithm, KeyId = _keyId.AbsoluteUri }, cancellationToken, "/verify").ConfigureAwait(false);
}
catch (Exception e)
{
Expand All @@ -294,7 +294,7 @@ public virtual Response<VerifyResult> Verify(SignatureAlgorithm algorithm, byte[

try
{
return Pipeline.SendRequest(RequestMethod.Post, parameters, () => new VerifyResult { Algorithm = algorithm, KeyId = _keyId.ToString() }, cancellationToken, "/verify");
return Pipeline.SendRequest(RequestMethod.Post, parameters, () => new VerifyResult { Algorithm = algorithm, KeyId = _keyId.AbsoluteUri }, cancellationToken, "/verify");
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal DeleteKeyOperation(KeyVaultPipeline pipeline, Response<DeletedKey> resp
protected DeleteKeyOperation() {}

/// <inheritdoc/>
public override string Id => _value.Id.ToString();
public override string Id => _value.Id.AbsoluteUri;

/// <summary>
/// Gets the <see cref="DeletedKey"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal DeletedKey(string name) : base(name)
public Uri RecoveryId
{
get => _recoveryId is null ? null : new Uri(_recoveryId);
internal set => _recoveryId = value?.ToString();
internal set => _recoveryId = value?.AbsoluteUri;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal RecoverDeletedKeyOperation(KeyVaultPipeline pipeline, Response<KeyVault
protected RecoverDeletedKeyOperation() {}

/// <inheritdoc/>
public override string Id => _value.Id.ToString();
public override string Id => _value.Id.AbsoluteUri;

/// <summary>
/// Gets the <see cref="KeyVaultKey"/> of the key being recovered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<NoWarn>$(NoWarn);3021</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableBannedApiAnalyzers>false</EnableBannedApiAnalyzers>
</PropertyGroup>

<Import Project="..\..\Azure.Security.KeyVault.Shared\src\Azure.Security.KeyVault.Shared.projitems" Label="Shared" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal DeleteSecretOperation(KeyVaultPipeline pipeline, Response<DeletedSecret
protected DeleteSecretOperation() {}

/// <inheritdoc/>
public override string Id => _value.Id.ToString();
public override string Id => _value.Id.AbsoluteUri;

/// <summary>
/// Gets the <see cref="DeletedSecret"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal DeletedSecret(SecretProperties properties = null) : base(properties)
public Uri RecoveryId
{
get => _recoveryId is null ? null : new Uri(_recoveryId);
internal set => _recoveryId = value?.ToString();
internal set => _recoveryId = value?.AbsoluteUri;
}

/// <summary>
Expand Down Expand Up @@ -72,7 +72,7 @@ internal override void WriteProperties(Utf8JsonWriter json)

if (RecoveryId != null)
{
json.WriteString(s_recoveryIdPropertyNameBytes, RecoveryId.ToString());
json.WriteString(s_recoveryIdPropertyNameBytes, RecoveryId.AbsoluteUri);
}

if (DeletedOn.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal RecoverDeletedSecretOperation(KeyVaultPipeline pipeline, Response<Secre
protected RecoverDeletedSecretOperation() {}

/// <inheritdoc/>
public override string Id => _value.Id.ToString();
public override string Id => _value.Id.AbsoluteUri;

/// <summary>
/// Gets the <see cref="SecretProperties"/> of the secret being recovered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public SecretProperties(Uri id)
public Uri KeyId
{
get => _keyId is null ? null : new Uri(_keyId);
internal set => _keyId = value?.ToString();
internal set => _keyId = value?.AbsoluteUri;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public async Task<Page<T>> GetPageAsync<T>(Uri firstPageUri, string nextLink, Fu
responseAsPage.Deserialize(response.ContentStream);

// convert from the Page<T> to PageResponse<T>
return Page<T>.FromValues(responseAsPage.Items.ToArray(), responseAsPage.NextLink?.ToString(), response);
return Page<T>.FromValues(responseAsPage.Items.ToArray(), responseAsPage.NextLink?.AbsoluteUri, response);
}
catch (Exception e)
{
Expand Down Expand Up @@ -158,7 +158,7 @@ public Page<T> GetPage<T>(Uri firstPageUri, string nextLink, Func<T> itemFactory
responseAsPage.Deserialize(response.ContentStream);

// convert from the Page<T> to PageResponse<T>
return Page<T>.FromValues(responseAsPage.Items.ToArray(), responseAsPage.NextLink?.ToString(), response);
return Page<T>.FromValues(responseAsPage.Items.ToArray(), responseAsPage.NextLink?.AbsoluteUri, response);
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/samples/sharelink/ManagedStorageRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static ManagedStorageRestClient Create(Uri vaultUri, TokenCredential cr
new ChallengeBasedAuthenticationPolicy(credential ?? throw new ArgumentNullException(nameof(credential))));

ClientDiagnostics diagnostics = new ClientDiagnostics(options);
return new ManagedStorageRestClient(diagnostics, pipeline, vaultUri.ToString());
return new ManagedStorageRestClient(diagnostics, pipeline, vaultUri.AbsoluteUri);
}
}
}
1 change: 0 additions & 1 deletion sdk/keyvault/samples/sharelink/ShareLink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</NoWarn>
<IncludeAzureCoreSharedCode>true</IncludeAzureCoreSharedCode>
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
<EnableBannedApiAnalyzers>false</EnableBannedApiAnalyzers>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit e86f662

Please sign in to comment.