valepakh commented on code in PR #1821:
URL: https://github.com/apache/ignite-3/pull/1821#discussion_r1145896438
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/cluster/ClusterInitCallInput.java:
##########
@@ -110,14 +132,37 @@ public ClusterInitCallInputBuilder clusterUrl(String
clusterUrl) {
* @return this builder
*/
public ClusterInitCallInputBuilder
fromClusterInitOptions(ClusterInitOptions clusterInitOptions) {
- this.metaStorageNodes = clusterInitOptions.getMetaStorageNodes();
- this.cmgNodes = clusterInitOptions.getCmgNodes();
- this.clusterName = clusterInitOptions.getClusterName();
+ this.metaStorageNodes = clusterInitOptions.metaStorageNodes();
+ this.cmgNodes = clusterInitOptions.cmgNodes();
+ this.clusterName = clusterInitOptions.clusterName();
+ this.authenticationSettings =
toAuthenticationConfig(clusterInitOptions.authenticationOptions());
return this;
}
public ClusterInitCallInput build() {
- return new ClusterInitCallInput(clusterUrl, metaStorageNodes,
cmgNodes, clusterName);
+ return new ClusterInitCallInput(clusterUrl, metaStorageNodes,
cmgNodes, clusterName, authenticationSettings);
+ }
+
+ private AuthenticationConfig
toAuthenticationConfig(AuthenticationOptions options) {
+ if (options == null) {
+ return null;
+ }
+
+ return new AuthenticationConfig(options.enabled(),
extractAuthenticationProviders(options));
+ }
+
+ private List<AuthenticationProviderConfig>
extractAuthenticationProviders(AuthenticationOptions options) {
+ return Stream.of(extractBasicAuthenticationProviderConfig(options))
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ }
+
+ private BasicAuthenticationProviderConfig
extractBasicAuthenticationProviderConfig(AuthenticationOptions options) {
+ if (!nullOrBlank(options.basicLogin()) &&
!nullOrBlank(options.basicPassword())) {
+ return new BasicAuthenticationProviderConfig("basic",
options.basicLogin(), options.basicPassword());
+ } else {
+ return null;
+ }
Review Comment:
```suggestion
private static List<AuthenticationProviderConfig>
extractAuthenticationProviders(AuthenticationOptions options) {
if (!nullOrBlank(options.basicLogin()) &&
!nullOrBlank(options.basicPassword())) {
return List.of(new
BasicAuthenticationProviderConfig("basic", options.basicLogin(),
options.basicPassword()));
} else {
return List.of();
}
}
```
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/cluster/ClusterInitCallInput.java:
##########
@@ -98,6 +113,13 @@ public static class ClusterInitCallInputBuilder {
private String clusterName;
+ private AuthenticationConfig authenticationSettings;
Review Comment:
```suggestion
private AuthenticationConfig authenticationConfig;
```
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/cluster/ClusterInitCallInput.java:
##########
@@ -110,14 +132,37 @@ public ClusterInitCallInputBuilder clusterUrl(String
clusterUrl) {
* @return this builder
*/
public ClusterInitCallInputBuilder
fromClusterInitOptions(ClusterInitOptions clusterInitOptions) {
- this.metaStorageNodes = clusterInitOptions.getMetaStorageNodes();
- this.cmgNodes = clusterInitOptions.getCmgNodes();
- this.clusterName = clusterInitOptions.getClusterName();
+ this.metaStorageNodes = clusterInitOptions.metaStorageNodes();
+ this.cmgNodes = clusterInitOptions.cmgNodes();
+ this.clusterName = clusterInitOptions.clusterName();
+ this.authenticationSettings =
toAuthenticationConfig(clusterInitOptions.authenticationOptions());
Review Comment:
```suggestion
this.authenticationConfig =
toAuthenticationConfig(clusterInitOptions.authenticationOptions());
```
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/cluster/ClusterInitCallInput.java:
##########
@@ -98,6 +113,13 @@ public static class ClusterInitCallInputBuilder {
private String clusterName;
+ private AuthenticationConfig authenticationSettings;
+
+ public ClusterInitCallInputBuilder
authenticationSettings(AuthenticationConfig authenticationConfig) {
+ this.authenticationSettings = authenticationConfig;
+ return this;
+ }
+
Review Comment:
```suggestion
```
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/exception/handler/IgniteCliApiExceptionHandler.java:
##########
@@ -69,7 +69,15 @@ public int handle(ExceptionWriter err, IgniteCliApiException
e) {
} else if (apiCause != null) {
errorComponentBuilder.header(apiCause.getMessage());
} else {
- tryToExtractProblem(errorComponentBuilder, cause);
+ if (e.getMessage().contains("Unauthorized")) {
Review Comment:
Can we check the code instead of message?
##########
modules/cli/src/test/java/org/apache/ignite/internal/cli/IgniteCliInterfaceTest.java:
##########
@@ -252,6 +252,63 @@ void initSuccess() {
assertThatStderrIsEmpty();
}
+ @Test
+ @DisplayName("init --cluster-endpoint-url http://localhost:10300
--meta-storage-node node1ConsistentId --meta-storage-node node2ConsistentId "
+ + "--cmg-node node2ConsistentId --cmg-node node3ConsistentId
--cluster-name cluster "
+ + "--authentication-enabled --basic-auth-providers
login=password")
Review Comment:
```suggestion
+ "--authentication-enabled --basic-auth-login admin
--basic-auth-password password")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]