[MM-38075] Use mattermost-server/v6 (#157)

This commit is contained in:
Ben Schumacher 2021-08-25 09:29:26 +02:00 committed by GitHub
parent f547011d23
commit a80b066195
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 621 additions and 403 deletions

View file

@ -8,7 +8,7 @@ import (
"net"
"os"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v6/model"
)
const helpText = `
@ -58,7 +58,7 @@ func pluginctl() error {
func getClient() (*model.Client4, error) {
socketPath := os.Getenv("MM_LOCALSOCKETPATH")
if socketPath == "" {
socketPath = model.LOCAL_MODE_SOCKET_PATH
socketPath = model.LocalModeSocketPath
}
client, connected := getUnixClient(socketPath)
@ -91,10 +91,11 @@ func getClient() (*model.Client4, error) {
if adminUsername != "" && adminPassword != "" {
client := model.NewAPIv4Client(siteURL)
log.Printf("Authenticating as %s against %s.", adminUsername, siteURL)
_, resp := client.Login(adminUsername, adminPassword)
if resp.Error != nil {
return nil, fmt.Errorf("failed to login as %s: %w", adminUsername, resp.Error)
_, _, err := client.Login(adminUsername, adminPassword)
if err != nil {
return nil, fmt.Errorf("failed to login as %s: %w", adminUsername, err)
}
return client, nil
}
@ -120,15 +121,15 @@ func deploy(client *model.Client4, pluginID, bundlePath string) error {
defer pluginBundle.Close()
log.Print("Uploading plugin via API.")
_, resp := client.UploadPluginForced(pluginBundle)
if resp.Error != nil {
return fmt.Errorf("failed to upload plugin bundle: %s", resp.Error.Error())
_, _, err = client.UploadPluginForced(pluginBundle)
if err != nil {
return fmt.Errorf("failed to upload plugin bundle: %s", err.Error())
}
log.Print("Enabling plugin.")
_, resp = client.EnablePlugin(pluginID)
if resp.Error != nil {
return fmt.Errorf("failed to enable plugin: %s", resp.Error.Error())
_, err = client.EnablePlugin(pluginID)
if err != nil {
return fmt.Errorf("failed to enable plugin: %s", err.Error())
}
return nil
@ -137,9 +138,9 @@ func deploy(client *model.Client4, pluginID, bundlePath string) error {
// disablePlugin attempts to disable the plugin via the Client4 API.
func disablePlugin(client *model.Client4, pluginID string) error {
log.Print("Disabling plugin.")
_, resp := client.DisablePlugin(pluginID)
if resp.Error != nil {
return fmt.Errorf("failed to disable plugin: %w", resp.Error)
_, err := client.DisablePlugin(pluginID)
if err != nil {
return fmt.Errorf("failed to disable plugin: %w", err)
}
return nil
@ -148,9 +149,9 @@ func disablePlugin(client *model.Client4, pluginID string) error {
// enablePlugin attempts to enable the plugin via the Client4 API.
func enablePlugin(client *model.Client4, pluginID string) error {
log.Print("Enabling plugin.")
_, resp := client.EnablePlugin(pluginID)
if resp.Error != nil {
return fmt.Errorf("failed to enable plugin: %w", resp.Error)
_, err := client.EnablePlugin(pluginID)
if err != nil {
return fmt.Errorf("failed to enable plugin: %w", err)
}
return nil