This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 8beeafa6e [INLONG-5739][Manager] Add anno API in the manager client 
(#5740)
8beeafa6e is described below

commit 8beeafa6ebf39ddf54273fc62b8c009c9063cfab
Author: haifxu <[email protected]>
AuthorDate: Wed Aug 31 14:28:15 2022 +0800

    [INLONG-5739][Manager] Add anno API in the manager client (#5740)
---
 .../apache/inlong/manager/client/api/NoAuth.java   | 34 ++++++++++++
 .../inlong/manager/client/api/impl/NoAuthImpl.java | 49 +++++++++++++++++
 .../client/api/inner/client/ClientFactory.java     |  3 ++
 .../client/api/inner/client/NoAuthClient.java      | 54 +++++++++++++++++++
 .../manager/client/api/service/NoAuthApi.java      | 33 ++++++++++++
 .../manager/client/api/inner/NoAuthClientTest.java | 61 ++++++++++++++++++++++
 6 files changed, 234 insertions(+)

diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/NoAuth.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/NoAuth.java
new file mode 100644
index 000000000..2181f8ab6
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/NoAuth.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api;
+
+import org.apache.inlong.manager.pojo.user.UserRequest;
+
+/**
+ * No auth interface, such as user login, register, etc.
+ */
+public interface NoAuth {
+
+    /**
+     * Save user info
+     *
+     * @param request user info request
+     * @return user id after saving
+     */
+    Integer register(UserRequest request);
+}
diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/NoAuthImpl.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/NoAuthImpl.java
new file mode 100644
index 000000000..6e7dcf8e4
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/NoAuthImpl.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.impl;
+
+import org.apache.inlong.manager.client.api.NoAuth;
+import org.apache.inlong.manager.client.api.ClientConfiguration;
+import org.apache.inlong.manager.client.api.inner.client.NoAuthClient;
+import org.apache.inlong.manager.client.api.inner.client.ClientFactory;
+import org.apache.inlong.manager.client.api.util.ClientUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
+import org.apache.inlong.manager.pojo.user.UserRequest;
+
+/**
+ * No auth interface implementation
+ */
+public class NoAuthImpl implements NoAuth {
+
+    private final NoAuthClient noAuthClient;
+
+    public NoAuthImpl(ClientConfiguration configuration) {
+        ClientFactory clientFactory = 
ClientUtils.getClientFactory(configuration);
+        this.noAuthClient = clientFactory.getNoAuthClient();
+    }
+
+    @Override
+    public Integer register(UserRequest request) {
+        Preconditions.checkNotEmpty(request.getName(), "username cannot be 
empty");
+        Preconditions.checkNotEmpty(request.getPassword(), "password cannot be 
empty");
+        Preconditions.checkNotNull(request.getAccountType(), "accountType 
cannot be null");
+        Preconditions.checkNotNull(request.getValidDays(), "validDays cannot 
be null");
+
+        return noAuthClient.register(request);
+    }
+}
diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
index 47a5901ae..c82e3618b 100644
--- 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
@@ -44,6 +44,8 @@ public class ClientFactory {
 
     private final UserClient userClient;
 
+    private final NoAuthClient noAuthClient;
+
     private final WorkflowApproverClient workflowApproverClient;
 
     public ClientFactory(ClientConfiguration configuration) {
@@ -56,6 +58,7 @@ public class ClientFactory {
         workflowClient = new WorkflowClient(configuration);
         dataNodeClient = new DataNodeClient(configuration);
         userClient = new UserClient(configuration);
+        noAuthClient = new NoAuthClient(configuration);
         workflowApproverClient = new WorkflowApproverClient(configuration);
     }
 }
diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/NoAuthClient.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/NoAuthClient.java
new file mode 100644
index 000000000..c427ff9dd
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/NoAuthClient.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.inner.client;
+
+import org.apache.inlong.manager.client.api.ClientConfiguration;
+import org.apache.inlong.manager.client.api.service.NoAuthApi;
+import org.apache.inlong.manager.client.api.util.ClientUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.user.UserRequest;
+
+/**
+ * Client for {@link NoAuthApi}.
+ */
+public class NoAuthClient {
+
+    private final NoAuthApi noAuthApi;
+
+    public NoAuthClient(ClientConfiguration configuration) {
+        noAuthApi = 
ClientUtils.createRetrofit(configuration).create(NoAuthApi.class);
+    }
+
+    /**
+     * Save user info
+     *
+     * @param request user info request
+     * @return user id after saving
+     */
+    public Integer register(UserRequest request) {
+        Preconditions.checkNotEmpty(request.getName(), "username cannot be 
empty");
+        Preconditions.checkNotEmpty(request.getPassword(), "password cannot be 
empty");
+        Preconditions.checkNotNull(request.getAccountType(), "accountType 
cannot be null");
+        Preconditions.checkNotNull(request.getValidDays(), "validDays cannot 
be null");
+
+        Response<Integer> response = 
ClientUtils.executeHttpCall(noAuthApi.register(request));
+        ClientUtils.assertRespSuccess(response);
+        return response.getData();
+    }
+}
diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/NoAuthApi.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/NoAuthApi.java
new file mode 100644
index 000000000..e66af42bc
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/NoAuthApi.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.service;
+
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.user.UserRequest;
+import retrofit2.Call;
+import retrofit2.http.Body;
+import retrofit2.http.POST;
+
+/**
+ * API for AnnoController in manager-web
+ */
+public interface NoAuthApi {
+
+    @POST("anno/register")
+    Call<Response<Integer>> register(@Body UserRequest request);
+}
diff --git 
a/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/NoAuthClientTest.java
 
b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/NoAuthClientTest.java
new file mode 100644
index 000000000..eb2332ab3
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/NoAuthClientTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.inner;
+
+import org.apache.inlong.manager.client.api.inner.client.NoAuthClient;
+import org.apache.inlong.manager.common.enums.UserTypeEnum;
+import org.apache.inlong.manager.common.util.JsonUtils;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.user.UserRequest;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+
+/**
+ * Tests for {@link NoAuthClient}
+ */
+public class NoAuthClientTest extends ClientFactoryTest {
+
+    private static final NoAuthClient NO_AUTH_CLIENT = 
clientFactory.getNoAuthClient();
+
+    @Test
+    void testRegister() {
+        stubFor(
+                post(urlMatching("/inlong/manager/api/anno/register.*"))
+                        .willReturn(
+                                okJson(JsonUtils.toJsonString(
+                                        Response.success(1))
+                                )
+                        )
+        );
+
+        UserRequest request = UserRequest.builder()
+                .name("username")
+                .password("pwd")
+                .accountType(UserTypeEnum.ADMIN.getCode())
+                .validDays(9999)
+                .build();
+
+        Integer userId = NO_AUTH_CLIENT.register(request);
+        Assertions.assertEquals(1, userId);
+    }
+}

Reply via email to