Skip to content

Commit

Permalink
rpk: add Admin API command check for rpk security users
Browse files Browse the repository at this point in the history
These commands can't be run in Cloud Clusters,
except for Serverless.
  • Loading branch information
r-vasquez committed Aug 23, 2024
1 parent 572ad19 commit fe47685
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/go/rpk/pkg/cli/security/user/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ acl help text for more info.
}
p, err := p.LoadVirtualProfile(fs)
out.MaybeDie(err, "rpk unable to load config: %v", err)
config.CheckExitNotServerlessAdmin(p)

cl, err := adminapi.NewClient(fs, p)
out.MaybeDie(err, "unable to initialize admin client: %v", err)
Expand Down
1 change: 1 addition & 0 deletions src/go/rpk/pkg/cli/security/user/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ delete any ACLs that may exist for this user.
}
p, err := p.LoadVirtualProfile(fs)
out.MaybeDie(err, "rpk unable to load config: %v", err)
config.CheckExitNotServerlessAdmin(p)

cl, err := adminapi.NewClient(fs, p)
out.MaybeDie(err, "unable to initialize admin client: %v", err)
Expand Down
1 change: 1 addition & 0 deletions src/go/rpk/pkg/cli/security/user/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func newListUsersCommand(fs afero.Fs, p *config.Params) *cobra.Command {
}
p, err := p.LoadVirtualProfile(fs)
out.MaybeDie(err, "rpk unable to load config: %v", err)
config.CheckExitNotServerlessAdmin(p)

cl, err := adminapi.NewClient(fs, p)
out.MaybeDie(err, "unable to initialize admin client: %v", err)
Expand Down
1 change: 1 addition & 0 deletions src/go/rpk/pkg/cli/security/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func newUpdateCommand(fs afero.Fs, p *config.Params) *cobra.Command {
f := p.Formatter
p, err := p.LoadVirtualProfile(fs)
out.MaybeDie(err, "rpk unable to load config: %v", err)
config.CheckExitNotServerlessAdmin(p)

cl, err := adminapi.NewClient(fs, p)
out.MaybeDie(err, "unable to initialize admin client: %v", err)
Expand Down
10 changes: 9 additions & 1 deletion src/go/rpk/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,21 @@ func CheckExitCloudAdmin(p *RpkProfile) {
}

// CheckExitServerlessAdmin exits if the profile has FromCloud=true and the
// cluster is a Serverless cluster
// cluster is a Serverless cluster.
func CheckExitServerlessAdmin(p *RpkProfile) {
if p.FromCloud && p.CloudCluster.IsServerless() {
out.Die("This admin API based command is not supported on Redpanda Cloud serverless clusters.")
}
}

// CheckExitNotServerlessAdmin exits if the profile has FromCloud=true and the
// cluster is NOT a Serverless cluster.
func CheckExitNotServerlessAdmin(p *RpkProfile) {
if p.FromCloud && !p.CloudCluster.IsServerless() {
out.Die("This admin API based command is not supported on Redpanda Cloud clusters.")
}
}

// VirtualRedpandaYaml returns a redpanda.yaml, starting with defaults,
// then decoding a potential file, then applying env vars and then flags.
func (c *Config) VirtualRedpandaYaml() *RedpandaYaml {
Expand Down

0 comments on commit fe47685

Please sign in to comment.