mirror of https://github.com/shred/acme4j
Return certificate on getAutoRenewalCertificate
Similar to getCertificate(), getAutoRenewalCertificate() would only return an empty optional if the order state is not valid. To keep the API simple, getAutoRenewalCertificate() now always returns a non-null certificate, and throws an exception otherwise.pull/140/head
parent
c26d6b1f8a
commit
c08c85b95c
|
@ -45,6 +45,7 @@ public class Order extends AcmeJsonResource {
|
|||
* <p>
|
||||
* Possible values are: {@link Status#PENDING}, {@link Status#READY},
|
||||
* {@link Status#PROCESSING}, {@link Status#VALID}, {@link Status#INVALID}.
|
||||
* If the server supports STAR, another possible value is {@link Status#CANCELED}.
|
||||
*/
|
||||
public Status getStatus() {
|
||||
return getJSON().get("status").asStatus();
|
||||
|
@ -132,11 +133,17 @@ public class Order extends AcmeJsonResource {
|
|||
* Gets the STAR extension's {@link Certificate} if it is available.
|
||||
*
|
||||
* @since 2.6
|
||||
* @throws IllegalStateException
|
||||
* if the order is not ready yet. You must finalize the order first, and wait
|
||||
* for the status to become {@link Status#VALID}. It is also thrown if the
|
||||
* order has been {@link Status#CANCELED}.
|
||||
*/
|
||||
public Optional<Certificate> getAutoRenewalCertificate() {
|
||||
public Certificate getAutoRenewalCertificate() {
|
||||
return getJSON().get("star-certificate")
|
||||
.optional()
|
||||
.map(Value::asURL)
|
||||
.map(getLogin()::bindCertificate);
|
||||
.map(getLogin()::bindCertificate)
|
||||
.orElseThrow(() -> new IllegalStateException("Order is in an invalid state"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -218,7 +218,8 @@ public class OrderTest {
|
|||
.isEqualTo("2016-01-08T00:00:00Z");
|
||||
softly.assertThat(order.getCertificate().getLocation())
|
||||
.isEqualTo(url("https://example.com/acme/cert/1234"));
|
||||
softly.assertThat(order.getAutoRenewalCertificate()).isEmpty();
|
||||
softly.assertThatIllegalStateException()
|
||||
.isThrownBy(order::getAutoRenewalCertificate);
|
||||
softly.assertThat(order.getFinalizeLocation()).isEqualTo(finalizeUrl);
|
||||
|
||||
var auths = order.getAuthorizations();
|
||||
|
@ -310,7 +311,7 @@ public class OrderTest {
|
|||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
softly.assertThatIllegalStateException()
|
||||
.isThrownBy(order::getCertificate);
|
||||
softly.assertThat(order.getAutoRenewalCertificate().orElseThrow().getLocation())
|
||||
softly.assertThat(order.getAutoRenewalCertificate().getLocation())
|
||||
.isEqualTo(url("https://example.com/acme/cert/1234"));
|
||||
softly.assertThat(order.isAutoRenewing()).isTrue();
|
||||
softly.assertThat(order.getAutoRenewalStartDate().orElseThrow())
|
||||
|
|
Loading…
Reference in New Issue