2023-05-30 17:48:52 +08:00
package repo
2023-11-30 22:49:27 +08:00
import (
"fmt"
2024-06-13 12:11:35 +08:00
"github.com/grafana/grafana/pkg/apimachinery/errutil"
2023-11-30 22:49:27 +08:00
)
2023-05-30 17:48:52 +08:00
type ErrResponse4xx struct {
message string
statusCode int
compatibilityInfo CompatOpts
}
func newErrResponse4xx ( statusCode int ) ErrResponse4xx {
return ErrResponse4xx {
statusCode : statusCode ,
}
}
func ( e ErrResponse4xx ) Message ( ) string {
return e . message
}
func ( e ErrResponse4xx ) StatusCode ( ) int {
return e . statusCode
}
func ( e ErrResponse4xx ) withMessage ( message string ) ErrResponse4xx {
e . message = message
return e
}
func ( e ErrResponse4xx ) withCompatibilityInfo ( compatibilityInfo CompatOpts ) ErrResponse4xx {
e . compatibilityInfo = compatibilityInfo
return e
}
func ( e ErrResponse4xx ) Error ( ) string {
if len ( e . message ) > 0 {
compatInfo := e . compatibilityInfo . String ( )
if len ( compatInfo ) > 0 {
return fmt . Sprintf ( "%d: %s (%s)" , e . statusCode , e . message , compatInfo )
}
return fmt . Sprintf ( "%d: %s" , e . statusCode , e . message )
}
return fmt . Sprintf ( "%d" , e . statusCode )
}
2023-11-30 22:49:27 +08:00
var (
ErrVersionUnsupportedMsg = "{{.Public.PluginID}} v{{.Public.Version}} is not supported on your system {{.Public.SysInfo}}"
ErrVersionUnsupportedBase = errutil . Conflict ( "plugin.unsupportedVersion" ) .
MustTemplate ( ErrVersionUnsupportedMsg , errutil . WithPublic ( ErrVersionUnsupportedMsg ) )
2023-05-30 17:48:52 +08:00
2023-11-30 22:49:27 +08:00
ErrVersionNotFoundMsg = "{{.Public.PluginID}} v{{.Public.Version}} either does not exist or is not supported on your system {{.Public.SysInfo}}"
ErrVersionNotFoundBase = errutil . NotFound ( "plugin.versionNotFound" ) .
MustTemplate ( ErrVersionNotFoundMsg , errutil . WithPublic ( ErrVersionNotFoundMsg ) )
2023-05-30 17:48:52 +08:00
2023-11-30 22:49:27 +08:00
ErrArcNotFoundMsg = "{{.Public.PluginID}} is not compatible with your system architecture: {{.Public.SysInfo}}"
ErrArcNotFoundBase = errutil . NotFound ( "plugin.archNotFound" ) .
MustTemplate ( ErrArcNotFoundMsg , errutil . WithPublic ( ErrArcNotFoundMsg ) )
2023-05-30 17:48:52 +08:00
2025-07-02 00:02:54 +08:00
ErrChecksumMismatchMsg = "expected SHA256 checksum ({{.Public.ExpectedSHA256}}) does not match the downloaded archive ({{.Public.ArchiveURL}}) computed SHA256 checksum ({{.Public.ComputedSHA256}}) - please contact security@grafana.com"
2023-11-30 22:49:27 +08:00
ErrChecksumMismatchBase = errutil . UnprocessableEntity ( "plugin.checksumMismatch" ) .
MustTemplate ( ErrChecksumMismatchMsg , errutil . WithPublic ( ErrChecksumMismatchMsg ) )
2023-05-30 17:48:52 +08:00
2023-11-30 22:49:27 +08:00
ErrCorePluginMsg = "plugin {{.Public.PluginID}} is a core plugin and cannot be installed separately"
ErrCorePluginBase = errutil . Forbidden ( "plugin.forbiddenCorePluginInstall" ) .
MustTemplate ( ErrCorePluginMsg , errutil . WithPublic ( ErrCorePluginMsg ) )
2024-08-22 19:47:00 +08:00
ErrNotCompatibledMsg = "{{.Public.PluginID}} is not compatible with your Grafana version: {{.Public.GrafanaVersion}}"
ErrNotCompatibleBase = errutil . NotFound ( "plugin.grafanaVersionNotCompatible" ) .
MustTemplate ( ErrNotCompatibledMsg , errutil . WithPublic ( ErrNotCompatibledMsg ) )
2023-11-30 22:49:27 +08:00
)
2023-05-30 17:48:52 +08:00
2023-11-30 22:49:27 +08:00
func ErrVersionUnsupported ( pluginID , requestedVersion , systemInfo string ) error {
return ErrVersionUnsupportedBase . Build ( errutil . TemplateData { Public : map [ string ] any { "PluginID" : pluginID , "Version" : requestedVersion , "SysInfo" : systemInfo } } )
2023-05-30 17:48:52 +08:00
}
2023-11-30 22:49:27 +08:00
func ErrVersionNotFound ( pluginID , requestedVersion , systemInfo string ) error {
return ErrVersionNotFoundBase . Build ( errutil . TemplateData { Public : map [ string ] any { "PluginID" : pluginID , "Version" : requestedVersion , "SysInfo" : systemInfo } } )
2023-05-30 17:48:52 +08:00
}
2023-11-30 22:49:27 +08:00
func ErrArcNotFound ( pluginID , systemInfo string ) error {
return ErrArcNotFoundBase . Build ( errutil . TemplateData { Public : map [ string ] any { "PluginID" : pluginID , "SysInfo" : systemInfo } } )
2023-05-30 17:48:52 +08:00
}
2023-11-21 19:46:26 +08:00
2025-07-02 00:02:54 +08:00
func ErrChecksumMismatch ( archiveURL , expectedSHA256 , computedSHA256 string ) error {
return ErrChecksumMismatchBase . Build ( errutil . TemplateData { Public : map [ string ] any { "ArchiveURL" : archiveURL , "ExpectedSHA256" : expectedSHA256 , "ComputedSHA256" : computedSHA256 } } )
2023-11-21 19:46:26 +08:00
}
2023-11-30 22:49:27 +08:00
func ErrCorePlugin ( pluginID string ) error {
return ErrCorePluginBase . Build ( errutil . TemplateData { Public : map [ string ] any { "PluginID" : pluginID } } )
2023-11-21 19:46:26 +08:00
}
2024-08-22 19:47:00 +08:00
func ErrNoCompatibleVersions ( pluginID , grafanaVersion string ) error {
return ErrNotCompatibleBase . Build ( errutil . TemplateData { Public : map [ string ] any { "PluginID" : pluginID , "GrafanaVersion" : grafanaVersion } } )
}