Skip to content

Commit

Permalink
Add method to return profile description
Browse files Browse the repository at this point in the history
  • Loading branch information
shred committed Jan 18, 2025
1 parent 43b6a7c commit 83d6f38
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions acme4j-client/src/main/java/org/shredzone/acme4j/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ public boolean isProfileAllowed(String profile) {
.isPresent();
}

/**
* Returns a description of the requested profile. This can be a human-readable string
* or a URL linking to a documentation.
* <p>
* Empty if the profile is not allowed.
*
* @since 3.5.0
*/
public Optional<String> getProfileDescription(String profile) {
return meta.get("profiles").optional()
.map(Value::asObject)
.orElseGet(JSON::empty)
.get(profile)
.optional()
.map(Value::asString);
}

/**
* Returns whether the CA supports subdomain auth according to RFC9444.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ public AcmeProvider provider() {
softly.assertThat(meta.isAutoRenewalGetAllowed()).isTrue();
softly.assertThat(meta.isProfileAllowed()).isTrue();
softly.assertThat(meta.isProfileAllowed("classic")).isTrue();
softly.assertThat(meta.isProfileAllowed("custom")).isTrue();
softly.assertThat(meta.isProfileAllowed("invalid")).isFalse();
softly.assertThat(meta.getProfileDescription("classic")).contains("The profile you're accustomed to");
softly.assertThat(meta.getProfileDescription("custom")).contains("Some other profile");
softly.assertThat(meta.getProfileDescription("invalid")).isEmpty();
softly.assertThat(meta.isExternalAccountRequired()).isTrue();
softly.assertThat(meta.isSubdomainAuthAllowed()).isTrue();
softly.assertThat(meta.getJSON()).isNotNull();
Expand Down Expand Up @@ -240,6 +244,7 @@ public AcmeProvider provider() {
.isThrownBy(meta::isAutoRenewalGetAllowed);
softly.assertThat(meta.isProfileAllowed()).isFalse();
softly.assertThat(meta.isProfileAllowed("classic")).isFalse();
softly.assertThat(meta.getProfileDescription("classic")).isEmpty();
}
}

Expand Down

0 comments on commit 83d6f38

Please sign in to comment.