bldr/plugin/plugin.go
Rama master · réplica de lectura del repositorio original.
package bldr_plugin
import (
"net/url"
"strings"
"github.com/s4wave/spacewave/bldr/plugin/pluginid"
)
// ValidatePluginID validates a plugin ID.
func ValidatePluginID(id string, allowEmpty bool) error {
return pluginid.Validate(id, allowEmpty)
}
// BuildPluginRpcComponentID addresses a plugin binding and optional exact executable.
func BuildPluginRpcComponentID(pluginID, instanceKey, manifestRoot string) string {
// Start the component ID with the plugin ID.
componentID := pluginID
// Append the escaped instance key when present.
if instanceKey != "" {
componentID += "/" + url.PathEscape(instanceKey)
}
// Append the manifest root as a query parameter when present.
if manifestRoot != "" {
componentID += "?manifest=" + url.QueryEscape(manifestRoot)
}
return componentID
}
// ParsePluginRpcComponentID keeps executable identity separate from instance routing.
func ParsePluginRpcComponentID(componentID string) (pluginID, instanceKey, manifestRoot string, err error) {
// Split the component ID into path and query, then unescape the instance key.
path, query, _ := strings.Cut(componentID, "?")
pluginID, instanceKey, _ = strings.Cut(path, "/")
instanceKey, err = url.PathUnescape(instanceKey)
if err != nil {
return
}
// Parse the query parameters and read the manifest root.
values, err := url.ParseQuery(query)
if err != nil {
return
}
manifestRoot = values.Get("manifest")
return
}
// Validate validates the PluginStatus object.
func (s *PluginStatus) Validate() error {
if err := ValidatePluginID(s.GetPluginId(), false); err != nil {
return err
}
return nil
}
// Validate validates the LoadPlugin request.
func (r *LoadPluginRequest) Validate() error {
if err := ValidatePluginID(r.GetPluginId(), false); err != nil {
return err
}
return nil
}