[MM-53695] Make use of github.com/mattermost/mattermost/server/public (#185)
This commit is contained in:
parent
b874f4747e
commit
8862f96d1f
9 changed files with 284 additions and 2864 deletions
50
build/go.mod
50
build/go.mod
|
@ -1,11 +1,55 @@
|
||||||
module github.com/mattermost/mattermost-plugin-starter-template/build
|
module github.com/mattermost/mattermost-plugin-starter-template/build
|
||||||
|
|
||||||
go 1.12
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-git/go-git/v5 v5.4.2
|
github.com/go-git/go-git/v5 v5.4.2
|
||||||
github.com/mattermost/mattermost-server/v6 v6.2.1
|
github.com/mattermost/mattermost/server/public v0.0.6
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.8.4
|
||||||
sigs.k8s.io/yaml v1.3.0
|
sigs.k8s.io/yaml v1.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/Microsoft/go-winio v0.4.16 // indirect
|
||||||
|
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
|
||||||
|
github.com/acomagu/bufpipe v1.0.3 // indirect
|
||||||
|
github.com/blang/semver v3.5.1+incompatible // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a // indirect
|
||||||
|
github.com/emirpasic/gods v1.12.0 // indirect
|
||||||
|
github.com/francoispqt/gojay v1.2.13 // indirect
|
||||||
|
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
|
||||||
|
github.com/go-git/gcfg v1.5.0 // indirect
|
||||||
|
github.com/go-git/go-billy/v5 v5.3.1 // indirect
|
||||||
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
|
github.com/graph-gophers/graphql-go v1.5.1-0.20230110080634-edea822f558a // indirect
|
||||||
|
github.com/imdario/mergo v0.3.12 // indirect
|
||||||
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||||
|
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
||||||
|
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
|
||||||
|
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d // indirect
|
||||||
|
github.com/mattermost/logr/v2 v2.0.16 // indirect
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
|
github.com/pborman/uuid v1.2.1 // indirect
|
||||||
|
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||||
|
github.com/philhofer/fwd v1.1.2 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
||||||
|
github.com/sergi/go-diff v1.1.0 // indirect
|
||||||
|
github.com/tinylib/msgp v1.1.8 // indirect
|
||||||
|
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
|
||||||
|
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||||
|
github.com/wiggin77/merror v1.0.5 // indirect
|
||||||
|
github.com/wiggin77/srslog v1.0.1 // indirect
|
||||||
|
github.com/xanzy/ssh-agent v0.3.0 // indirect
|
||||||
|
golang.org/x/crypto v0.10.0 // indirect
|
||||||
|
golang.org/x/net v0.11.0 // indirect
|
||||||
|
golang.org/x/sys v0.9.0 // indirect
|
||||||
|
golang.org/x/text v0.10.0 // indirect
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
|
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
|
1472
build/go.sum
1472
build/go.sum
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost/server/public/model"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,19 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost/server/public/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const commandTimeout = 120 * time.Second
|
||||||
|
|
||||||
const helpText = `
|
const helpText = `
|
||||||
Usage:
|
Usage:
|
||||||
pluginctl deploy <plugin id> <bundle path>
|
pluginctl deploy <plugin id> <bundle path>
|
||||||
|
@ -33,7 +37,10 @@ func pluginctl() error {
|
||||||
return errors.New("invalid number of arguments")
|
return errors.New("invalid number of arguments")
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := getClient()
|
ctx, cancel := context.WithTimeout(context.Background(), commandTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
client, err := getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -43,19 +50,19 @@ func pluginctl() error {
|
||||||
if len(os.Args) < 4 {
|
if len(os.Args) < 4 {
|
||||||
return errors.New("invalid number of arguments")
|
return errors.New("invalid number of arguments")
|
||||||
}
|
}
|
||||||
return deploy(client, os.Args[2], os.Args[3])
|
return deploy(ctx, client, os.Args[2], os.Args[3])
|
||||||
case "disable":
|
case "disable":
|
||||||
return disablePlugin(client, os.Args[2])
|
return disablePlugin(ctx, client, os.Args[2])
|
||||||
case "enable":
|
case "enable":
|
||||||
return enablePlugin(client, os.Args[2])
|
return enablePlugin(ctx, client, os.Args[2])
|
||||||
case "reset":
|
case "reset":
|
||||||
return resetPlugin(client, os.Args[2])
|
return resetPlugin(ctx, client, os.Args[2])
|
||||||
default:
|
default:
|
||||||
return errors.New("invalid second argument")
|
return errors.New("invalid second argument")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getClient() (*model.Client4, error) {
|
func getClient(ctx context.Context) (*model.Client4, error) {
|
||||||
socketPath := os.Getenv("MM_LOCALSOCKETPATH")
|
socketPath := os.Getenv("MM_LOCALSOCKETPATH")
|
||||||
if socketPath == "" {
|
if socketPath == "" {
|
||||||
socketPath = model.LocalModeSocketPath
|
socketPath = model.LocalModeSocketPath
|
||||||
|
@ -91,7 +98,7 @@ func getClient() (*model.Client4, error) {
|
||||||
if adminUsername != "" && adminPassword != "" {
|
if adminUsername != "" && adminPassword != "" {
|
||||||
client := model.NewAPIv4Client(siteURL)
|
client := model.NewAPIv4Client(siteURL)
|
||||||
log.Printf("Authenticating as %s against %s.", adminUsername, siteURL)
|
log.Printf("Authenticating as %s against %s.", adminUsername, siteURL)
|
||||||
_, _, err := client.Login(adminUsername, adminPassword)
|
_, _, err := client.Login(ctx, adminUsername, adminPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to login as %s: %w", adminUsername, err)
|
return nil, fmt.Errorf("failed to login as %s: %w", adminUsername, err)
|
||||||
}
|
}
|
||||||
|
@ -113,7 +120,7 @@ func getUnixClient(socketPath string) (*model.Client4, bool) {
|
||||||
|
|
||||||
// deploy attempts to upload and enable a plugin via the Client4 API.
|
// deploy attempts to upload and enable a plugin via the Client4 API.
|
||||||
// It will fail if plugin uploads are disabled.
|
// It will fail if plugin uploads are disabled.
|
||||||
func deploy(client *model.Client4, pluginID, bundlePath string) error {
|
func deploy(ctx context.Context, client *model.Client4, pluginID, bundlePath string) error {
|
||||||
pluginBundle, err := os.Open(bundlePath)
|
pluginBundle, err := os.Open(bundlePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open %s: %w", bundlePath, err)
|
return fmt.Errorf("failed to open %s: %w", bundlePath, err)
|
||||||
|
@ -121,13 +128,13 @@ func deploy(client *model.Client4, pluginID, bundlePath string) error {
|
||||||
defer pluginBundle.Close()
|
defer pluginBundle.Close()
|
||||||
|
|
||||||
log.Print("Uploading plugin via API.")
|
log.Print("Uploading plugin via API.")
|
||||||
_, _, err = client.UploadPluginForced(pluginBundle)
|
_, _, err = client.UploadPluginForced(ctx, pluginBundle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to upload plugin bundle: %s", err.Error())
|
return fmt.Errorf("failed to upload plugin bundle: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print("Enabling plugin.")
|
log.Print("Enabling plugin.")
|
||||||
_, err = client.EnablePlugin(pluginID)
|
_, err = client.EnablePlugin(ctx, pluginID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to enable plugin: %s", err.Error())
|
return fmt.Errorf("failed to enable plugin: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -136,9 +143,9 @@ func deploy(client *model.Client4, pluginID, bundlePath string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// disablePlugin attempts to disable the plugin via the Client4 API.
|
// disablePlugin attempts to disable the plugin via the Client4 API.
|
||||||
func disablePlugin(client *model.Client4, pluginID string) error {
|
func disablePlugin(ctx context.Context, client *model.Client4, pluginID string) error {
|
||||||
log.Print("Disabling plugin.")
|
log.Print("Disabling plugin.")
|
||||||
_, err := client.DisablePlugin(pluginID)
|
_, err := client.DisablePlugin(ctx, pluginID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to disable plugin: %w", err)
|
return fmt.Errorf("failed to disable plugin: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -147,9 +154,9 @@ func disablePlugin(client *model.Client4, pluginID string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// enablePlugin attempts to enable the plugin via the Client4 API.
|
// enablePlugin attempts to enable the plugin via the Client4 API.
|
||||||
func enablePlugin(client *model.Client4, pluginID string) error {
|
func enablePlugin(ctx context.Context, client *model.Client4, pluginID string) error {
|
||||||
log.Print("Enabling plugin.")
|
log.Print("Enabling plugin.")
|
||||||
_, err := client.EnablePlugin(pluginID)
|
_, err := client.EnablePlugin(ctx, pluginID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to enable plugin: %w", err)
|
return fmt.Errorf("failed to enable plugin: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -158,13 +165,13 @@ func enablePlugin(client *model.Client4, pluginID string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// resetPlugin attempts to reset the plugin via the Client4 API.
|
// resetPlugin attempts to reset the plugin via the Client4 API.
|
||||||
func resetPlugin(client *model.Client4, pluginID string) error {
|
func resetPlugin(ctx context.Context, client *model.Client4, pluginID string) error {
|
||||||
err := disablePlugin(client, pluginID)
|
err := disablePlugin(ctx, client, pluginID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = enablePlugin(client, pluginID)
|
err = enablePlugin(ctx, client, pluginID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
51
go.mod
51
go.mod
|
@ -1,9 +1,54 @@
|
||||||
module github.com/mattermost/mattermost-plugin-starter-template
|
module github.com/mattermost/mattermost-plugin-starter-template
|
||||||
|
|
||||||
go 1.16
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/mattermost/mattermost-server/v6 v6.2.1
|
github.com/mattermost/mattermost/server/public v0.0.6
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.8.4
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/blang/semver v3.5.1+incompatible // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a // indirect
|
||||||
|
github.com/fatih/color v1.15.0 // indirect
|
||||||
|
github.com/francoispqt/gojay v1.2.13 // indirect
|
||||||
|
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
|
||||||
|
github.com/go-sql-driver/mysql v1.7.1 // indirect
|
||||||
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
|
github.com/graph-gophers/graphql-go v1.5.1-0.20230110080634-edea822f558a // indirect
|
||||||
|
github.com/hashicorp/go-hclog v1.5.0 // indirect
|
||||||
|
github.com/hashicorp/go-plugin v1.4.10 // indirect
|
||||||
|
github.com/hashicorp/yamux v0.1.1 // indirect
|
||||||
|
github.com/lib/pq v1.10.9 // indirect
|
||||||
|
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
|
||||||
|
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d // indirect
|
||||||
|
github.com/mattermost/logr/v2 v2.0.16 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
|
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
|
||||||
|
github.com/oklog/run v1.1.0 // indirect
|
||||||
|
github.com/pborman/uuid v1.2.1 // indirect
|
||||||
|
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||||
|
github.com/philhofer/fwd v1.1.2 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
||||||
|
github.com/tinylib/msgp v1.1.8 // indirect
|
||||||
|
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
|
||||||
|
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||||
|
github.com/wiggin77/merror v1.0.5 // indirect
|
||||||
|
github.com/wiggin77/srslog v1.0.1 // indirect
|
||||||
|
golang.org/x/crypto v0.10.0 // indirect
|
||||||
|
golang.org/x/net v0.11.0 // indirect
|
||||||
|
golang.org/x/sys v0.9.0 // indirect
|
||||||
|
golang.org/x/text v0.10.0 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 // indirect
|
||||||
|
google.golang.org/grpc v1.56.1 // indirect
|
||||||
|
google.golang.org/protobuf v1.31.0 // indirect
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost/server/public/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed plugin.json
|
//go:embed plugin.json
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
"github.com/mattermost/mattermost/server/public/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
"github.com/mattermost/mattermost/server/public/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Plugin implements the interface expected by the Mattermost server to communicate between the server and plugin processes.
|
// Plugin implements the interface expected by the Mattermost server to communicate between the server and plugin processes.
|
||||||
|
|
Reference in a new issue