From b2931f9ddee4211ec6721a56e5a82ff17580942f Mon Sep 17 00:00:00 2001 From: vcolin7 Date: Fri, 18 Jun 2021 15:30:47 -0700 Subject: [PATCH] Applied APIView suggestion for KV Admin. (#22381) * Applied APIView suggestions. * Applied APIView suggestions. * Fixed SpotBugs issue. * Fixed another SpotBugs issue. --- .../CHANGELOG.md | 2 +- .../administration/models/KeyVaultRoleScope.java | 10 +++++++--- .../models/KeyVaultCertificateIdentifier.java | 10 +++++++--- .../keyvault/keys/models/KeyVaultKeyIdentifier.java | 10 +++++++--- .../secrets/models/KeyVaultSecretIdentifier.java | 10 +++++++--- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/sdk/keyvault/azure-security-keyvault-administration/CHANGELOG.md b/sdk/keyvault/azure-security-keyvault-administration/CHANGELOG.md index f48f2c7b1f06e..c2359cea9abaa 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/CHANGELOG.md +++ b/sdk/keyvault/azure-security-keyvault-administration/CHANGELOG.md @@ -1,7 +1,7 @@ # Release History ## 4.0.0 (2021-06-17) -- Initial release of `KeyVaultAccessControlClient` and `KeyVaultAccessControlAsyncClient` to managed role assignments and definitions for Managed HSM. +- Initial release of `KeyVaultAccessControlClient` and `KeyVaultAccessControlAsyncClient` to manage role assignments and definitions for Managed HSM. - Initial release of `KeyVaultBackupClient` and `KeyVaultBackupAsyncClient` to backup and restore Managed HSM. ### Features Added diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleScope.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleScope.java index ae654c7dda0dd..6bd6295819ee2 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleScope.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleScope.java @@ -30,10 +30,14 @@ public static KeyVaultRoleScope fromString(String name) { * * @param url A string representing a URL containing the name of the scope to look for. * @return The corresponding {@link KeyVaultRoleScope}. - * @throws MalformedURLException If the given {@link String URL String} is malformed. + * @throws IllegalArgumentException If the given {@link String URL String} is malformed. */ - public static KeyVaultRoleScope fromUrl(String url) throws MalformedURLException { - return fromString(new URL(url).getPath(), KeyVaultRoleScope.class); + public static KeyVaultRoleScope fromUrl(String url) { + try { + return fromString(new URL(url).getPath(), KeyVaultRoleScope.class); + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); + } } /** diff --git a/sdk/keyvault/azure-security-keyvault-certificates/src/main/java/com/azure/security/keyvault/certificates/models/KeyVaultCertificateIdentifier.java b/sdk/keyvault/azure-security-keyvault-certificates/src/main/java/com/azure/security/keyvault/certificates/models/KeyVaultCertificateIdentifier.java index 176b5912a4e1e..22261639a6cd1 100644 --- a/sdk/keyvault/azure-security-keyvault-certificates/src/main/java/com/azure/security/keyvault/certificates/models/KeyVaultCertificateIdentifier.java +++ b/sdk/keyvault/azure-security-keyvault-certificates/src/main/java/com/azure/security/keyvault/certificates/models/KeyVaultCertificateIdentifier.java @@ -4,6 +4,7 @@ package com.azure.security.keyvault.certificates.models; import com.azure.core.annotation.Immutable; +import com.azure.core.util.logging.ClientLogger; import com.azure.security.keyvault.certificates.CertificateAsyncClient; import com.azure.security.keyvault.certificates.CertificateClient; @@ -16,6 +17,7 @@ */ @Immutable public final class KeyVaultCertificateIdentifier { + private final ClientLogger logger = new ClientLogger(KeyVaultCertificateIdentifier.class); private final String sourceId, vaultUrl, name, version; /** @@ -37,7 +39,7 @@ public final class KeyVaultCertificateIdentifier { */ public KeyVaultCertificateIdentifier(String sourceId) { if (sourceId == null) { - throw new NullPointerException("'sourceId' cannot be null"); + throw logger.logExceptionAsError(new NullPointerException("'sourceId' cannot be null")); } try { @@ -47,7 +49,8 @@ public KeyVaultCertificateIdentifier(String sourceId) { // More or less segments in the URI than expected. if (pathSegments.length != 3 && pathSegments.length != 4) { - throw new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier."); + throw logger.logExceptionAsError( + new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.")); } this.sourceId = sourceId; @@ -55,7 +58,8 @@ public KeyVaultCertificateIdentifier(String sourceId) { this.name = pathSegments[2]; this.version = pathSegments.length == 4 ? pathSegments[3] : null; } catch (MalformedURLException e) { - throw new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.", e); + throw logger.logExceptionAsError( + new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.", e)); } } diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/models/KeyVaultKeyIdentifier.java b/sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/models/KeyVaultKeyIdentifier.java index 61d6ab51a2a71..b8dfc13a8d26d 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/models/KeyVaultKeyIdentifier.java +++ b/sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/models/KeyVaultKeyIdentifier.java @@ -4,6 +4,7 @@ package com.azure.security.keyvault.keys.models; import com.azure.core.annotation.Immutable; +import com.azure.core.util.logging.ClientLogger; import com.azure.security.keyvault.keys.KeyAsyncClient; import com.azure.security.keyvault.keys.KeyClient; @@ -16,6 +17,7 @@ */ @Immutable public final class KeyVaultKeyIdentifier { + private final ClientLogger logger = new ClientLogger(KeyVaultKeyIdentifier.class); private final String sourceId, vaultUrl, name, version; /** @@ -37,7 +39,7 @@ public final class KeyVaultKeyIdentifier { */ public KeyVaultKeyIdentifier(String sourceId) { if (sourceId == null) { - throw new NullPointerException("'sourceId' cannot be null."); + throw logger.logExceptionAsError(new NullPointerException("'sourceId' cannot be null.")); } try { @@ -47,7 +49,8 @@ public KeyVaultKeyIdentifier(String sourceId) { // More or less segments in the URI than expected. if (pathSegments.length != 3 && pathSegments.length != 4) { - throw new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier."); + throw logger.logExceptionAsError( + new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.")); } this.sourceId = sourceId; @@ -55,7 +58,8 @@ public KeyVaultKeyIdentifier(String sourceId) { this.name = pathSegments[2]; this.version = pathSegments.length == 4 ? pathSegments[3] : null; } catch (MalformedURLException e) { - throw new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.", e); + throw logger.logExceptionAsError( + new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.", e)); } } diff --git a/sdk/keyvault/azure-security-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/models/KeyVaultSecretIdentifier.java b/sdk/keyvault/azure-security-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/models/KeyVaultSecretIdentifier.java index d1296c4be85b2..9e19ecdbf573a 100644 --- a/sdk/keyvault/azure-security-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/models/KeyVaultSecretIdentifier.java +++ b/sdk/keyvault/azure-security-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/models/KeyVaultSecretIdentifier.java @@ -4,6 +4,7 @@ package com.azure.security.keyvault.secrets.models; import com.azure.core.annotation.Immutable; +import com.azure.core.util.logging.ClientLogger; import com.azure.security.keyvault.secrets.SecretAsyncClient; import com.azure.security.keyvault.secrets.SecretClient; @@ -16,6 +17,7 @@ */ @Immutable public final class KeyVaultSecretIdentifier { + private final ClientLogger logger = new ClientLogger(KeyVaultSecretIdentifier.class); private final String sourceId, vaultUrl, name, version; /** @@ -37,7 +39,7 @@ public final class KeyVaultSecretIdentifier { */ public KeyVaultSecretIdentifier(String sourceId) { if (sourceId == null) { - throw new NullPointerException("'sourceId' cannot be null."); + throw logger.logExceptionAsError(new NullPointerException("'sourceId' cannot be null.")); } try { @@ -47,7 +49,8 @@ public KeyVaultSecretIdentifier(String sourceId) { // More or less segments in the URI than expected. if (pathSegments.length != 3 && pathSegments.length != 4) { - throw new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier."); + throw logger.logExceptionAsError( + new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.")); } this.sourceId = sourceId; @@ -55,7 +58,8 @@ public KeyVaultSecretIdentifier(String sourceId) { this.name = pathSegments[2]; this.version = pathSegments.length == 4 ? pathSegments[3] : null; } catch (MalformedURLException e) { - throw new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.", e); + throw logger.logExceptionAsError( + new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.", e)); } }