Update Packet metadata generation based on feedback (#27490)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9f396c9294
Коммит
6bbf7bbb9f
@@ -2,11 +2,14 @@ package pluginapi
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
filePath "path"
|
||||
"time"
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
@@ -102,11 +105,20 @@ func (s *SystemService) GetSystemInstallDate() (time.Time, error) {
|
||||
// GetDiagnosticID returns a unique identifier used by the server for diagnostic reports.
|
||||
//
|
||||
// Minimum server version: 5.10
|
||||
//
|
||||
// Deprecated: Use GetTelemetryID instead. It returns the same value.
|
||||
func (s *SystemService) GetDiagnosticID() string {
|
||||
// TODO: Consider deprecating/rewriting in favor of just using GetUnsanitizedConfig().
|
||||
return s.api.GetDiagnosticId()
|
||||
}
|
||||
|
||||
// GetTelemetryID returns a unique identifier used by the server for telemetry reports.
|
||||
//
|
||||
// Minimum server version: 5.10
|
||||
func (s *SystemService) GetTelemetryID() string {
|
||||
return s.api.GetTelemetryId()
|
||||
}
|
||||
|
||||
// RequestTrialLicense requests a trial license and installs it in the server.
|
||||
// If the server version is lower than 5.36.0, an error is returned.
|
||||
//
|
||||
@@ -122,3 +134,49 @@ func (s *SystemService) RequestTrialLicense(requesterID string, users int, terms
|
||||
err := s.api.RequestTrialLicense(requesterID, users, termsAccepted, receiveEmailsAccepted)
|
||||
return normalizeAppErr(err)
|
||||
}
|
||||
|
||||
// GeneratePacketMetadata generates metadata for Customer Packets, encods it to YAML and saves it to a file
|
||||
// defined by the path parameter.
|
||||
// pluginMeta should contain the values that plugin wants to insert into the standard metadata.
|
||||
//
|
||||
// The plugin_id and plugin_version will be used from the manifest.
|
||||
// If pluginMeta contains plugin_id or plugin_version, they will be overridden.
|
||||
//
|
||||
// It returns the path to the file where the metadata was saved.
|
||||
//
|
||||
// @tag Metadata
|
||||
// Minimum server version: 5.10
|
||||
func (s *SystemService) GeneratePacketMetadata(path string, pluginMeta map[string]any) (string, error) {
|
||||
manifest, err := s.GetManifest()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to get manifest")
|
||||
}
|
||||
license := s.GetLicense()
|
||||
serverID := s.GetTelemetryID()
|
||||
|
||||
if pluginMeta == nil {
|
||||
pluginMeta = make(map[string]any)
|
||||
}
|
||||
|
||||
// we override the plugin_id and version fields from the manifest
|
||||
pluginMeta["plugin_id"] = manifest.Id
|
||||
pluginMeta["plugin_version"] = manifest.Version
|
||||
|
||||
md, err := model.GeneratePacketMetadata(serverID, license, pluginMeta)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to get packet metadata")
|
||||
}
|
||||
filePath := filePath.Join(path, model.PacketMetadataFileName)
|
||||
f, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to create packet metadata file")
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
err = yaml.NewEncoder(f).Encode(md)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to create packet metadata file")
|
||||
}
|
||||
|
||||
return filePath, nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user