Skip to content

Commit

Permalink
(feature) Add whoami
Browse files Browse the repository at this point in the history
  • Loading branch information
agrim123 committed Dec 25, 2020
1 parent a4ac051 commit 64143ad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
13 changes: 13 additions & 0 deletions gatekeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/agrim123/gatekeeper/pkg/authentication"
"github.com/agrim123/gatekeeper/pkg/authorization"
"github.com/agrim123/gatekeeper/pkg/notifier"
storePkg "github.com/agrim123/gatekeeper/pkg/store"
)

type GateKeeper struct {
Expand Down Expand Up @@ -61,6 +62,18 @@ func (g *GateKeeper) WithAuthenticationModule(authenticationModule authenticatio
return g
}

func (g *GateKeeper) AllowedCommands() map[string][]string {
return g.store.GetAllowedCommandsForUser(utils.GetExecutingUser())
}

func (g *GateKeeper) Whoami() *storePkg.Whoami {
return &storePkg.Whoami{
Username: utils.GetExecutingUser(),
Groups: store.Store.Users[utils.GetExecutingUser()].Groups,
AllowedCommands: g.AllowedCommands(),
}
}

// Run runs the command given to the gatekeeper
// It then delegates different tasks
func (g *GateKeeper) Run(plan, option string) {
Expand Down
5 changes: 0 additions & 5 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"

"github.com/agrim123/gatekeeper/internal/store"
"github.com/agrim123/gatekeeper/internal/utils"
"github.com/agrim123/gatekeeper/pkg/logger"
)

Expand Down Expand Up @@ -46,7 +45,3 @@ func InitStore(users, plan, servers, groups interface{}) {

store.Store = newStore
}

func GetAllowedCommandsForUser() map[string][]string {
return store.Store.GetAllowedCommandsForUser(utils.GetExecutingUser())
}
7 changes: 7 additions & 0 deletions pkg/store/whoami.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package store

type Whoami struct {
Username string
Groups []string
AllowedCommands map[string][]string
}

0 comments on commit 64143ad

Please sign in to comment.