Alex Dunmow 1a8347a9e5 Add plugin route, output, form, log and egress rules (checks 33 to 37)
Generated plugins (acceptance.json at the root) fail on: HTTP routes not
registered through pluginsdk route or a public route reading personal
columns; HTML built from unescaped non-constant strings; public POSTs
outside route.Form; personal data names in log calls; outbound requests
carrying personal data or values the spec does not send to that host.
First-party plugins get the same findings as warnings.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 06:26:33 +08:00

59 lines
2.0 KiB
Go

package main
import (
"context"
"strings"
"git.dev.alexdunmow.com/block/pluginsdk/blocks"
"git.dev.alexdunmow.com/block/pluginsdk/plugin"
"git.dev.alexdunmow.com/block/pluginsdk/plugin/wasmguest"
"git.dev.alexdunmow.com/block/pluginsdk/templates"
)
const pluginName = "weather-forecast-6aa47a"
const settingsSchema = `{"schema":"weather-forecast.settings.v1","fields":[{"key":"town_name","label":"Town name","type":"string","default":""},{"key":"latitude","label":"Latitude","type":"string","default":""},{"key":"longitude","label":"Longitude","type":"string","default":""}]}`
const unavailable = "The forecast is not available right now."
// Registration is the plugin entry point.
var Registration = plugin.PluginRegistration{
Name: pluginName,
Version: "1.0.0",
Register: register,
SettingsSchema: func() []byte { return []byte(settingsSchema) },
}
func register(_ templates.TemplateRegistry, br blocks.BlockRegistry) error {
br.Register(blocks.BlockMeta{
Key: "weather_forecast",
Title: "Local weather forecast",
Category: blocks.CategoryContent,
}, renderBlock)
return nil
}
func renderBlock(ctx context.Context, content map[string]any) string {
heading, _ := content["heading"].(string)
days := parseDays(content["days_shown"])
svc := wasmguest.HostServices()
if svc.Settings == nil || svc.OutboundHTTP == nil {
return renderForecast(heading, "", nil, unavailable)
}
set, err := svc.Settings.GetPluginSettings(ctx, pluginName)
if err != nil {
return renderForecast(heading, "", nil, unavailable)
}
lat, ok1 := settingFloat(set, "latitude")
lon, ok2 := settingFloat(set, "longitude")
if !ok1 || !ok2 || !validCoords(lat, lon) {
return renderForecast(heading, "", nil, "The town location has not been set up yet.")
}
forecast, err := fetchForecast(ctx, svc.OutboundHTTP, lat, lon, days)
if err != nil || len(forecast) == 0 {
return renderForecast(heading, "", nil, unavailable)
}
town, _ := set["town_name"].(string)
return renderForecast(heading, strings.TrimSpace(town), forecast, "")
}