|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package namespace |
| 19 | + |
| 20 | +import ( |
| 21 | + "github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils" |
| 22 | + "github.com/streamnative/pulsarctl/pkg/cmdutils" |
| 23 | +) |
| 24 | + |
| 25 | +func GetSubPermissionsCmd(vc *cmdutils.VerbCmd) { |
| 26 | + desc := cmdutils.LongDescription{} |
| 27 | + desc.CommandUsedFor = "Get permissions to access subscription admin API" |
| 28 | + desc.CommandPermission = "This command requires tenant admin permissions." |
| 29 | + |
| 30 | + desc.CommandExamples = []cmdutils.Example{ |
| 31 | + { |
| 32 | + Desc: "Get permissions to access subscription admin API", |
| 33 | + Command: "pulsarctl namespaces subscription-permission tenant/namespace", |
| 34 | + }, |
| 35 | + } |
| 36 | + |
| 37 | + vc.SetDescription( |
| 38 | + "subscription-permission", |
| 39 | + "Get permissions to access subscription admin API", |
| 40 | + desc.ToString(), |
| 41 | + desc.ExampleToString(), |
| 42 | + "subscription-permission", |
| 43 | + ) |
| 44 | + |
| 45 | + vc.SetRunFuncWithNameArg(func() error { |
| 46 | + return doGetSubPermissions(vc) |
| 47 | + }, "the namespace name is not specified or the namespace name is specified more than one") |
| 48 | + vc.EnableOutputFlagSet() |
| 49 | +} |
| 50 | + |
| 51 | +func doGetSubPermissions(vc *cmdutils.VerbCmd) error { |
| 52 | + ns, err := utils.GetNamespaceName(vc.NameArg) |
| 53 | + if err != nil { |
| 54 | + return err |
| 55 | + } |
| 56 | + |
| 57 | + admin := cmdutils.NewPulsarClient() |
| 58 | + permissions, err := admin.Namespaces().GetSubPermissions(*ns) |
| 59 | + if err == nil { |
| 60 | + err = vc.OutputConfig.WriteOutput(vc.Command.OutOrStdout(), cmdutils.NewOutputContent().WithObject(permissions)) |
| 61 | + } |
| 62 | + return err |
| 63 | +} |
0 commit comments