Skip to content

Commit

Permalink
feat: add support for validating and allowing namespaces
Browse files Browse the repository at this point in the history
- Add support for checking and allowing certain namespaces in `cmd/backup/app.go`
- Add a `ValidNamespace` function to validate namespaces in `internal/pkg/util/kutil/kutil.go`

Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed May 23, 2024
1 parent 8c71fef commit 319e22f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/backup/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/easysoft/qcadmin/internal/api/cne"
"github.com/easysoft/qcadmin/internal/pkg/util/factory"
"github.com/easysoft/qcadmin/internal/pkg/util/kutil"
"github.com/easysoft/qcadmin/internal/pkg/util/output"
)

Expand All @@ -43,6 +44,9 @@ func newCmdBackupAppCreate(f factory.Factory) *cobra.Command {
if len(app) == 0 || len(ns) == 0 {
return errors.New("missing app or ns")
}
if !kutil.ValidNamespace(ns) {
return errors.New("allow support quickon prefix namespace")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -99,6 +103,9 @@ func newCmdBackupAppList(f factory.Factory) *cobra.Command {
if len(app) == 0 || len(ns) == 0 {
return errors.New("missing app or ns")
}
if !kutil.ValidNamespace(ns) {
return errors.New("allow support quickon prefix namespace")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
10 changes: 10 additions & 0 deletions internal/pkg/util/kutil/kutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ func GetConsoleURL(cfg *config.Config) string {
}
return domain
}

// ValidNamespace valid namespace
func ValidNamespace(ns string) bool {
switch ns {
case common.DefaultAppNamespace, common.DefaultSystemNamespace:
return true
default:
return false
}
}

0 comments on commit 319e22f

Please sign in to comment.