Documentation
¶
Overview ¶
Package common provides shared helpers for StreamNative MCP Server.
Index ¶
- Constants
- func ConvertToMapInterface(m map[string]string) map[string]interface{}
- func ConvertToMapString(m map[string]interface{}) map[string]string
- func GetEngineType(...) string
- func GetOptions(ctx context.Context) *config.Options
- func HasCachedValidToken(cachedGrant *auth.AuthorizationGrant) (bool, error)
- func IsClusterAvailable(...) bool
- func IsInstanceValid(...) bool
- func IsTokenAboutToExpire(cachedGrant *auth.AuthorizationGrant, window time.Duration) (bool, error)
- func OptionalParam[T any](arguments map[string]interface{}, paramName string) (T, bool)
- func OptionalParamArray[T any](arguments map[string]interface{}, paramName string) ([]T, bool)
- func OptionalParamConfigs(arguments map[string]interface{}, paramName string) ([]string, bool)
- func OptionalParamObject(arguments map[string]interface{}, name string) (map[string]interface{}, bool)
- func ParseMessageConfigs(configs []string) (map[string]*string, error)
- func RequiredParam[T comparable](arguments map[string]interface{}, p string) (T, error)
- func RequiredParamArray[T any](arguments map[string]interface{}, paramName string) ([]T, error)
- func RequiredParamObject(arguments map[string]interface{}, name string) (map[string]interface{}, error)
- type ContextKey
Constants ¶
const ( OptionsKey ContextKey = "snmcp-options" AnnotationStreamNativeCloudEngine = "cloud.streamnative.io/engine" KeyPrefix = "snmcp-token" TokenRefreshWindow = 5 * time.Minute )
Common constants used for context keys and token handling.
Variables ¶
This section is empty.
Functions ¶
func ConvertToMapInterface ¶
ConvertToMapInterface converts a map of strings to a map of interface values.
func ConvertToMapString ¶
ConvertToMapString converts a map of interface values to a map of strings.
func GetEngineType ¶
func GetEngineType(cluster sncloud.ComGithubStreamnativeCloudApiServerPkgApisCloudV1alpha1PulsarCluster) string
GetEngineType returns the Pulsar cluster is an Ursa engine or a Classic engine
func GetOptions ¶
GetOptions extracts the config options from the context.
func HasCachedValidToken ¶
func HasCachedValidToken(cachedGrant *auth.AuthorizationGrant) (bool, error)
HasCachedValidToken returns whether the cached grant has a valid token.
func IsClusterAvailable ¶
func IsClusterAvailable(cluster sncloud.ComGithubStreamnativeCloudApiServerPkgApisCloudV1alpha1PulsarCluster) bool
IsClusterAvailable checks if a PulsarCluster is available (ready)
func IsInstanceValid ¶
func IsInstanceValid(instance sncloud.ComGithubStreamnativeCloudApiServerPkgApisCloudV1alpha1PulsarInstance) bool
IsInstanceValid checks if PulsarInstance has valid OAuth2 authentication configuration
func IsTokenAboutToExpire ¶
IsTokenAboutToExpire reports whether the token expires within the window.
func OptionalParam ¶
OptionalParam returns an optional parameter from the request.
func OptionalParamArray ¶
OptionalParamArray returns an optional array parameter from the request.
func OptionalParamConfigs ¶
OptionalParamConfigs gets an optional parameter as a list of key=value strings
func OptionalParamObject ¶
func OptionalParamObject(arguments map[string]interface{}, name string) (map[string]interface{}, bool)
OptionalParamObject returns an optional object parameter from the request.
func ParseMessageConfigs ¶
ParseMessageConfigs parses a list of key=value strings into a map
func RequiredParam ¶
func RequiredParam[T comparable](arguments map[string]interface{}, p string) (T, error)
RequiredParam is a helper function that can be used to fetch a requested parameter from the request. It does the following checks: 1. Checks if the parameter is present in the request. 2. Checks if the parameter is of the expected type. 3. Checks if the parameter is not empty, i.e: non-zero value
func RequiredParamArray ¶
RequiredParamArray returns a required array parameter from the request.