-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edb0c4c
commit 0554ae5
Showing
20 changed files
with
6,239 additions
and
1,318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// main handles deployment of the plugin to a development server using either the Client4 API | ||
// or by copying the plugin bundle into a sibling mattermost-server/plugin directory. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/mattermost/mattermost-server/v5/model" | ||
"github.com/mholt/archiver/v3" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func main() { | ||
err := deploy() | ||
if err != nil { | ||
fmt.Printf("Failed to deploy: %s\n", err.Error()) | ||
fmt.Println() | ||
fmt.Println("Usage:") | ||
fmt.Println(" deploy <plugin id> <bundle path>") | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// deploy handles deployment of the plugin to a development server. | ||
func deploy() error { | ||
if len(os.Args) < 3 { | ||
return errors.New("invalid number of arguments") | ||
} | ||
|
||
pluginID := os.Args[1] | ||
bundlePath := os.Args[2] | ||
|
||
siteURL := os.Getenv("MM_SERVICESETTINGS_SITEURL") | ||
adminToken := os.Getenv("MM_ADMIN_TOKEN") | ||
adminUsername := os.Getenv("MM_ADMIN_USERNAME") | ||
adminPassword := os.Getenv("MM_ADMIN_PASSWORD") | ||
copyTargetDirectory, _ := filepath.Abs("../mattermost-server") | ||
|
||
if siteURL != "" { | ||
client := model.NewAPIv4Client(siteURL) | ||
|
||
if adminToken != "" { | ||
log.Printf("Authenticating using token against %s.", siteURL) | ||
client.SetToken(adminToken) | ||
|
||
return uploadPlugin(client, pluginID, bundlePath) | ||
} | ||
|
||
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 errors.Wrapf(resp.Error, "failed to login as %s", adminUsername) | ||
} | ||
|
||
return uploadPlugin(client, pluginID, bundlePath) | ||
} | ||
} | ||
|
||
_, err := os.Stat(copyTargetDirectory) | ||
if os.IsNotExist(err) { | ||
return errors.New("no supported deployment method available, please install plugin manually") | ||
} else if err != nil { | ||
return errors.Wrapf(err, "failed to stat %s", copyTargetDirectory) | ||
} | ||
|
||
log.Printf("Installing plugin to mattermost-server found in %s.", copyTargetDirectory) | ||
log.Print("Server restart required to load updated plugin.") | ||
return copyPlugin(pluginID, copyTargetDirectory, bundlePath) | ||
} | ||
|
||
// uploadPlugin attempts to upload and enable a plugin via the Client4 API. | ||
// It will fail if plugin uploads are disabled. | ||
func uploadPlugin(client *model.Client4, pluginID, bundlePath string) error { | ||
pluginBundle, err := os.Open(bundlePath) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to open %s", bundlePath) | ||
} | ||
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()) | ||
} | ||
|
||
log.Print("Enabling plugin.") | ||
_, resp = client.EnablePlugin(pluginID) | ||
if resp.Error != nil { | ||
return fmt.Errorf("Failed to enable plugin: %s", resp.Error.Error()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// copyPlugin attempts to install a plugin by copying it to a sibling ../mattermost-server/plugin | ||
// directory. A server restart is required before the plugin will start. | ||
func copyPlugin(pluginID, targetPath, bundlePath string) error { | ||
targetPath = filepath.Join(targetPath, "plugins") | ||
|
||
err := os.MkdirAll(targetPath, 0777) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to create %s", targetPath) | ||
} | ||
|
||
existingPluginPath := filepath.Join(targetPath, pluginID) | ||
err = os.RemoveAll(existingPluginPath) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to remove existing existing plugin directory %s", existingPluginPath) | ||
} | ||
|
||
err = archiver.Unarchive(bundlePath, targetPath) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to unarchive %s into %s", bundlePath, targetPath) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
module github.com/streamer45/mattermost-plugin-voice | ||
module github.com/mattermost/mattermost-plugin-starter-template | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/blang/semver v3.6.1+incompatible | ||
github.com/blang/semver v3.5.1+incompatible | ||
github.com/go-ldap/ldap v3.0.3+incompatible // indirect | ||
github.com/hashicorp/go-hclog v0.9.2 // indirect | ||
github.com/hashicorp/go-plugin v1.0.1 // indirect | ||
github.com/lib/pq v1.1.1 // indirect | ||
github.com/mattermost/go-i18n v1.11.0 // indirect | ||
github.com/mattermost/mattermost-server v5.12.0+incompatible | ||
github.com/pelletier/go-toml v1.4.0 // indirect | ||
github.com/pkg/errors v0.8.1 | ||
github.com/stretchr/testify v1.3.0 | ||
github.com/mattermost/mattermost-server v5.11.1+incompatible | ||
github.com/mattermost/mattermost-server/v5 v5.20.0 | ||
github.com/mholt/archiver/v3 v3.3.0 | ||
github.com/nicksnyder/go-i18n v1.10.1 // indirect | ||
github.com/pkg/errors v0.9.1 | ||
github.com/stretchr/testify v1.5.1 | ||
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect | ||
) | ||
|
||
// Workaround for https://github.com/golang/go/issues/30831 and fallout. | ||
replace github.com/golang/lint => github.com/golang/lint v0.0.0-20190227174305-8f45f776aaf1 |
Oops, something went wrong.