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

warren pushed a commit to branch feat-plugin-zentao
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit cdf63f3db8e6cdcbf2180c3df033e1c85eb5f283
Author: Yingchu Chen <[email protected]>
AuthorDate: Tue Sep 6 18:03:04 2022 +0800

    feat(zentao): create new plugin
    
    Relate to #2961
---
 plugins/zentao/api/connection.go      | 11 +++++------
 plugins/zentao/models/access_token.go | 27 +++++++++++++++++++++++++++
 plugins/zentao/tasks/api_client.go    | 13 ++++++-------
 3 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/plugins/zentao/api/connection.go b/plugins/zentao/api/connection.go
index 2f8183d5..fe702185 100644
--- a/plugins/zentao/api/connection.go
+++ b/plugins/zentao/api/connection.go
@@ -21,7 +21,6 @@ import (
        "context"
        "github.com/apache/incubator-devlake/errors"
        "github.com/apache/incubator-devlake/plugins/core"
-       "github.com/apache/incubator-devlake/plugins/feishu/apimodels"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/zentao/models"
        "github.com/mitchellh/mapstructure"
@@ -47,20 +46,20 @@ func TestConnection(input *core.ApiResourceInput) 
(*core.ApiResourceOutput, erro
        }
 
        // request for access token
-       tokenReqBody := &apimodels.ApiAccessTokenRequest{
-               AppId:     params.Username,
-               AppSecret: params.Password,
+       tokenReqBody := &models.ApiAccessTokenRequest{
+               Account:  params.Username,
+               Password: params.Password,
        }
        tokenRes, err := authApiClient.Post("/tokens", nil, tokenReqBody, nil)
        if err != nil {
                return nil, err
        }
-       tokenResBody := &apimodels.ApiAccessTokenResponse{}
+       tokenResBody := &models.ApiAccessTokenResponse{}
        err = helper.UnmarshalResponse(tokenRes, tokenResBody)
        if err != nil {
                return nil, err
        }
-       if tokenResBody.AppAccessToken == "" && tokenResBody.TenantAccessToken 
== "" {
+       if tokenResBody.Token == "" {
                return nil, errors.Default.New("failed to request access token")
        }
 
diff --git a/plugins/zentao/models/access_token.go 
b/plugins/zentao/models/access_token.go
new file mode 100644
index 00000000..60bf2617
--- /dev/null
+++ b/plugins/zentao/models/access_token.go
@@ -0,0 +1,27 @@
+/*
+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 models
+
+type ApiAccessTokenRequest struct {
+       Account  string `json:"account"`
+       Password string `json:"password"`
+}
+
+type ApiAccessTokenResponse struct {
+       Token string `json:"token"`
+}
diff --git a/plugins/zentao/tasks/api_client.go 
b/plugins/zentao/tasks/api_client.go
index 62d2d954..17d490fb 100644
--- a/plugins/zentao/tasks/api_client.go
+++ b/plugins/zentao/tasks/api_client.go
@@ -20,7 +20,6 @@ package tasks
 import (
        "fmt"
        "github.com/apache/incubator-devlake/errors"
-       "github.com/apache/incubator-devlake/plugins/feishu/apimodels"
        "net/http"
        "strconv"
        "time"
@@ -37,20 +36,20 @@ func NewZentaoApiClient(taskCtx core.TaskContext, 
connection *models.ZentaoConne
        }
 
        // request for access token
-       tokenReqBody := &apimodels.ApiAccessTokenRequest{
-               AppId:     connection.Username,
-               AppSecret: connection.Password,
+       tokenReqBody := &models.ApiAccessTokenRequest{
+               Account:  connection.Username,
+               Password: connection.Password,
        }
        tokenRes, err := authApiClient.Post("/tokens", nil, tokenReqBody, nil)
        if err != nil {
                return nil, err
        }
-       tokenResBody := &apimodels.ApiAccessTokenResponse{}
+       tokenResBody := &models.ApiAccessTokenResponse{}
        err = helper.UnmarshalResponse(tokenRes, tokenResBody)
        if err != nil {
                return nil, err
        }
-       if tokenResBody.AppAccessToken == "" && tokenResBody.TenantAccessToken 
== "" {
+       if tokenResBody.Token == "" {
                return nil, errors.Default.New("failed to request access token")
        }
        // real request apiClient
@@ -60,7 +59,7 @@ func NewZentaoApiClient(taskCtx core.TaskContext, connection 
*models.ZentaoConne
        }
        // set token
        apiClient.SetHeaders(map[string]string{
-               "Token": fmt.Sprintf("%v", tokenResBody.TenantAccessToken),
+               "Token": fmt.Sprintf("%v", tokenResBody.Token),
        })
 
        // create rate limit calculator

Reply via email to