Skip to content

Commit

Permalink
Merge pull request #183 from ninech/nctl_permError
Browse files Browse the repository at this point in the history
wrote if statement to simplfy the forbidden error
  • Loading branch information
SaadAssaf authored Oct 31, 2024
2 parents 1c61a91 + a7dc18f commit 12064e1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

"github.com/alecthomas/kong"

k8serrors "k8s.io/apimachinery/pkg/api/errors"

completion "github.com/jotaen/kong-completion"
"github.com/ninech/nctl/api"
"github.com/ninech/nctl/api/util"
Expand All @@ -34,6 +36,7 @@ type flags struct {
APICluster string `help:"Context name of the API cluster." default:"${api_cluster}" env:"NCTL_API_CLUSTER" hidden:""`
LogAPIAddress string `help:"Address of the deplo.io logging API server." default:"https://logs.deplo.io" env:"NCTL_LOG_ADDR" hidden:""`
LogAPIInsecure bool `help:"Don't verify TLS connection to the logging API server." hidden:"" default:"false" env:"NCTL_LOG_INSECURE"`
Verbose bool `help:"Show verbose messages."`
Version kong.VersionFlag `name:"version" help:"Print version information and quit."`
}

Expand Down Expand Up @@ -154,7 +157,14 @@ func main() {
os.Exit(1)
}

kongCtx.FatalIfErrorf(kongCtx.Run(ctx, client))
err = kongCtx.Run(ctx, client)
if err != nil {
if k8serrors.IsForbidden(err) && !nctl.Verbose {
err = errors.New("permission denied: are you part of the organization?")
}
kongCtx.FatalIfErrorf(err)
}

}

func setupSignalHandler(ctx context.Context, cancel context.CancelFunc) {
Expand Down

0 comments on commit 12064e1

Please sign in to comment.