Skip to content

Commit 69a3b48

Browse files
committed
Added convenience layer for Keys.
1 parent fd20273 commit 69a3b48

27 files changed

+7053
-11
lines changed

sdk/keyvault/azure-security-keyvault-keys-v2/src/main/java/com/azure/v2/security/keyvault/keys/KeyClient.java

+1,920
Large diffs are not rendered by default.

sdk/keyvault/azure-security-keyvault-keys-v2/src/main/java/com/azure/v2/security/keyvault/keys/KeyClientBuilder.java

+479
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.v2.security.keyvault.keys.implementation;
4+
5+
import com.azure.v2.security.keyvault.keys.models.DeletedKey;
6+
import com.azure.v2.security.keyvault.keys.models.JsonWebKey;
7+
8+
import java.time.OffsetDateTime;
9+
10+
public final class DeletedKeyHelper {
11+
private static DeletedKeyAccessor accessor;
12+
13+
public interface DeletedKeyAccessor {
14+
DeletedKey createDeletedKey(JsonWebKey jsonWebKey);
15+
16+
void setRecoveryId(DeletedKey deletedKey, String recoveryId);
17+
18+
void setScheduledPurgeDate(DeletedKey deletedKey, OffsetDateTime scheduledPurgeDate);
19+
20+
void setDeletedOn(DeletedKey deletedKey, OffsetDateTime deletedOn);
21+
}
22+
23+
private DeletedKeyHelper() {
24+
}
25+
26+
public static DeletedKey createDeletedKey(JsonWebKey jsonWebKey) {
27+
if (accessor == null) {
28+
new DeletedKey();
29+
}
30+
31+
assert accessor != null;
32+
return accessor.createDeletedKey(jsonWebKey);
33+
}
34+
35+
public static void setRecoveryId(DeletedKey deletedKey, String recoveryId) {
36+
accessor.setRecoveryId(deletedKey, recoveryId);
37+
}
38+
39+
public static void setScheduledPurgeDate(DeletedKey deletedKey, OffsetDateTime scheduledPurgeDate) {
40+
accessor.setScheduledPurgeDate(deletedKey, scheduledPurgeDate);
41+
}
42+
43+
public static void setDeletedOn(DeletedKey deletedKey, OffsetDateTime deletedOn) {
44+
accessor.setDeletedOn(deletedKey, deletedOn);
45+
}
46+
47+
public static void setAccessor(DeletedKeyAccessor accessor) {
48+
DeletedKeyHelper.accessor = accessor;
49+
}
50+
}

