Files
+14 ba79c48dca [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235)
Include https://github.com/mattermost/mattermost-plugin-api into the mono repo

Co-authored-by: Jesse Hallam <[email protected]>
Co-authored-by: Michael Kochell <[email protected]>
Co-authored-by: Alejandro García Montoro <[email protected]>
Co-authored-by: Ben Schumacher <[email protected]>
Co-authored-by: Alex Dovenmuehle <[email protected]>
Co-authored-by: Michael Kochell <[email protected]>
Co-authored-by: Christopher Poile <[email protected]>
Co-authored-by: İlker Göktuğ Öztürk <[email protected]>
Co-authored-by: Shota Gvinepadze <[email protected]>
Co-authored-by: Ali Farooq <[email protected]>
Co-authored-by: Maria A Nunez <[email protected]>
Co-authored-by: Daniel Espino García <[email protected]>
Co-authored-by: Christopher Speller <[email protected]>
Co-authored-by: Alex Dovenmuehle <[email protected]>
Co-authored-by: Szymon Gibała <[email protected]>
Co-authored-by: Lev <[email protected]>
Co-authored-by: Jason Frerich <[email protected]>
Co-authored-by: Agniva De Sarker <[email protected]>
Co-authored-by: Artur M. Wolff <[email protected]>
Co-authored-by: Madhav Hugar <[email protected]>
Co-authored-by: Joe <[email protected]>
Co-authored-by: Ibrahim Serdar Acikgoz <[email protected]>
Co-authored-by: José Peso <[email protected]>
2023-08-21 09:50:30 +02:00

80 lines
2.3 KiB
Go

package pluginapi
import (
"github.com/blang/semver/v4"
"github.com/mattermost/mattermost/server/public/plugin"
"github.com/pkg/errors"
)
// Client is a streamlined wrapper over the mattermost plugin API.
type Client struct {
api plugin.API
Bot BotService
Channel ChannelService
Cluster ClusterService
Configuration ConfigurationService
SlashCommand SlashCommandService
OAuth OAuthService
Emoji EmojiService
File FileService
Frontend FrontendService
Group GroupService
KV KVService
Log LogService
Mail MailService
Plugin PluginService
Post PostService
Session SessionService
Store *StoreService
System SystemService
Team TeamService
User UserService
}
// NewClient creates a new instance of Client.
//
// This client must only be created once per plugin to
// prevent reacquiring of resources.
func NewClient(api plugin.API, driver plugin.Driver) *Client {
return &Client{
api: api,
Bot: BotService{api: api},
Channel: ChannelService{api: api},
Cluster: ClusterService{api: api},
Configuration: ConfigurationService{api: api},
SlashCommand: SlashCommandService{api: api},
OAuth: OAuthService{api: api},
Emoji: EmojiService{api: api},
File: FileService{api: api},
Frontend: FrontendService{api: api},
Group: GroupService{api: api},
KV: KVService{api: api},
Log: LogService{api: api},
Mail: MailService{api: api},
Plugin: PluginService{api: api},
Post: PostService{api: api},
Session: SessionService{api: api},
Store: &StoreService{
api: api,
driver: driver,
},
System: SystemService{api: api},
Team: TeamService{api: api},
User: UserService{api: api},
}
}
func ensureServerVersion(api plugin.API, required string) error {
serverVersion := api.GetServerVersion()
currentVersion := semver.MustParse(serverVersion)
requiredVersion := semver.MustParse(required)
if currentVersion.LT(requiredVersion) {
return errors.Errorf("incompatible server version for plugin, minimum required version: %s, current version: %s", required, serverVersion)
}
return nil
}