config

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceName  = "StreamNativeMCP"
	KeychainName = "snmcp"
)
View Source
const (
	EnvConfigDir               = "SNMCP_CONFIG_DIR"
	GlobalDefaultIssuer        = "https://auth.streamnative.cloud/"
	GlobalDefaultClientID      = "AJYEdHWi9EFekEaUXkPWA2MqQ3lq1NrI"
	GlobalDefaultAudience      = "https://api.streamnative.cloud"
	GlobalDefaultAPIServer     = "https://api.streamnative.cloud"
	GlobalDefaultProxyLocation = "https://proxy.streamnative.cloud"
	GlobalDefaultLogLocation   = "https://log.streamnative.cloud"

	// Environment variable prefix
	EnvPrefix = "SNMCP"
)

Variables

View Source
var SNCloudClient *sncloud.APIClient
View Source
var SNCloudClientConfiguration *sncloud.Configuration
View Source
var SNCloudLogClient *http.Client

Functions

func CreateContextWithTokenSource

func CreateContextWithTokenSource(ctx context.Context) (context.Context, error)

CreateContextWithTokenSource creates a context with the TokenSource This might be useful in special scenarios, but is usually not needed as we've already configured the default HTTP client

func GetAPIClient

func GetAPIClient() (*sncloud.APIClient, error)

GetAPIClient returns the initialized API client or an error if not initialized

func GetSNCloudLogClient

func GetSNCloudLogClient() (*http.Client, error)

func InitSNCloudClient

func InitSNCloudClient(issuerURL, audience, keyFilePath, apiURL string, timeout time.Duration, tokenStore store.Store) error

InitSNCloudClient initializes the StreamNative Cloud API client Parameters:

  • issuerURL: OAuth2 authorization server URL
  • audience: API service audience identifier
  • keyFilePath: Client credentials key file path
  • apiURL: API server URL
  • timeout: HTTP client timeout
  • tokenStore: Store for caching tokens

func InitSNCloudLogClient

func InitSNCloudLogClient(issuerData auth.Issuer, tokenStore store.Store) error

func ResetSNCloudLogClient

func ResetSNCloudLogClient()

func TokenRefreshed

func TokenRefreshed(audience string, token *oauth2.Token, tokenStore store.Store) error

TokenRefreshed is called when a token is refreshed to persist the updated token

Types

type Auth

type Auth struct {
	// the OAuth 2.0 issuer endpoint
	IssuerEndpoint string `yaml:"issuer"`
	// the audience identifier for the API server (default: server URL)
	Audience string `yaml:"audience"`
	// the client ID to use for authorization grants (note: not used for service accounts)
	ClientID string `yaml:"client-id"`
}

func (*Auth) Issuer

func (a *Auth) Issuer() auth.Issuer

func (*Auth) Validate

func (a *Auth) Validate() error

type AuthOptions

type AuthOptions struct {
	BackendOverride string

	// AuthOptions is a facade for the token store
	// note: call Complete before using the token store methods
	store.Store
	// contains filtered or unexported fields
}

func NewDefaultAuthOptions

func NewDefaultAuthOptions() AuthOptions

func (*AuthOptions) AddFlags

func (o *AuthOptions) AddFlags(cmd *cobra.Command)

func (*AuthOptions) Complete

func (o *AuthOptions) Complete(storage Storage) error

type Context

type Context struct {
	Organization   string `yaml:"organization,omitempty"`
	PulsarInstance string `yaml:"pulsar-instance,omitempty"`
	PulsarCluster  string `yaml:"pulsar-cluster,omitempty"`
}

type ExternalKafka

type ExternalKafka struct {
	BootstrapServers  string
	AuthType          string
	AuthMechanism     string
	AuthUser          string
	AuthPass          string
	UseTLS            bool
	ClientKeyFile     string
	ClientCertFile    string
	CaFile            string
	SchemaRegistryURL string

	SchemaRegistryAuthUser    string
	SchemaRegistryAuthPass    string
	SchemaRegistryBearerToken string
}

