Remove all references to Trello
continuous-integration/drone/pr Build is failing Details

Allow insecure connections.
This commit is contained in:
Giacomo Rossetto 2023-09-28 17:58:42 +02:00
parent ea72978dd2
commit dd0cc8ec47
2 changed files with 66 additions and 16 deletions

View File

@ -145,6 +145,7 @@ const (
MigrationKanboardEnable Key = `migration.kanboard.enable`
MigrationKanboardApiToken Key = `migration.kanboard.token`
MigrationKanboardApiEndpoint Key = `migration.kanboard.endpoint`
MigrationKanboardApiInsecure Key = `migration.kanboard.insecure`
CorsEnable Key = `cors.enable`
CorsOrigins Key = `cors.origins`

View File

@ -17,6 +17,10 @@
package kanboard
import (
"crypto/tls"
"encoding/base64"
"net/http"
"github.com/ybbus/jsonrpc/v2"
"code.vikunja.io/api/pkg/config"
@ -26,18 +30,34 @@ import (
"code.vikunja.io/api/pkg/user"
)
// Migration represents the trello migration struct
// Migration represents the kanboard migration struct
type Migration struct {
Token string `json:"code"`
}
type kanboardBoard struct {
ID string `json:"id"`
Name string `json:"name"`
IsActive string `json:"is_active"`
Token string `json:"token"`
LastModified string `json:"last_modified"`
IsPublic string `json:"is_public"`
IsPrivate string `json:"is_private"`
DefaultSwimlane string `json:"default_swimlane"`
ShowDefaultSwimlane string `json:"show_default_swimlane"`
Description interface{} `json:"description"`
Identifier string `json:"identifier"`
URL struct {
Board string `json:"board"`
Calendar string `json:"calendar"`
List string `json:"list"`
} `json:"url"`
}
func init() {
}
// Name is used to get the name of the trello migration - we're using the docs here to annotate the status route.
// Name is used to get the name of the kanboard migration - we're using the docs here to annotate the status route.
// @Summary Get migration status
// @Description Returns if the current user already did the migation or not. This is useful to show a confirmation message in the frontend if the user is trying to do the same migration again.
// @tags migration
@ -45,35 +65,60 @@ func init() {
// @Security JWTKeyAuth
// @Success 200 {object} migration.Status "The migration status"
// @Failure 500 {object} models.Message "Internal server error"
// @Router /migration/trello/status [get]
// @Router /migration/kanboard/status [get]
func (m *Migration) Name() string {
return "kanboard"
}
// AuthURL returns the url users need to authenticate against
// @Summary Get the auth url from trello
// @Description Returns the auth url where the user needs to get its auth code. This code can then be used to migrate everything from trello to Vikunja.
// @Summary Get the auth url from kanboard
// @Description Returns the auth url where the user needs to get its auth code. This code can then be used to migrate everything from kanboard to Vikunja.
// @tags migration
// @Produce json
// @Security JWTKeyAuth
// @Success 200 {object} handler.AuthURL "The auth url."
// @Failure 500 {object} models.Message "Internal server error"
// @Router /migration/trello/auth [get]
// @Router /migration/kanboard/auth [get]
func (m *Migration) AuthURL() string {
return ""
return config.MigrationKanboardApiEndpoint.GetString()
}
func getKanboardData(endpoint string, token string) (kanboardData []kanboardBoard, err error) {
func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}
rpcClient := jsonrpc.NewClient(endpoint)
func getKanboardData(endpoint string, token string, allowInsecure bool) (kanboardData []kanboardBoard, err error) {
var tr *http.Transport
if allowInsecure {
tr = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
} else {
tr = &http.Transport{}
}
client := &http.Client{Transport: tr}
auth := make(map[string]string)
auth["Authorization"] = "Basic " + basicAuth("jsonrpc", token)
opts := jsonrpc.RPCClientOpts{
HTTPClient: client,
CustomHeaders: auth,
}
rpcClient := jsonrpc.NewClientWithOpts(endpoint, &opts)
err = rpcClient.CallFor(&kanboardData, "getAllProjects")
return
}
// Converts all previously obtained data from trello into the vikunja format.
// `trelloData` should contain all boards with their projects and cards respectively.
// Converts all previously obtained data from kanboard into the vikunja format.
// `kanboardData` should contain all boards with their projects and cards respectively.
func convertKanboardDataToVikunja(kanboardData []kanboardBoard, token string) (fullVikunjaHierachie []*models.ProjectWithTasksAndBuckets, err error) {
log.Debugf("[Kanboard Migration] ")
@ -92,9 +137,9 @@ func convertKanboardDataToVikunja(kanboardData []kanboardBoard, token string) (f
return
}
// Migrate gets all tasks from trello for a user and puts them into vikunja
// @Summary Migrate all projects, tasks etc. from trello
// @Description Migrates all projects, tasks, notes, reminders, subtasks and files from trello to vikunja.
// Migrate gets all tasks from kanboard for a user and puts them into vikunja
// @Summary Migrate all projects, tasks etc. from kanboard
// @Description Migrates all projects, tasks, notes, reminders, subtasks and files from kanboard to vikunja.
// @tags migration
// @Accept json
// @Produce json
@ -107,7 +152,11 @@ func (m *Migration) Migrate(u *user.User) (err error) {
log.Debugf("[Kanboard Migration] Starting migration for user %d", u.ID)
log.Debugf("[Kanboard Migration] Getting all kanboard data for user %d", u.ID)
trelloData, err := getKanboardData(config.MigrationKanboardApiEndpoint.GetString(), config.MigrationKanboardApiToken.GetString())
kanboardData, err := getKanboardData(
config.MigrationKanboardApiEndpoint.GetString(),
config.MigrationKanboardApiToken.GetString(),
config.MigrationKanboardApiInsecure.GetBool(),
)
if err != nil {
return
}
@ -115,7 +164,7 @@ func (m *Migration) Migrate(u *user.User) (err error) {
log.Debugf("[Kanboard Migration] Got all kanboard data for user %d", u.ID)
log.Debugf("[Kanboard Migration] Start converting kanboard data for user %d", u.ID)
fullVikunjaHierachie, err := convertKanboardDataToVikunja(trelloData, m.Token)
fullVikunjaHierachie, err := convertKanboardDataToVikunja(kanboardData, m.Token)
if err != nil {
return
}