24
24
import java .util .Optional ;
25
25
import java .util .Set ;
26
26
import java .util .stream .Collectors ;
27
+ import java .util .stream .Stream ;
27
28
import javax .annotation .Nullable ;
28
29
import org .apache .commons .lang3 .StringUtils ;
29
30
@@ -38,16 +39,28 @@ public enum OfficialSonarQubeCloudInstance {
38
39
this .endpoint = new ScannerEndpoint (webEndpoint , apiEndpoint , true );
39
40
}
40
41
41
- public static Set <String > getRegionCodes () {
42
- return Arrays .stream (OfficialSonarQubeCloudInstance .values ()).filter (r -> r != GLOBAL ).map (Enum ::name ).map (s -> s .toLowerCase (Locale .ENGLISH )).collect (Collectors .toSet ());
42
+ public static Set <String > getRegionCodesWithoutGlobal () {
43
+ return getRegionsWithoutGlobal ().map (Enum ::name ).map (s -> s .toLowerCase (Locale .ENGLISH )).collect (Collectors .toSet ());
44
+ }
45
+
46
+ /**
47
+ * For now, we are not sure the default region will be called "global" so don't let users use this enum value
48
+ */
49
+ private static Stream <OfficialSonarQubeCloudInstance > getRegionsWithoutGlobal () {
50
+ return Arrays .stream (OfficialSonarQubeCloudInstance .values ()).filter (r -> r != GLOBAL );
43
51
}
44
52
45
53
public static Optional <OfficialSonarQubeCloudInstance > fromRegionCode (@ Nullable String regionCode ) {
46
54
if (StringUtils .isBlank (regionCode )) {
47
55
return Optional .of (GLOBAL );
48
56
}
49
57
try {
50
- return Optional .of (OfficialSonarQubeCloudInstance .valueOf (regionCode .toUpperCase (Locale .ENGLISH )));
58
+ var value = OfficialSonarQubeCloudInstance .valueOf (regionCode .toUpperCase (Locale .ENGLISH ));
59
+ if (value == GLOBAL ) {
60
+ // For now, we are not sure the default region will be called "global" so don't let users use this enum value
61
+ return Optional .empty ();
62
+ }
63
+ return Optional .of (value );
51
64
} catch (IllegalArgumentException e ) {
52
65
return Optional .empty ();
53
66
}
0 commit comments