feat: added cacerts and some tidying

This commit is contained in:
David Allen 2025-08-31 22:02:10 -06:00
parent 2112e7eefd
commit bdd85b01ff
Signed by: towk
GPG key ID: 0430CDBE22619155
8 changed files with 279 additions and 59 deletions

View file

@ -19,9 +19,10 @@ import (
)
type Service struct {
Addr string
RootPath string `yaml:"root,omitempty"`
Environment map[string]string
Addr string
RootPath string `yaml:"root,omitempty"`
CACertFile string `yaml:"cacert,omitempty"`
CACertKeyfile string `yaml:"keyfile,omitempty"`
// max counts
PluginsMaxCount int
@ -32,13 +33,8 @@ type Service struct {
// New creates a new Service instance with default values
func New() *Service {
return &Service{
Addr: ":5050",
RootPath: "./",
Environment: map[string]string{
"MAKESHIFT_HOST": "",
"MAKESHIFT_ROOT": "",
"ACCESS_TOKEN": "",
},
Addr: ":5050",
RootPath: "./",
PluginsMaxCount: DEFAULT_PLUGINS_MAX_COUNT,
ProfilesMaxCount: DEFAULT_PROFILES_MAX_COUNT,
Timeout: DEFAULT_TIMEOUT_IN_SECS,
@ -121,7 +117,11 @@ func (s *Service) Serve() error {
// always available public routes go here
router.HandleFunc("/status", s.GetStatus)
return http.ListenAndServe(s.Addr, router)
if s.CACertFile != "" && s.CACertKeyfile != "" {
return http.ListenAndServeTLS(s.Addr, s.CACertFile, s.CACertKeyfile, router)
} else {
return http.ListenAndServe(s.Addr, router)
}
}
func (s *Service) requireAuth() bool {