Skip to content

Commit

Permalink
More accurate additional output parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
porunov committed Apr 18, 2017
1 parent bc74f38 commit 3c6c499
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.jblur.acme_client.command.AccountKeyNotFoundException;
import com.jblur.acme_client.manager.AuthorizationManager;
import org.shredzone.acme4j.Authorization;
import org.shredzone.acme4j.Status;
import org.shredzone.acme4j.challenge.Dns01Challenge;
import org.shredzone.acme4j.challenge.Http01Challenge;
import org.slf4j.Logger;
Expand Down Expand Up @@ -102,6 +103,9 @@ void writeChallengeByAuthorization(AuthorizationManager authorizationManagement)
switch (getChallengeType()) {
case Http01Challenge.TYPE:
Http01Challenge http01Challenge = authorizationManagement.getHttp01Challenge();
if(http01Challenge.getStatus()== Status.INVALID){
throw new ChallengeInvalidException(http01Challenge.getLocation().toString());
}
String path;
if (getParameters().isOneDirForWellKnown()) {
path = Paths.get(getParameters().getWellKnownDir(), http01Challenge.getToken()).toString();
Expand All @@ -115,6 +119,9 @@ void writeChallengeByAuthorization(AuthorizationManager authorizationManagement)
break;
case Dns01Challenge.TYPE:
Dns01Challenge dns01Challenge = authorizationManagement.getDns01Challenge();
if(dns01Challenge.getStatus()== Status.INVALID){
throw new ChallengeInvalidException(dns01Challenge.getLocation().toString());
}
IOManager.writeString(
Paths.get(getParameters().getDnsDigestDir(),
authorizationManagement.getAuthorization().getDomain() + "_dns_digest").toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jblur.acme_client.command.authorization;

public class ChallengeInvalidException extends Exception {
public ChallengeInvalidException() {

}

public ChallengeInvalidException(String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void commandExecution() {
return;
}

List<String> failedDomains = new LinkedList<>();
List<String> failedAuthorizations = new LinkedList<>();

List<Authorization> authorizationList = new LinkedList<>();

Expand All @@ -38,8 +38,8 @@ public void commandExecution() {
try {
authorization.deactivate();
} catch (AcmeException e) {
LOG.error("Cannot deactivate authorization", e);
failedDomains.add(authorization.getDomain());
LOG.error("Cannot deactivate authorization: "+authorization.getLocation().toString(), e);
failedAuthorizations.add(authorization.getLocation().toString());
error = true;
}
} else {
Expand All @@ -49,10 +49,10 @@ public void commandExecution() {

error = error || !writeAuthorizationList(authorizationList);

if (failedDomains.size() > 0) {
JsonElement failedDomainsJsonElement = getGson().toJsonTree(failedDomains, new TypeToken<List<String>>() {
if (failedAuthorizations.size() > 0) {
JsonElement failedDomainsJsonElement = getGson().toJsonTree(failedAuthorizations, new TypeToken<List<String>>() {
}.getType());
result.add("failed_domains", failedDomainsJsonElement);
result.add("failed_authorizations", failedDomainsJsonElement);
error=true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void commandExecution() {
if (!succeedDomains.contains(authorization.getDomain()))
succeedDomains.add(authorization.getDomain());
} catch (Exception e) {
LOG.error("Cannot get challenges for authorization: " + authorization.getLocation()
LOG.warn("Cannot get challenge for authorization: " + authorization.getLocation()
+ "\nDomain: " + authorization.getDomain(), e);
if (!failedDomains.contains(authorization.getDomain()))
failedDomains.add(authorization.getDomain());
Expand All @@ -53,7 +53,7 @@ public void commandExecution() {
if (failedDomains.size() > 0) {
JsonElement failedDomainsJsonElement = getGson().toJsonTree(failedDomains,
new TypeToken<HashSet<String>>() {}.getType());
result.add("failed_domains_to_download_authorizations", failedDomainsJsonElement);
result.add("failed_domains", failedDomainsJsonElement);
error=true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.1
version=2.2.0

0 comments on commit 3c6c499

Please sign in to comment.