Skip to content

Commit

Permalink
Applied APIView suggestion for KV Admin. (Azure#22381)
Browse files Browse the repository at this point in the history
* Applied APIView suggestions.

* Applied APIView suggestions.

* Fixed SpotBugs issue.

* Fixed another SpotBugs issue.
  • Loading branch information
vcolin7 authored Jun 18, 2021
1 parent 913b669 commit b2931f9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,6 +17,7 @@
*/
@Immutable
public final class KeyVaultCertificateIdentifier {
private final ClientLogger logger = new ClientLogger(KeyVaultCertificateIdentifier.class);
private final String sourceId, vaultUrl, name, version;

/**
Expand All @@ -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 {
Expand All @@ -47,15 +49,17 @@ 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;
this.vaultUrl = String.format("%s://%s", url.getProtocol(), url.getHost());
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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,6 +17,7 @@
*/
@Immutable
public final class KeyVaultKeyIdentifier {
private final ClientLogger logger = new ClientLogger(KeyVaultKeyIdentifier.class);
private final String sourceId, vaultUrl, name, version;

/**
Expand All @@ -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 {
Expand All @@ -47,15 +49,17 @@ 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;
this.vaultUrl = String.format("%s://%s", url.getProtocol(), url.getHost());
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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,6 +17,7 @@
*/
@Immutable
public final class KeyVaultSecretIdentifier {
private final ClientLogger logger = new ClientLogger(KeyVaultSecretIdentifier.class);
private final String sourceId, vaultUrl, name, version;

/**
Expand All @@ -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 {
Expand All @@ -47,15 +49,17 @@ 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;
this.vaultUrl = String.format("%s://%s", url.getProtocol(), url.getHost());
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));
}
}

Expand Down

0 comments on commit b2931f9

Please sign in to comment.