From 33ea673c03949c49e01d4921b37ad79fae6372c1 Mon Sep 17 00:00:00 2001 From: Ruslan Sennov Date: Wed, 18 Dec 2024 08:17:19 +0300 Subject: [PATCH] remove deprecated API --- .../java/io/vertx/ext/consul/AclToken.java | 171 ------------------ src/main/java/io/vertx/ext/consul/Check.java | 29 --- .../io/vertx/ext/consul/ConsulClient.java | 73 +------- .../ext/consul/impl/ConsulClientImpl.java | 60 ++---- .../io/vertx/ext/consul/token/AclToken.java | 1 + .../io/vertx/ext/consul/tests/CopyTest.java | 15 +- .../vertx/ext/consul/tests/RandomObjects.java | 23 ++- 7 files changed, 38 insertions(+), 334 deletions(-) delete mode 100644 src/main/java/io/vertx/ext/consul/AclToken.java diff --git a/src/main/java/io/vertx/ext/consul/AclToken.java b/src/main/java/io/vertx/ext/consul/AclToken.java deleted file mode 100644 index 54402c44..00000000 --- a/src/main/java/io/vertx/ext/consul/AclToken.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2016 The original author or authors - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.ext.consul; - -import io.vertx.codegen.annotations.DataObject; -import io.vertx.core.json.JsonObject; - -/** - * Holds properties of Acl token - * - * @author Ruslan Sennov - */ -@DataObject -@Deprecated -public class AclToken { - - private static final String ID_KEY = "ID"; - private static final String NAME_KEY = "Name"; - private static final String TYPE_KEY = "Type"; - private static final String RULES_KEY = "Rules"; - - private String id; - private String name; - private AclTokenType type; - private String rules; - - /** - * Default constructor - */ - public AclToken() { - } - - /** - * Copy constructor - * - * @param token the one to copy - */ - public AclToken(AclToken token) { - this.id = token.id; - this.name = token.name; - this.type = token.type; - this.rules = token.rules; - } - - /** - * Constructor from JSON - * - * @param token the JSON - */ - public AclToken(JsonObject token) { - this.id = token.getString(ID_KEY); - this.name = token.getString(NAME_KEY); - this.type = AclTokenType.of(token.getString(TYPE_KEY)); - this.rules = token.getString(RULES_KEY); - } - - /** - * Convert to JSON - * - * @return the JSON - */ - public JsonObject toJson() { - JsonObject jsonObject = new JsonObject(); - if (id != null) { - jsonObject.put(ID_KEY, id); - } - if (name != null) { - jsonObject.put(NAME_KEY, name); - } - if (type != null) { - jsonObject.put(TYPE_KEY, type.key); - } - if (rules != null) { - jsonObject.put(RULES_KEY, rules); - } - return jsonObject; - } - - /** - * Get ID of token - * - * @return ID of token - */ - public String getId() { - return id; - } - - /** - * Set ID of token - * - * @param id ID of token - * @return reference to this, for fluency - */ - public AclToken setId(String id) { - this.id = id; - return this; - } - - /** - * Get name of token - * - * @return name of token - */ - public String getName() { - return name; - } - - /** - * Set name of token - * - * @param name name of token - * @return reference to this, for fluency - */ - public AclToken setName(String name) { - this.name = name; - return this; - } - - /** - * Get type of token - * - * @return type of token - */ - public AclTokenType getType() { - return type; - } - - /** - * Set type of token - * - * @param type type of token - * @return reference to this, for fluency - */ - public AclToken setType(AclTokenType type) { - this.type = type; - return this; - } - - /** - * Get rules for token - * - * @return rules for token - */ - public String getRules() { - return rules; - } - - /** - * Set rules for token - * - * @param rules rules for token - * @return reference to this, for fluency - */ - public AclToken setRules(String rules) { - this.rules = rules; - return this; - } -} diff --git a/src/main/java/io/vertx/ext/consul/Check.java b/src/main/java/io/vertx/ext/consul/Check.java index 809afd36..63ed4438 100644 --- a/src/main/java/io/vertx/ext/consul/Check.java +++ b/src/main/java/io/vertx/ext/consul/Check.java @@ -36,8 +36,6 @@ public class Check { private String serviceId; private String serviceName; private String node; - @Deprecated - private String nodeName; /** * Default constructor @@ -58,7 +56,6 @@ public Check(Check other) { this.output = other.output; this.serviceId = other.serviceId; this.serviceName = other.serviceName; - this.nodeName = other.nodeName; this.node = other.node; } @@ -100,17 +97,6 @@ public String getName() { return name; } - /** - * Get the name of node. - * Deprecated since consul 1.11, renamed to 'node'. Use {@link #getNode()} instead - * - * @return name of node - */ - @Deprecated - public String getNodeName() { - return nodeName; - } - /** * Get the name of node * @@ -242,19 +228,6 @@ public Check setServiceName(String serviceName) { return this; } - /** - * Set the name of node - * Deprecated since consul 1.11, renamed to 'node'. Use {@link #setNode(String)} ()} instead - * - * @param nodeName the name of node - * @return reference to this, for fluency - */ - @Deprecated - public Check setNodeName(String nodeName) { - this.nodeName = nodeName; - return this; - } - /** * Set the name of node * @@ -280,7 +253,6 @@ public boolean equals(Object o) { if (output != null ? !output.equals(check.output) : check.output != null) return false; if (serviceId != null ? !serviceId.equals(check.serviceId) : check.serviceId != null) return false; if (serviceName != null ? !serviceName.equals(check.serviceName) : check.serviceName != null) return false; - if (nodeName != null ? !nodeName.equals(check.nodeName) : check.nodeName != null) return false; return node != null ? node.equals(check.node) : check.node == null; } @@ -293,7 +265,6 @@ public int hashCode() { result = 31 * result + (output != null ? output.hashCode() : 0); result = 31 * result + (serviceId != null ? serviceId.hashCode() : 0); result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0); - result = 31 * result + (nodeName != null ? nodeName.hashCode() : 0); result = 31 * result + (node != null ? node.hashCode() : 0); return result; } diff --git a/src/main/java/io/vertx/ext/consul/ConsulClient.java b/src/main/java/io/vertx/ext/consul/ConsulClient.java index bf87d683..acce91e8 100644 --- a/src/main/java/io/vertx/ext/consul/ConsulClient.java +++ b/src/main/java/io/vertx/ext/consul/ConsulClient.java @@ -21,6 +21,7 @@ import io.vertx.core.json.JsonObject; import io.vertx.ext.consul.impl.ConsulClientImpl; import io.vertx.ext.consul.policy.AclPolicy; +import io.vertx.ext.consul.token.AclToken; import io.vertx.ext.consul.token.CloneAclTokenOptions; import java.util.List; @@ -228,7 +229,7 @@ static ConsulClient create(Vertx vertx, ConsulClientOptions options) { /** * This endpoint updates an existing ACL policy * - * @param id uuid of existing policy + * @param id uuid of existing policy * @param policy options that will be applied to the existing policy * @return a future of AclPolicy * @see PUT /acl/policy/:id @@ -262,7 +263,7 @@ static ConsulClient create(Vertx vertx, ConsulClientOptions options) { * {@link AclToken} secretId - using in {@link ConsulClientOptions#setAclToken(String)}. * @see /v1/acl/create endpoint */ - Future createAclToken(io.vertx.ext.consul.token.AclToken token); + Future createAclToken(AclToken token); /** * Update an existing Acl token @@ -277,7 +278,7 @@ static ConsulClient create(Vertx vertx, ConsulClientOptions options) { /** * Clones an existing ACL token * - * @param accessorId uuid of the token + * @param accessorId uuid of the token * @param cloneAclTokenOptions properties of cloned token * @return a future NewAclToken like in {@link #createAclToken(io.vertx.ext.consul.token.AclToken)} * @see /acl/token/:accessorId/clone endpoint @@ -303,76 +304,12 @@ static ConsulClient create(Vertx vertx, ConsulClientOptions options) { /** * Deletes an ACL token + * * @param accessorId uuid of token * @return a future boolean value: true or false, indicating whether the deletion was successful. */ Future deleteAclToken(String accessorId); - /** - * Legacy create new Acl token - * - * @param token properties of the token - * @return a future provided with ID of created token - * @see /v1/acl/create endpoint - * @deprecated Use {@link #createAclToken(io.vertx.ext.consul.token.AclToken)} instead - */ - @Deprecated - Future createAclToken(AclToken token); - - /** - * Update Acl token - * - * @param token properties of the token to be updated - * @return a future provided with ID of updated - * @see /v1/acl/update endpoint - * @deprecated Use {@link #updateAclToken(String, io.vertx.ext.consul.token.AclToken)} instead - */ - @Deprecated - Future updateAclToken(AclToken token); - - /** - * Clone Acl token - * - * @param id the ID of token to be cloned - * @return a future provided with ID of cloned token - * @see /v1/acl/clone/:uuid endpoint - * @deprecated Use {@link #cloneAclToken(String, CloneAclTokenOptions)} instead - */ - @Deprecated - Future cloneAclToken(String id); - - /** - * Get list of Acl token - * - * @return a future provided with list of tokens - * @see /v1/acl/list endpoint - * @deprecated Use {@link #getAclTokens()} instead - */ - @Deprecated - Future> listAclTokens(); - - /** - * Get info of Acl token - * - * @param id the ID of token - * @return a future provided with token - * @see /v1/acl/info/:uuid endpoint - * @deprecated Use {@link #readAclToken(String)} instead - */ - @Deprecated - Future infoAclToken(String id); - - /** - * Destroy Acl token - * - * @param id the ID of token - * @return a future notified on complete - * @see /v1/acl/destroy/:uuid endpoint - * @deprecated Use {@link #deleteAclToken(String)} instead - */ - @Deprecated - Future destroyAclToken(String id); - /** * Fires a new user event * diff --git a/src/main/java/io/vertx/ext/consul/impl/ConsulClientImpl.java b/src/main/java/io/vertx/ext/consul/impl/ConsulClientImpl.java index 77e3f90c..094c119c 100644 --- a/src/main/java/io/vertx/ext/consul/impl/ConsulClientImpl.java +++ b/src/main/java/io/vertx/ext/consul/impl/ConsulClientImpl.java @@ -26,6 +26,7 @@ import io.vertx.core.json.JsonObject; import io.vertx.ext.consul.*; import io.vertx.ext.consul.policy.AclPolicy; +import io.vertx.ext.consul.token.AclToken; import io.vertx.ext.consul.token.CloneAclTokenOptions; import io.vertx.ext.web.client.HttpRequest; import io.vertx.ext.web.client.HttpResponse; @@ -226,39 +227,39 @@ public Future> getAclPolicies() { ); } - public Future createAclToken(io.vertx.ext.consul.token.AclToken token) { + public Future createAclToken(AclToken token) { return requestObject(HttpMethod.PUT, "/v1/acl/token", null, token.toJson().encode(), (obj, headers) -> - new io.vertx.ext.consul.token.AclToken(obj) + new AclToken(obj) ); } @Override - public Future updateAclToken(String accessorId, io.vertx.ext.consul.token.AclToken token) { + public Future updateAclToken(String accessorId, AclToken token) { return requestObject(HttpMethod.PUT, "/v1/acl/token/" + urlEncode(accessorId), null, token.toJson().encode(), - (obj, headers) -> new io.vertx.ext.consul.token.AclToken(obj) + (obj, headers) -> new AclToken(obj) ); } @Override - public Future cloneAclToken(String accessorId, CloneAclTokenOptions cloneAclTokenOptions) { + public Future cloneAclToken(String accessorId, CloneAclTokenOptions cloneAclTokenOptions) { return requestObject(HttpMethod.PUT, "/v1/acl/token/" + urlEncode(accessorId) + "/clone", null, cloneAclTokenOptions.toJson().encode(), - (obj, headers) -> new io.vertx.ext.consul.token.AclToken(obj) + (obj, headers) -> new AclToken(obj) ); } @Override - public Future> getAclTokens() { + public Future> getAclTokens() { return requestArray(HttpMethod.GET, "/v1/acl/tokens", null, null, (arr, headers) -> arr.stream() - .map(obj -> new io.vertx.ext.consul.token.AclToken((JsonObject) obj)) + .map(obj -> new AclToken((JsonObject) obj)) .collect(Collectors.toList())); } @Override - public Future readAclToken(String accessorId) { + public Future readAclToken(String accessorId) { return requestObject(HttpMethod.GET, "/v1/acl/token/" + urlEncode(accessorId), null, null, - (obj, headers) -> new io.vertx.ext.consul.token.AclToken(obj) + (obj, headers) -> new AclToken(obj) ); } @@ -269,45 +270,6 @@ public Future deleteAclToken(String accessorId) { ); } - @Override - public Future createAclToken(AclToken token) { - return requestObject(HttpMethod.PUT, "/v1/acl/create", null, token.toJson().encode(), (obj, headers) -> - obj.getString("ID")); - } - - @Override - public Future updateAclToken(AclToken token) { - return requestObject(HttpMethod.PUT, "/v1/acl/update", null, token.toJson().encode(), (obj, headers) -> - obj.getString("ID")); - } - - @Override - public Future cloneAclToken(String id) { - return requestObject(HttpMethod.PUT, "/v1/acl/clone/" + urlEncode(id), null, null, (obj, headers) -> - obj.getString("ID")); - } - - @Override - public Future> listAclTokens() { - return requestArray(HttpMethod.GET, "/v1/acl/list", null, null, (arr, headers) -> - arr.stream() - .map(obj -> new AclToken((JsonObject) obj)) - .collect(Collectors.toList())); - } - - @Override - public Future infoAclToken(String id) { - return requestArray(HttpMethod.GET, "/v1/acl/info/" + urlEncode(id), null, null, (arr, headers) -> { - JsonObject jsonObject = arr.getJsonObject(0); - return new AclToken(jsonObject); - }); - } - - @Override - public Future destroyAclToken(String id) { - return requestVoid(HttpMethod.PUT, "/v1/acl/destroy/" + urlEncode(id), null, null); - } - @Override public Future fireEvent(String name) { return fireEventWithOptions(name, null); diff --git a/src/main/java/io/vertx/ext/consul/token/AclToken.java b/src/main/java/io/vertx/ext/consul/token/AclToken.java index 8bfee7b1..2109b39a 100644 --- a/src/main/java/io/vertx/ext/consul/token/AclToken.java +++ b/src/main/java/io/vertx/ext/consul/token/AclToken.java @@ -68,6 +68,7 @@ public AclToken() { } public AclToken(JsonObject json) { + this.description = json.getString(DESCRIPTION_KEY); this.accessorId = json.getString(ACCESSOR_ID_KEY); this.secretId = json.getString(SECRET_ID_KEY); this.policies = new ArrayList<>(); diff --git a/src/test/java/io/vertx/ext/consul/tests/CopyTest.java b/src/test/java/io/vertx/ext/consul/tests/CopyTest.java index 4183a647..e26a94c7 100644 --- a/src/test/java/io/vertx/ext/consul/tests/CopyTest.java +++ b/src/test/java/io/vertx/ext/consul/tests/CopyTest.java @@ -15,7 +15,9 @@ */ package io.vertx.ext.consul.tests; +import io.vertx.core.json.JsonObject; import io.vertx.ext.consul.*; +import io.vertx.ext.consul.token.AclToken; import org.junit.Test; import java.util.ArrayList; @@ -34,16 +36,8 @@ public class CopyTest { @Test public void testAclToken() { - AclToken token = randomAclToken(); - checkAclToken(token, new AclToken(token)); - checkAclToken(token, new AclToken(token.toJson())); - } - - private void checkAclToken(AclToken expected, AclToken actual) { - assertEquals(expected.getId(), actual.getId()); - assertEquals(expected.getName(), actual.getName()); - assertEquals(expected.getType(), actual.getType()); - assertEquals(expected.getRules(), actual.getRules()); + JsonObject token = randomAclToken(); + assertEquals(token, new AclToken(token).toJson()); } @Test @@ -209,7 +203,6 @@ private void checkCheck(Check expected, Check actual) { assertEquals(expected.hashCode(), actual.hashCode()); assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getName(), actual.getName()); - assertEquals(expected.getNodeName(), actual.getNodeName()); assertEquals(expected.getNotes(), actual.getNotes()); assertEquals(expected.getOutput(), actual.getOutput()); assertEquals(expected.getServiceId(), actual.getServiceId()); diff --git a/src/test/java/io/vertx/ext/consul/tests/RandomObjects.java b/src/test/java/io/vertx/ext/consul/tests/RandomObjects.java index 92cc1a26..cf7cfea0 100644 --- a/src/test/java/io/vertx/ext/consul/tests/RandomObjects.java +++ b/src/test/java/io/vertx/ext/consul/tests/RandomObjects.java @@ -15,7 +15,12 @@ */ package io.vertx.ext.consul.tests; +import io.vertx.core.json.JsonObject; import io.vertx.ext.consul.*; +import io.vertx.ext.consul.token.AclToken; +import io.vertx.ext.consul.token.NodeTokenApplyingOptions; +import io.vertx.ext.consul.token.PolicyLink; +import io.vertx.ext.consul.token.ServiceTokenApplyingOptions; import io.vertx.test.core.TestUtils; import java.util.*; @@ -28,12 +33,19 @@ */ public class RandomObjects { - public static AclToken randomAclToken() { + public static JsonObject randomAclToken() { return new AclToken() - .setId(randomAlphaString(10)) - .setName(randomAlphaString(10)) - .setType(randomElement(AclTokenType.values())) - .setRules(randomAlphaString(10)); + .local() + .setDescription(randomAlphaString(10)) + .setPolicies(Collections.singletonList( + new PolicyLink().setId(randomAlphaString(10)).setName(randomAlphaString(10)))) + .setServiceIdentities(Collections.singletonList( + new ServiceTokenApplyingOptions(new JsonObject().put("ServiceName", randomAlphaString(10))))) + .setNodeIdentities(Collections.singletonList( + new NodeTokenApplyingOptions(new JsonObject().put("NodeName", randomAlphaString(10))))) + .setNamespace(randomAlphaString(10)) + .setExpirationTime(randomAlphaString(10)) + .toJson(); // TODO } public static KeyValue randomKeyValue() { @@ -62,7 +74,6 @@ public static Check randomCheck() { return new Check() .setId(randomAlphaString(10)) .setName(randomAlphaString(10)) - .setNodeName(randomAlphaString(10)) .setNotes(randomAlphaString(100)) .setOutput(randomAlphaString(100)) .setServiceId(randomAlphaString(10))