klesh opened a new pull request, #4260:
URL: https://github.com/apache/incubator-devlake/pull/4260

   ### Summary
   This PR is a more robust/reasonable/elegant/comprehensive solution for 
#4027, #4212.
   
   The Mechanism offers the following aid for connections that require Single 
or Multiple Authorizations
   
   ** For Connections Support Single Authorization Method **, define the 
connection to look like:
   
   ```golang
   // GitlabConn holds the essential information to connect to the Gitlab API
   type GitlabConn struct {
        helper.RestConnection `mapstructure:",squash"`
        helper.AccessToken    `mapstructure:",squash"`
   }
   
   // This object conforms to what the frontend currently sends.
   // GitlabConnection holds GitlabConn plus ID/Name for database storage
   type GitlabConnection struct {
        helper.BaseConnection `mapstructure:",squash"`
        GitlabConn            `mapstructure:",squash"`
   }
   ```
   
   ** For Connections Support Multiple Authorization Methods **, define the 
connection to look like:
   ```golang
   // JiraConn holds the essential information to connect to the Jira API
   type JiraConn struct {
        helper.RestConnection `mapstructure:",squash"`
        helper.MultiAuth      `mapstructure:",squash"`
        helper.BasicAuth      `mapstructure:",squash"`
        helper.AccessToken    `mapstructure:",squash"`
   }
   
   // SetupAuthentication implements the `IAuthentication` interface by 
delegating
   // the actual logic to the `MultiAuth` struct to help us write less code
   func (jc JiraConn) SetupAuthentication(req *http.Request) errors.Error {
        return jc.MultiAuth.SetupAuthenticationForConnection(&jc, req)
   }
   
   // JiraConnection holds JiraConn plus ID/Name for database storage
   type JiraConnection struct {
        helper.BaseConnection `mapstructure:",squash"`
        JiraConn              `mapstructure:",squash"`
   }
   ```
   
   ** Test Connection implementation for both parties be like **:
   ```golang
        // decode
        var err errors.Error
        var connection models.GitlabConn
        if err = api.Decode(input.Body, &connection, vld); err != nil {
                return nil, err
        }
        // test connection
        apiClient, err := api.NewApiClientFromConnection(context.TODO(), 
basicRes, connection)
        if err != nil {
                return nil, errors.Convert(err)
        }
   
   // TEST the connection with apiClient
   ```
   
   
   ### Does this close any open issues?
   Closes #4027 
   Closes #4212 
   


-- 
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: commits-unsubscr...@devlake.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to