1/* 2Copyright (c) 2016 VMware, Inc. All Rights Reserved. 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16 17package role 18 19import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 "github.com/vmware/govmomi/govc/permissions" 25) 26 27type remove struct { 28 *permissions.PermissionFlag 29 30 force bool 31} 32 33func init() { 34 cli.Register("role.remove", &remove{}) 35} 36 37func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) { 38 cmd.PermissionFlag, ctx = permissions.NewPermissionFlag(ctx) 39 cmd.PermissionFlag.Register(ctx, f) 40 41 f.BoolVar(&cmd.force, "force", false, "Force removal if role is in use") 42} 43 44func (cmd *remove) Process(ctx context.Context) error { 45 if err := cmd.PermissionFlag.Process(ctx); err != nil { 46 return err 47 } 48 return nil 49} 50 51func (cmd *remove) Usage() string { 52 return "NAME" 53} 54 55func (cmd *remove) Description() string { 56 return `Remove authorization role. 57 58Examples: 59 govc role.remove MyRole 60 govc role.remove MyRole -force` 61} 62 63func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error { 64 if f.NArg() != 1 { 65 return flag.ErrHelp 66 } 67 68 m, err := cmd.Manager(ctx) 69 if err != nil { 70 return err 71 } 72 73 role, err := cmd.Role(f.Arg(0)) 74 if err != nil { 75 return err 76 } 77 78 return m.RemoveRole(ctx, role.RoleId, !cmd.force) 79} 80