11package heimdall
22
33import (
4+ "context"
45 "fmt"
56 "net/http"
67 "net/http/httputil"
@@ -20,6 +21,7 @@ import (
2021 "github.com/patterninc/heimdall/pkg/object/command"
2122 "github.com/patterninc/heimdall/pkg/object/job"
2223 "github.com/patterninc/heimdall/pkg/plugin"
24+ "github.com/patterninc/heimdall/pkg/rbac"
2325)
2426
2527const (
@@ -42,6 +44,7 @@ type Heimdall struct {
4244 Server * server.Server `yaml:"server,omitempty" json:"server,omitempty"`
4345 Commands command.Commands `yaml:"commands,omitempty" json:"commands,omitempty"`
4446 Clusters cluster.Clusters `yaml:"clusters,omitempty" json:"clusters,omitempty"`
47+ RBACs rbac.RBACs `yaml:"rbacs,omitempty" json:"rbacs,omitempty"`
4548 JobsDirectory string `yaml:"jobs_directory,omitempty" json:"jobs_directory,omitempty"`
4649 ArchiveDirectory string `yaml:"archive_directory,omitempty" json:"archive_directory,omitempty"`
4750 ResultDirectory string `yaml:"result_directory,omitempty" json:"result_directory,omitempty"`
@@ -79,41 +82,48 @@ func (h *Heimdall) Init() error {
7982 }
8083 h .agentName = fmt .Sprintf ("%s-%d" , strings .ToLower (hostname ), time .Now ().UnixMicro ())
8184
82- // let's load all the plugins
83- plugins , err := h .loadPlugins ()
84- if err != nil {
85- return err
86- }
85+ // // let's load all the plugins
86+ // plugins, err := h.loadPlugins()
87+ // if err != nil {
88+ // return err
89+ // }
8790
88- h .commandHandlers = make (map [string ]plugin.Handler )
91+ // h.commandHandlers = make(map[string]plugin.Handler)
8992
9093 // process commands / add default values if missing, write commands to db
91- for _ , c := range h .Commands {
92-
93- // set defaults for missing properties
94- if err := c .Init (); err != nil {
95- return err
96- }
97-
98- // set command handlers
99- pluginNew , found := plugins [c .Plugin ]
100- if ! found {
101- return fmt .Errorf (formatErrUnknownPlugin , c .Plugin )
102- }
103-
104- handler , err := pluginNew (c .Context )
105- if err != nil {
106- return err
107- }
108- h .commandHandlers [c .ID ] = handler
109-
110- // let's record command in the database
111- if err := h .commandUpsert (c ); err != nil {
112- return err
94+ // for _, c := range h.Commands {
95+
96+ // // set defaults for missing properties
97+ // if err := c.Init(); err != nil {
98+ // return err
99+ // }
100+
101+ // // // set command handlers
102+ // // pluginNew, found := plugins[c.Plugin]
103+ // // if !found {
104+ // // return fmt.Errorf(formatErrUnknownPlugin, c.Plugin)
105+ // // }
106+
107+ // // handler, err := pluginNew(c.Context)
108+ // // if err != nil {
109+ // // return err
110+ // // }
111+ // // h.commandHandlers[c.ID] = handler
112+
113+ // // let's record command in the database
114+ // if err := h.commandUpsert(c); err != nil {
115+ // return err
116+ // }
117+
118+ // }
119+
120+ rbacsByName := map [string ]rbac.RBAC {}
121+ for rbacName , r := range h .RBACs {
122+ if err := r .Init (context .Background ()); err != nil {
123+ return fmt .Errorf ("failed to init rbac %s: %w" , rbacName , err )
113124 }
114-
125+ rbacsByName [ rbacName ] = r
115126 }
116-
117127 // process commands / add default values if missing, write commands to db
118128 for _ , c := range h .Clusters {
119129
@@ -122,11 +132,19 @@ func (h *Heimdall) Init() error {
122132 return err
123133 }
124134
125- // let's record command in the database
126- if err := h .clusterUpsert (c ); err != nil {
127- return err
135+ // // let's record command in the database
136+ // if err := h.clusterUpsert(c); err != nil {
137+ // return err
138+ // }
139+ if len (c .RBACNames ) > 0 {
140+ for _ , rbacName := range c .RBACNames {
141+ r , found := rbacsByName [rbacName ]
142+ if ! found {
143+ return fmt .Errorf ("failed to find rbac %s for cluster %s" , rbacName , c .Name )
144+ }
145+ c .RBACs = append (c .RBACs , r )
146+ }
128147 }
129-
130148 }
131149
132150 // start janitor
0 commit comments