sdk/keyvault/azure-security-keyvault-keys-v2/src/main/java/com/azure/v2/security/keyvault/keys/implementation/KeyClientImpl.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ public Response<KeyBundle> getKeyWithResponse(String keyName, String keyVersion,
11441144
* @throws HttpResponseException thrown if the service returns an error.
11451145
* @return the key list result.
11461146
*/
1147-
private PagedResponse<KeyItem> getKeyVersionsSinglePage(String keyName, RequestOptions requestOptions) {
1147+
public PagedResponse<KeyItem> getKeyVersionsSinglePage(String keyName, RequestOptions requestOptions) {
11481148
Response<KeyListResult> res
11491149
= service.getKeyVersions(this.getServiceVersion().getVersion(), keyName, requestOptions);
11501150
return new PagedResponse<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getBody(),
@@ -1257,7 +1257,7 @@ public PagedIterable<KeyItem> getKeyVersions(String keyName, RequestOptions requ
12571257
* @throws HttpResponseException thrown if the service returns an error.
12581258
* @return the key list result.
12591259
*/
1260-
private PagedResponse<KeyItem> getKeysSinglePage(RequestOptions requestOptions) {
1260+
public PagedResponse<KeyItem> getKeysSinglePage(RequestOptions requestOptions) {
12611261
Response<KeyListResult> res = service.getKeys(this.getServiceVersion().getVersion(), requestOptions);
12621262
return new PagedResponse<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getBody(),
12631263
res.getValue().getValue(), null, res.getValue().getNextLink(), null, null, null);
@@ -1816,7 +1816,7 @@ public Response<ReleaseKeyResult> releaseWithResponse(String keyName, String key
18161816
* @throws HttpResponseException thrown if the service returns an error.
18171817
* @return a list of keys that have been deleted in this vault.
18181818
*/
1819-
private PagedResponse<DeletedKeyItem> getDeletedKeysSinglePage(RequestOptions requestOptions) {
1819+
public PagedResponse<DeletedKeyItem> getDeletedKeysSinglePage(RequestOptions requestOptions) {
18201820
Response<DeletedKeyListResult> res
18211821
= service.getDeletedKeys(this.getServiceVersion().getVersion(), requestOptions);
18221822
return new PagedResponse<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getBody(),
@@ -2219,7 +2219,7 @@ public Response<RandomBytes> getRandomBytesWithResponse(BinaryData parameters, R
22192219
* @throws HttpResponseException thrown if the service returns an error.
22202220
* @return the key list result.
22212221
*/
2222-
private PagedResponse<KeyItem> getKeyVersionsNextSinglePage(String nextLink, RequestOptions requestOptions) {
2222+
public PagedResponse<KeyItem> getKeyVersionsNextSinglePage(String nextLink, RequestOptions requestOptions) {
22232223
Response<KeyListResult> res = service.getKeyVersionsNext(nextLink, requestOptions);
22242224
return new PagedResponse<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getBody(),
22252225
res.getValue().getValue(), null, res.getValue().getNextLink(), null, null, null);
@@ -2264,7 +2264,7 @@ private PagedResponse<KeyItem> getKeyVersionsNextSinglePage(String nextLink, Req
22642264
* @throws HttpResponseException thrown if the service returns an error.
22652265
* @return the key list result.
22662266
*/
2267-
private PagedResponse<KeyItem> getKeysNextSinglePage(String nextLink, RequestOptions requestOptions) {
2267+
public PagedResponse<KeyItem> getKeysNextSinglePage(String nextLink, RequestOptions requestOptions) {
22682268
Response<KeyListResult> res = service.getKeysNext(nextLink, requestOptions);
22692269
return new PagedResponse<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getBody(),
22702270
res.getValue().getValue(), null, res.getValue().getNextLink(), null, null, null);
@@ -2312,7 +2312,7 @@ private PagedResponse<KeyItem> getKeysNextSinglePage(String nextLink, RequestOpt
23122312
* @throws HttpResponseException thrown if the service returns an error.
23132313
* @return a list of keys that have been deleted in this vault.
23142314
*/
2315-
private PagedResponse<DeletedKeyItem> getDeletedKeysNextSinglePage(String nextLink, RequestOptions requestOptions) {
2315+
public PagedResponse<DeletedKeyItem> getDeletedKeysNextSinglePage(String nextLink, RequestOptions requestOptions) {
23162316
Response<DeletedKeyListResult> res = service.getDeletedKeysNext(nextLink, requestOptions);
23172317
return new PagedResponse<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getBody(),
23182318
res.getValue().getValue(), null, res.getValue().getNextLink(), null, null, null);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.v2.security.keyvault.keys.implementation;
4+
5+
import com.azure.v2.security.keyvault.keys.models.KeyProperties;
6+
7+
import java.time.OffsetDateTime;
8+
9+
public final class KeyPropertiesHelper {
10+
private static KeyPropertiesAccessor accessor;
11+
12+
public interface KeyPropertiesAccessor {
13+
void setCreatedOn(KeyProperties keyProperties, OffsetDateTime createdOn);
14+
15+
void setUpdatedOn(KeyProperties keyProperties, OffsetDateTime updatedOn);
16+
17+
void setRecoveryLevel(KeyProperties keyProperties, String recoveryLevel);
18+
19+
void setName(KeyProperties keyProperties, String name);
20+
21+
void setVersion(KeyProperties keyProperties, String version);
22+
23+
void setId(KeyProperties keyProperties, String id);
24+
25+
void setManaged(KeyProperties keyProperties, Boolean managed);
26+
27+
void setRecoverableDays(KeyProperties keyProperties, Integer recoverableDays);
28+
29+
void setHsmPlatform(KeyProperties keyProperties, String hsmPlatform);
30+
}
31+
32+
public static void setCreatedOn(KeyProperties keyProperties, OffsetDateTime createdOn) {
33+
accessor.setCreatedOn(keyProperties, createdOn);
34+
}
35+
36+
public static void setUpdatedOn(KeyProperties keyProperties, OffsetDateTime updatedOn) {
37+
accessor.setUpdatedOn(keyProperties, updatedOn);
38+
}
39+
40+
public static void setRecoveryLevel(KeyProperties keyProperties, String recoveryLevel) {
41+
accessor.setRecoveryLevel(keyProperties, recoveryLevel);
42+
}
43+
44+
public static void setName(KeyProperties keyProperties, String name) {
45+
accessor.setName(keyProperties, name);
46+
}
47+
48+
public static void setVersion(KeyProperties keyProperties, String version) {
49+
accessor.setVersion(keyProperties, version);
50+
}
51+
52+
public static void setId(KeyProperties keyProperties, String id) {
53+
accessor.setId(keyProperties, id);
54+
}
55+
56+
public static void setManaged(KeyProperties keyProperties, Boolean managed) {
57+
accessor.setManaged(keyProperties, managed);
58+
}
59+
60+
public static void setRecoverableDays(KeyProperties keyProperties, Integer recoverableDays) {
61+
accessor.setRecoverableDays(keyProperties, recoverableDays);
62+
}
63+
64+
public static void setHsmPlatform(KeyProperties keyProperties, String hsmPlatform) {
65+
accessor.setHsmPlatform(keyProperties, hsmPlatform);
66+
}
67+
68+
public static void setAccessor(KeyPropertiesAccessor accessor) {
69+
KeyPropertiesHelper.accessor = accessor;
70+
}
71+
72+
private KeyPropertiesHelper() {
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.v2.security.keyvault.keys.implementation;
4+
5+
import com.azure.v2.security.keyvault.keys.implementation.models.LifetimeActionsTrigger;
6+
import com.azure.v2.security.keyvault.keys.implementation.models.LifetimeActionsType;
7+
import com.azure.v2.security.keyvault.keys.models.KeyRotationLifetimeAction;
8+
import com.azure.v2.security.keyvault.keys.models.KeyRotationPolicyAction;
9+
10+
public final class KeyRotationLifetimeActionHelper {
11+
private static KeyRotationLifetimeActionAccessor accessor;
12+
13+
public interface KeyRotationLifetimeActionAccessor {
14+
KeyRotationLifetimeAction createLifetimeAction(LifetimeActionsTrigger trigger, LifetimeActionsType actionsType);
15+
16+
LifetimeActionsTrigger getTrigger(KeyRotationLifetimeAction lifetimeAction);
17+
18+
LifetimeActionsType getActionType(KeyRotationLifetimeAction lifetimeAction);
19+
}
20+
21+
public static KeyRotationLifetimeAction createLifetimeAction(LifetimeActionsTrigger trigger,
22+
LifetimeActionsType actionsType) {
23+
24+
if (accessor == null) {
25+
new KeyRotationLifetimeAction(KeyRotationPolicyAction.NOTIFY);
26+
}
27+
28+
assert accessor != null;
29+
return accessor.createLifetimeAction(trigger, actionsType);
30+
}
31+
32+
public static LifetimeActionsTrigger getTrigger(KeyRotationLifetimeAction lifetimeAction) {
33+
return accessor.getTrigger(lifetimeAction);
34+
}
35+
36+
public static LifetimeActionsType getActionType(KeyRotationLifetimeAction lifetimeAction) {
37+
return accessor.getActionType(lifetimeAction);
38+
}
39+
40+
public static void setAccessor(KeyRotationLifetimeActionAccessor accessor) {
41+
KeyRotationLifetimeActionHelper.accessor = accessor;
42+
}
43+
44+
private KeyRotationLifetimeActionHelper() {
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.v2.security.keyvault.keys.implementation;
4+
5+
import com.azure.v2.security.keyvault.keys.models.KeyRotationPolicy;
6+
7+
public final class KeyRotationPolicyHelper {
8+
private static KeyRotationPolicyAccessor accessor;
9+
10+
public interface KeyRotationPolicyAccessor {
11+
KeyRotationPolicy createPolicy(
12+
com.azure.v2.security.keyvault.keys.implementation.models.KeyRotationPolicy impl);
13+
14+
com.azure.v2.security.keyvault.keys.implementation.models.KeyRotationPolicy getImpl(KeyRotationPolicy policy);
15+
}
16+
17+
public static KeyRotationPolicy createPolicy(
18+
com.azure.v2.security.keyvault.keys.implementation.models.KeyRotationPolicy impl) {
19+
// If the class hasn't been loaded yet the accessor won't be set. Attempt to load the class before using the
20+
// accessor.
21+
if (accessor == null) {
22+
new KeyRotationPolicy();
23+
}
24+
25+
assert accessor != null;
26+
return accessor.createPolicy(impl);
27+
}
28+
29+
public static com.azure.v2.security.keyvault.keys.implementation.models.KeyRotationPolicy getImpl(
30+
KeyRotationPolicy policy) {
31+
32+
return accessor.getImpl(policy);
33+
}
34+
35+
public static void setAccessor(KeyRotationPolicyAccessor accessor) {
36+
KeyRotationPolicyHelper.accessor = accessor;
37+
}
38+
39+
private KeyRotationPolicyHelper() {
40+
}
41+
}

0 commit comments

Comments
 (0)