Skip to content

Commit 4c7c7a0

Browse files
authored
Merge pull request #50900 from radcortez/config-processor-secrets
Support io.smallrye.config.Secret when processing Config
2 parents 0810c92 + 6f64881 commit 4c7c7a0

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/ResolvedType.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public record ResolvedType(
1414
boolean isMap,
1515
boolean isList,
1616
boolean isOptional,
17+
boolean isSecret,
1718
boolean isDeclared,
1819
boolean isInterface,
1920
boolean isClass,
@@ -36,14 +37,14 @@ public final String toString() {
3637

3738
public static ResolvedType ofPrimitive(TypeMirror unwrappedType, String typeName) {
3839
return new ResolvedType(unwrappedType, unwrappedType, typeName, typeName, typeName, true, false, false,
39-
false, false, false, false, false, false, false);
40+
false, false, false, false, false, false, false, false);
4041
}
4142

4243
public static ResolvedType ofDeclaredType(TypeMirror type, String binaryName,
4344
String qualifiedName, String simpleName,
4445
boolean isInterface, boolean isClass, boolean isEnum, boolean isDuration, boolean isConfigGroup) {
45-
return new ResolvedType(type, type, binaryName, qualifiedName, simpleName, false, false, false, false, true,
46-
isInterface, isClass, isEnum, isDuration, isConfigGroup);
46+
return new ResolvedType(type, type, binaryName, qualifiedName, simpleName, false, false, false, false, false,
47+
true, isInterface, isClass, isEnum, isDuration, isConfigGroup);
4748
}
4849

4950
public static ResolvedType makeList(TypeMirror type, ResolvedType unwrappedResolvedType) {
@@ -52,6 +53,7 @@ public static ResolvedType makeList(TypeMirror type, ResolvedType unwrappedResol
5253
unwrappedResolvedType.isPrimitive,
5354
unwrappedResolvedType.isMap, true,
5455
unwrappedResolvedType.isOptional,
56+
unwrappedResolvedType.isSecret,
5557
unwrappedResolvedType.isDeclared, unwrappedResolvedType.isInterface, unwrappedResolvedType.isClass,
5658
unwrappedResolvedType.isEnum, unwrappedResolvedType.isDuration, unwrappedResolvedType.isConfigGroup);
5759
}
@@ -62,6 +64,18 @@ public static ResolvedType makeOptional(ResolvedType unwrappedResolvedType) {
6264
unwrappedResolvedType.isPrimitive,
6365
unwrappedResolvedType.isMap, unwrappedResolvedType.isList,
6466
true,
67+
unwrappedResolvedType.isSecret,
68+
unwrappedResolvedType.isDeclared, unwrappedResolvedType.isInterface, unwrappedResolvedType.isClass,
69+
unwrappedResolvedType.isEnum, unwrappedResolvedType.isDuration, unwrappedResolvedType.isConfigGroup);
70+
}
71+
72+
public static ResolvedType makeSecret(ResolvedType unwrappedResolvedType) {
73+
return new ResolvedType(unwrappedResolvedType.wrapperType, unwrappedResolvedType.unwrappedType,
74+
unwrappedResolvedType.binaryName, unwrappedResolvedType.qualifiedName, unwrappedResolvedType.simplifiedName,
75+
unwrappedResolvedType.isPrimitive,
76+
unwrappedResolvedType.isMap, unwrappedResolvedType.isList,
77+
unwrappedResolvedType.isOptional,
78+
true,
6579
unwrappedResolvedType.isDeclared, unwrappedResolvedType.isInterface, unwrappedResolvedType.isClass,
6680
unwrappedResolvedType.isEnum, unwrappedResolvedType.isDuration, unwrappedResolvedType.isConfigGroup);
6781
}
@@ -72,6 +86,7 @@ public static ResolvedType makeMap(TypeMirror type, ResolvedType unwrappedResolv
7286
unwrappedResolvedType.isPrimitive,
7387
true, false,
7488
unwrappedResolvedType.isOptional,
89+
unwrappedResolvedType.isSecret,
7590
unwrappedResolvedType.isDeclared, unwrappedResolvedType.isInterface, unwrappedResolvedType.isClass,
7691
unwrappedResolvedType.isEnum, unwrappedResolvedType.isDuration, unwrappedResolvedType.isConfigGroup);
7792
}

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigProperty.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public final class ConfigProperty extends AbstractConfigItem {
1818
private final boolean map;
1919
private final boolean list;
2020
private final boolean optional;
21+
private final boolean secret;
2122
private final String mapKey;
2223
private final boolean unnamedMapKey;
2324
private final boolean withinMap;
@@ -31,7 +32,7 @@ public final class ConfigProperty extends AbstractConfigItem {
3132

3233
public ConfigProperty(ConfigPhase phase, String sourceType, String sourceElementName, SourceElementType sourceElementType,
3334
PropertyPath path, List<PropertyPath> additionalPaths, String type, String typeDescription, boolean map,
34-
boolean list, boolean optional,
35+
boolean list, boolean optional, boolean secret,
3536
String mapKey, boolean unnamedMapKey, boolean withinMap, boolean converted, @JsonProperty("enum") boolean isEnum,
3637
EnumAcceptedValues enumAcceptedValues,
3738
String defaultValue, String javadocSiteLink,
@@ -43,6 +44,7 @@ public ConfigProperty(ConfigPhase phase, String sourceType, String sourceElement
4344
this.map = map;
4445
this.list = list;
4546
this.optional = optional;
47+
this.secret = secret;
4648
this.mapKey = mapKey;
4749
this.unnamedMapKey = unnamedMapKey;
4850
this.withinMap = withinMap;
@@ -87,6 +89,10 @@ public boolean isOptional() {
8789
return optional;
8890
}
8991

92+
public boolean isSecret() {
93+
return secret;
94+
}
95+
9096
public String getMapKey() {
9197
return mapKey;
9298
}

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/resolver/ConfigResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ private void resolveProperty(ConfigRoot configRoot, Map<String, ConfigSection> e
179179

180180
String potentiallyMappedPath = path;
181181
boolean optional = discoveryConfigProperty.getType().isOptional();
182+
boolean secret = discoveryConfigProperty.getType().isSecret();
182183

183184
if (discoveryConfigProperty.getType().isMap()) {
184185
// it is a leaf pass through map, it is always optional
@@ -208,7 +209,7 @@ private void resolveProperty(ConfigRoot configRoot, Map<String, ConfigSection> e
208209
propertyPath, additionalPropertyPaths,
209210
typeQualifiedName, typeSimplifiedName,
210211
discoveryConfigProperty.getType().isMap(), discoveryConfigProperty.getType().isList(),
211-
optional, discoveryConfigProperty.getMapKey(),
212+
optional, secret, discoveryConfigProperty.getMapKey(),
212213
discoveryConfigProperty.isUnnamedMapKey(), context.isWithinMap(),
213214
discoveryConfigProperty.isConverted(),
214215
discoveryConfigProperty.getType().isEnum(),

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/ConfigAnnotationScanner.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ private ResolvedType resolveType(TypeMirror typeMirror) {
318318
String qualifiedName = typeElement.getQualifiedName().toString();
319319

320320
boolean optional = qualifiedName.startsWith(Optional.class.getName());
321+
boolean secret = qualifiedName.startsWith("io.smallrye.config.Secret");
321322
boolean map = qualifiedName.equals(Map.class.getName());
322323
boolean list = qualifiedName.equals(List.class.getName())
323324
|| qualifiedName.equals(Set.class.getName());
@@ -327,6 +328,8 @@ private ResolvedType resolveType(TypeMirror typeMirror) {
327328
// let's resolve the type
328329
if (typeArguments.size() == 1 && optional) {
329330
return ResolvedType.makeOptional(resolveType(typeArguments.get(0)));
331+
} else if (typeArguments.size() == 1 && secret) {
332+
return ResolvedType.makeSecret(resolveType(typeArguments.get(0)));
330333
} else if (typeArguments.size() == 1 && list) {
331334
return ResolvedType.makeList(typeMirror, resolveType(typeArguments.get(0)));
332335
} else if (typeArguments.size() == 2 && map) {

0 commit comments

Comments
 (0)