Files
team/server/public/model/packet_metadata.go
zeekayandHanzo Dev 05e7bfa24b call the product Hanzo Team, and paint it in one ink
Renames the product across user-facing text -- 1475 lines, i18n and the
defaultMessage strings that must match it -- while leaving the names that
are code rather than prose: upstream copyright, Go import paths, the
@mattermost npm scope, i18n keys, Go template fields, and legacy theme
identifiers like AuthorType.Mattermost and the 'Mattermost' key that maps
an old theme to a new one. The rule is a word boundary on identifier
characters; MattermostEntry is a symbol, "Mattermost" in a sentence is
the product.

The theme goes monochrome. Hanzo and Hanzo Dark are the two built-ins and
Hanzo is the default, with the CSS custom properties that carry brand
colour outside the theme object -- sidebar, buttons, links, titles --
moved to black. Status colours stay: online, away, do-not-disturb and
error encode state, not brand, and flattening them to grey would cost
meaning to buy consistency.

The sign-in header drops the TEAM EDITION badge. It advertised which
licence tier you were on, and there are no tiers here. Booting without a
licence is now logged at debug rather than warned about, because it is
this server's normal condition rather than a fault.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-13 22:28:09 -07:00

132 lines
3.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"fmt"
"github.com/Masterminds/semver/v3"
"github.com/goccy/go-yaml"
)
type PacketType string
const (
CurrentMetadataVersion int = 1
SupportPacketType PacketType = "support-packet"
PluginPacketType PacketType = "plugin-packet"
PacketMetadataFileName = "metadata.yaml"
)
// PacketMetadata contains information about the server and the configured license (if there is one),
// It's used in file archives, so called Packets, that customer send to Hanzo Team Staff for review.
// For example, this metadata is attached to the Support Packet and the Metrics plugin Packet.
type PacketMetadata struct {
// Required Fields
Version int `yaml:"version"`
Type PacketType `yaml:"type"`
GeneratedAt int64 `yaml:"generated_at"`
ServerVersion string `yaml:"server_version"`
ServerID string `yaml:"server_id"`
// Optional Fields
LicenseID string `yaml:"license_id"`
CustomerID string `yaml:"customer_id"`
Extras map[string]any `yaml:"extras,omitempty"`
}
func (md *PacketMetadata) Validate() error {
if md.Version < 1 {
return fmt.Errorf("metadata version should be greater than 1")
}
switch md.Type {
case SupportPacketType, PluginPacketType:
default:
return fmt.Errorf("unrecognized packet type: %s", md.Type)
}
if md.GeneratedAt <= 0 {
return fmt.Errorf("generated_at should be a positive number")
}
if _, err := semver.NewVersion(md.ServerVersion); err != nil {
return fmt.Errorf("could not parse server version: %w", err)
}
if !IsValidId(md.ServerID) {
return fmt.Errorf("server id is not a valid id %q", md.ServerID)
}
if md.LicenseID != "" && !IsValidId(md.LicenseID) {
return fmt.Errorf("license id is not a valid id %q", md.LicenseID)
}
if md.CustomerID != "" && !IsValidId(md.CustomerID) {
return fmt.Errorf("customer id is not a valid id %q", md.CustomerID)
}
return nil
}
func ParsePacketMetadata(b []byte) (*PacketMetadata, error) {
v := struct {
Version int `yaml:"version"`
}{}
err := yaml.Unmarshal(b, &v)
if err != nil {
return nil, err
}
switch v.Version {
case 1:
var md PacketMetadata
err = yaml.Unmarshal(b, &md)
if err != nil {
return nil, err
}
err = md.Validate()
if err != nil {
return nil, err
}
return &md, nil
default:
return nil, fmt.Errorf("unsupported metadata version: %d", v.Version)
}
}
// GeneratePacketMetadata is a utility function to generate metadata for customer provided Packets.
// It will construct it from a Packet Type, the telemetryID and optionally a license.
func GeneratePacketMetadata(t PacketType, telemetryID string, license *License, extra map[string]any) (*PacketMetadata, error) {
if extra == nil {
extra = make(map[string]any)
}
md := &PacketMetadata{
Version: CurrentMetadataVersion,
Type: t,
GeneratedAt: GetMillis(),
ServerVersion: CurrentVersion,
ServerID: telemetryID,
Extras: extra,
}
if license != nil {
md.LicenseID = license.Id
md.CustomerID = license.Customer.Id
}
if err := md.Validate(); err != nil {
return nil, fmt.Errorf("invalid metadata: %w", err)
}
return md, nil
}