Skip to content

Commit

Permalink
fix: correct some issues
Browse files Browse the repository at this point in the history
* fix: correct some issues

* fix: correct some issues
  • Loading branch information
saman2000hoseini authored Oct 25, 2023
1 parent caf5faf commit e5b485a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/hubble-middleware/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main(cfg config.Config) {
os.Exit(1)
}

projectsHandler := handler.NewProject(clusterConfig)
projectsHandler := handler.NewProject(*clusterConfig)

app.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
Expand Down
15 changes: 8 additions & 7 deletions internal/hubble-middleware/handler/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import (

type (
ProjectHandler struct {
k8sClusterConfig *rest.Config
k8sUserConfig rest.Config
k8sAppConfig rest.Config
}
)

func NewProject(k8s *rest.Config) *ProjectHandler {
return &ProjectHandler{k8sClusterConfig: k8s}
func NewProject(k8s rest.Config) *ProjectHandler {
return &ProjectHandler{k8sUserConfig: k8s, k8sAppConfig: k8s}
}

func (h *ProjectHandler) Get(c echo.Context) error {
Expand Down Expand Up @@ -53,13 +54,13 @@ func (h *ProjectHandler) Get(c echo.Context) error {
}

func (h *ProjectHandler) getUserProjects(username string, groups []string) ([]string, error) {
h.k8sClusterConfig.Impersonate.UserName = username
h.k8sUserConfig.Impersonate.UserName = username

if len(groups) > 0 {
h.k8sClusterConfig.Impersonate.Groups = groups
h.k8sUserConfig.Impersonate.Groups = groups
}

projectClientset, err := projectv1.NewForConfig(h.k8sClusterConfig)
projectClientset, err := projectv1.NewForConfig(&h.k8sUserConfig)
if err != nil {
logrus.Error(err)
return nil, err
Expand All @@ -80,7 +81,7 @@ func (h *ProjectHandler) getUserProjects(username string, groups []string) ([]st
}

func (h *ProjectHandler) getUserGroups(username string) ([]string, error) {
groupClientset, err := groupv1.NewForConfig(h.k8sClusterConfig)
groupClientset, err := groupv1.NewForConfig(&h.k8sAppConfig)
if err != nil {
logrus.Error(err)
return nil, err
Expand Down

0 comments on commit e5b485a

Please sign in to comment.