type ExternalPulsar

type ExternalPulsar struct {
	ServiceURL                    string
	WebServiceURL                 string
	Token                         string
	AuthPlugin                    string
	AuthParams                    string
	TLSAllowInsecureConnection    bool
	TLSEnableHostnameVerification bool
	TLSTrustCertsFilePath         string
	TLSCertFile                   string
	TLSKeyFile                    string
}

type OAuth2TokenRefresher

type OAuth2TokenRefresher struct {
	// contains filtered or unexported fields
}

OAuth2TokenRefresher implements oauth2.TokenSource interface for refreshing OAuth2 tokens This is now a wrapper around the cache.CachingTokenSource to leverage the existing token caching

func NewOAuth2TokenRefresher

func NewOAuth2TokenRefresher(tokenStore store.Store, audience string, refresher auth.AuthorizationGrantRefresher) (*OAuth2TokenRefresher, error)

NewOAuth2TokenRefresher creates a new token refresher that uses the stored token cache

func (*OAuth2TokenRefresher) Token

func (t *OAuth2TokenRefresher) Token() (*oauth2.Token, error)

Token implements the oauth2.TokenSource interface, leveraging the cached token

type Options

type Options struct {
	AuthOptions
	ConfigDir  string
	ConfigPath string
	Server     string
	// the OAuth 2.0 issuer endpoint
	IssuerEndpoint string
	// the audience identifier for the API server (default: server URL)
	Audience string
	// the client ID to use for authorization grants (note: not used for service accounts)
	ClientID       string
	Organization   string
	PulsarInstance string
	PulsarCluster  string
	ProxyLocation  string
	LogLocation    string
	KeyFile        string

	UseExternalKafka  bool
	UseExternalPulsar bool
	Kafka             ExternalKafka
	Pulsar            ExternalPulsar
}

Options represents the common options used throughout the program.

func NewConfigOptions

func NewConfigOptions() *Options

NewConfigOptions creates and returns a new Options instance with default values

func (*Options) AddFlags

func (o *Options) AddFlags(cmd *cobra.Command)

AddFlags adds command-line flags for Options

func (*Options) Complete

func (o *Options) Complete() error

Complete completes options from the provided values

func (*Options) GetConfigDirectory

func (o *Options) GetConfigDirectory() string

func (*Options) LoadConfig

func (o *Options) LoadConfig() (*SnConfig, error)

func (*Options) LoadConfigOrDie

func (o *Options) LoadConfigOrDie() *SnConfig

func (*Options) SaveConfig

func (o *Options) SaveConfig(config *SnConfig) error

type SnConfig

type SnConfig struct {
	// the API server endpoint
	Server string `yaml:"server"`
	// CA bundle (base64, PEM)
	CertificateAuthorityData string `yaml:"certificate-authority-data"`
	// indicates whether to skip TLS verification
	InsecureSkipTLSVerify bool `yaml:"insecure-skip-tls-verify"`
	// user auth information
	Auth Auth `yaml:"auth"`
	// settable context
	Context       Context `yaml:"context"`
	ProxyLocation string  `yaml:"proxy-location"`
	LogLocation   string  `yaml:"log-location"`
	KeyFile       string  `yaml:"key-file"`

	ExternalKafka  *ExternalKafka  `yaml:"external-kafka"`
	ExternalPulsar *ExternalPulsar `yaml:"external-pulsar"`
}

type Storage

type Storage interface {
	// Gets the config directory for configuration files, credentials and caches
	GetConfigDirectory() string

	// LoadConfig loads the raw configuration from storage.
	LoadConfig() (*SnConfig, error)

	// LoadConfigOrDie loads the raw configuration from storage, or dies if unable to.
	LoadConfigOrDie() *SnConfig

	// SaveConfig saves the given configuration to storage, overwriting any previous configuration.
	SaveConfig(config *SnConfig) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL