Skip to content

Commit

Permalink
feat: RBAC Generation from charts with dependencies (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
matteogastaldello authored Jul 29, 2024
1 parent c213ff5 commit 1233e2a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions internal/tools/rbacgen/rbacgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,40 @@ func (r *RbacGenerator) PopulateRBAC(resourceName string) (map[string]RBAC, erro
return rbacMap, rbacErr
}

func getDependencyDir(pkg *chartfs.ChartFS, templatesDir string) string {
chartsDirPath := path.Join(strings.TrimSuffix(templatesDir, "templates"), "charts")

_, err := fs.ReadDir(pkg.FS(), chartsDirPath)
if err != nil {
return ""
}
return chartsDirPath
}

func (r *RbacGenerator) getResourcesInfo(templatesDir string) ([]Resource, error) {
var resources []Resource
var errs []error
// error is ignored - not critical
crdList, _ := crdinfo.GetCRDInfoList(r.pkg)

depsDirPath := getDependencyDir(r.pkg, templatesDir)
if depsDirPath != "" {
depsDir, err := fs.ReadDir(r.pkg.FS(), depsDirPath)
if err != nil {
return nil, fmt.Errorf("failed to read directory %s: %w", depsDirPath, err)
}
for _, file := range depsDir {
if file.IsDir() {
depsDir := path.Join(depsDirPath, file.Name(), "templates")
ress, err := r.getResourcesInfo(depsDir)
if err != nil {
return nil, err
}
resources = append(resources, ress...)
}
}
}

dir, err := fs.ReadDir(r.pkg.FS(), templatesDir)
if err != nil {
return nil, fmt.Errorf("failed to read directory %s: %w", templatesDir, err)
Expand Down

0 comments on commit 1233e2a

Please sign in to comment.