Files
upstream-mirror 240db4e2a7
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 00:29:55 +05:00

208 lines
6.3 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package commands
import (
"context"
"fmt"
"os"
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/client"
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var PluginCmd = &cobra.Command{
Use: "plugin",
Short: "Management of plugins",
}
var PluginAddCmd = &cobra.Command{
Use: "add [plugins]",
Short: "Add plugins",
Long: "Add plugins to your Mattermost server.",
Example: ` plugin add hovercardexample.tar.gz pluginexample.tar.gz`,
RunE: withClient(pluginAddCmdF),
Args: cobra.MinimumNArgs(1),
}
var PluginInstallURLCmd = &cobra.Command{
Use: "install-url <url>...",
Short: "Install plugin from url",
Long: "Supply one or multiple URLs to plugins compressed in a .tar.gz file. Plugins must be enabled in the server's config settings",
Example: ` # You can install one plugin
$ mmctl plugin install-url https://example.com/mattermost-plugin.tar.gz
# Or install multiple in one go
$ mmctl plugin install-url https://example.com/mattermost-plugin-one.tar.gz https://example.com/mattermost-plugin-two.tar.gz`,
RunE: withClient(pluginInstallURLCmdF),
Args: cobra.MinimumNArgs(1),
}
var PluginDeleteCmd = &cobra.Command{
Use: "delete [plugins]",
Short: "Delete plugins",
Long: "Delete previously uploaded plugins from your Mattermost server.",
Example: ` plugin delete hovercardexample pluginexample`,
RunE: withClient(pluginDeleteCmdF),
Args: cobra.MinimumNArgs(1),
}
var PluginEnableCmd = &cobra.Command{
Use: "enable [plugins]",
Short: "Enable plugins",
Long: "Enable plugins for use on your Mattermost server.",
Example: ` plugin enable hovercardexample pluginexample`,
RunE: withClient(pluginEnableCmdF),
Args: cobra.MinimumNArgs(1),
}
var PluginDisableCmd = &cobra.Command{
Use: "disable [plugins]",
Short: "Disable plugins",
Long: "Disable plugins. Disabled plugins are immediately removed from the user interface and logged out of all sessions.",
Example: ` plugin disable hovercardexample pluginexample`,
RunE: withClient(pluginDisableCmdF),
Args: cobra.MinimumNArgs(1),
}
var PluginListCmd = &cobra.Command{
Use: "list",
Short: "List plugins",
Long: "List all enabled and disabled plugins installed on your Mattermost server.",
Example: ` plugin list`,
RunE: withClient(pluginListCmdF),
}
func init() {
PluginAddCmd.Flags().BoolP("force", "f", false, "overwrite a previously installed plugin with the same ID, if any")
PluginInstallURLCmd.Flags().BoolP("force", "f", false, "overwrite a previously installed plugin with the same ID, if any")
PluginCmd.AddCommand(
PluginAddCmd,
PluginInstallURLCmd,
PluginDeleteCmd,
PluginEnableCmd,
PluginDisableCmd,
PluginListCmd,
)
RootCmd.AddCommand(PluginCmd)
}
func pluginAddCmdF(c client.Client, cmd *cobra.Command, args []string) error {
force, _ := cmd.Flags().GetBool("force")
var multiErr *multierror.Error
for i, plugin := range args {
fileReader, err := os.Open(plugin)
if err != nil {
return err
}
if force {
_, _, err = c.UploadPluginForced(context.TODO(), fileReader)
} else {
_, _, err = c.UploadPlugin(context.TODO(), fileReader)
}
if err != nil {
printer.PrintError("Unable to add plugin: " + args[i] + ". Error: " + err.Error())
multiErr = multierror.Append(multiErr, err)
} else {
printer.Print("Added plugin: " + plugin)
}
fileReader.Close()
}
return multiErr.ErrorOrNil()
}
func pluginInstallURLCmdF(c client.Client, cmd *cobra.Command, args []string) error {
force, _ := cmd.Flags().GetBool("force")
var multiErr *multierror.Error
for _, plugin := range args {
manifest, _, err := c.InstallPluginFromURL(context.TODO(), plugin, force)
if err != nil {
printer.PrintError("Unable to install plugin from URL \"" + plugin + "\". Error: " + err.Error())
multiErr = multierror.Append(multiErr, err)
} else {
printer.PrintT("Plugin {{.Name}} successfully installed", manifest)
}
}
return multiErr.ErrorOrNil()
}
func pluginDeleteCmdF(c client.Client, cmd *cobra.Command, args []string) error {
var multiErr *multierror.Error
for _, plugin := range args {
if _, err := c.RemovePlugin(context.TODO(), plugin); err != nil {
printer.PrintError("Unable to delete plugin: " + plugin + ". Error: " + err.Error())
multiErr = multierror.Append(multiErr, fmt.Errorf("Unable to delete plugin. %w", err))
} else {
printer.Print("Deleted plugin: " + plugin)
}
}
return multiErr.ErrorOrNil()
}
func pluginEnableCmdF(c client.Client, cmd *cobra.Command, args []string) error {
var multiErr *multierror.Error
for _, plugin := range args {
if _, err := c.EnablePlugin(context.TODO(), plugin); err != nil {
printer.PrintError("Unable to enable plugin: " + plugin + ". Error: " + err.Error())
multiErr = multierror.Append(multiErr, err)
} else {
printer.Print("Enabled plugin: " + plugin)
}
}
return multiErr.ErrorOrNil()
}
func pluginDisableCmdF(c client.Client, cmd *cobra.Command, args []string) error {
var multiErr *multierror.Error
for _, plugin := range args {
if _, err := c.DisablePlugin(context.TODO(), plugin); err != nil {
printer.PrintError("Unable to disable plugin: " + plugin + ". Error: " + err.Error())
multiErr = multierror.Append(multiErr, err)
} else {
printer.Print("Disabled plugin: " + plugin)
}
}
return multiErr.ErrorOrNil()
}
func pluginListCmdF(c client.Client, cmd *cobra.Command, args []string) error {
pluginsResp, _, err := c.GetPlugins(context.TODO())
if err != nil {
return errors.New("Unable to list plugins. Error: " + err.Error())
}
format, _ := cmd.Flags().GetString("format")
json, _ := cmd.Flags().GetBool("json")
if format == printer.FormatJSON || json {
printer.Print(pluginsResp)
} else {
printer.Print("Listing enabled plugins")
for _, plugin := range pluginsResp.Active {
printer.PrintT("{{.Manifest.Id}}: {{.Manifest.Name}}, Version: {{.Manifest.Version}}", plugin)
}
printer.Print("")
printer.Print("Listing disabled plugins")
for _, plugin := range pluginsResp.Inactive {
printer.PrintT("{{.Manifest.Id}}: {{.Manifest.Name}}, Version: {{.Manifest.Version}}", plugin)
}
}
return nil
}