Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Cmd = &cobra.Command{ Use: "server", Short: "Start plugin server", RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() config := ServerConfig{} if err := viper.Unmarshal(&config); err != nil { return err } slog.Debug("Received list of token paths", "token-paths", config.ServiceAccountTokenPaths) config.ServiceAccountTokenPathsAsMap = make(map[string]string) _ServiceAccountTokenPath := []string{} for _, v := range config.ServiceAccountTokenPaths { parts := strings.Split(v, ",") _ServiceAccountTokenPath = append(_ServiceAccountTokenPath, parts...) } for _, v := range _ServiceAccountTokenPath { parts := strings.SplitN(strings.TrimSpace(v), "=", 2) if len(parts) != 2 { return errors.New("Invalid service-account-token-path format") } config.ServiceAccountTokenPathsAsMap[parts[0]] = parts[1] } slog.Debug("Resulting token paths as map", "token-paths", config.ServiceAccountTokenPathsAsMap) http.HandleFunc("/api/v1/getparams.execute", config.secretsHandler(ctx)) if config.ListenTlsCrt != "" || config.ListenTlsKey != "" { cert, err := tls.LoadX509KeyPair(config.ListenTlsCrt, config.ListenTlsKey) if err != nil { slog.Error("server: load cert", "error", err) } tlsConfig := &tls.Config{ Certificates: []tls.Certificate{cert}, ClientAuth: tls.RequireAndVerifyClientCert, } if config.ListenTlsCa != "" { caCert, err := os.ReadFile("ca.crt") if err != nil { slog.Error("server: read ca cert", "error", err) } caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) tlsConfig.ClientCAs = caCertPool } server := &http.Server{ Addr: config.ListenAddress, TLSConfig: tlsConfig, } slog.Info("Server starting with TLS...", "listenAddress", config.ListenAddress) log.Fatal(server.ListenAndServeTLS("", "")) } else { slog.Info("Server starting...", "listenAddress", config.ListenAddress) if err := http.ListenAndServe(config.ListenAddress, nil); err != nil { slog.Error("Server Failure", "err", err) return err } } return nil }, }
Functions ¶
This section is empty.
Types ¶
type PluginInput ¶ added in v0.0.3
type PluginInput struct {
Parameters *PluginParameters `json:"parameters,omitempty"`
}
type PluginParameters ¶ added in v0.0.3
type ResponseBody ¶
type ResponseBody struct {
Output *ResponseOutput `json:"output,omitempty"`
}
type ResponseOutput ¶
type ResponseOutput struct {
Parameters []*ResponseParameters `json:"parameters,omitempty"`
}
type ResponseParameters ¶
type ResponseParameters struct {
Namespace *string `json:"namespace,omitempty"`
}
type ServerConfig ¶
type ServerConfig struct { ListenAddress string `mapstructure:"listen-address"` ListenToken string `mapstructure:"listen-token"` ListenTlsCa string `mapstructure:"listen-tls-ca"` ListenTlsCrt string `mapstructure:"listen-tls-crt"` ListenTlsKey string `mapstructure:"listen-tls-key"` Local bool `mapstructure:"local"` ServiceAccountTlsCa string `mapstructure:"service-account-tls-ca"` ServiceAccountTokenPaths []string `mapstructure:"service-account-token-paths"` ServiceAccountTokenPathsAsMap map[string]string }
func (*ServerConfig) GetClient ¶
func (c *ServerConfig) GetClient(req *PluginParameters) (*rest.Config, kubernetes.Interface, error)
type ServiceRequest ¶ added in v0.0.3
type ServiceRequest struct { ApplicationSetName *string `json:"applicationSetName,omitempty"` Input *PluginInput `json:"input,omitempty"` }
Click to show internal directories.
Click to hide internal directories.