github.com/vmware/govmomi@v0.37.1/govc/permissions/ls.go (about) 1 /* 2 Copyright (c) 2015 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package permissions 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 ) 25 26 type ls struct { 27 *PermissionFlag 28 29 inherited bool 30 } 31 32 func init() { 33 cli.Register("permissions.ls", &ls{}) 34 } 35 36 func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) { 37 cmd.PermissionFlag, ctx = NewPermissionFlag(ctx) 38 cmd.PermissionFlag.Register(ctx, f) 39 40 f.BoolVar(&cmd.inherited, "a", true, "Include inherited permissions defined by parent entities") 41 } 42 43 func (cmd *ls) Process(ctx context.Context) error { 44 if err := cmd.PermissionFlag.Process(ctx); err != nil { 45 return err 46 } 47 return nil 48 } 49 50 func (cmd *ls) Usage() string { 51 return "[PATH]..." 52 } 53 54 func (cmd *ls) Description() string { 55 return `List the permissions defined on or effective on managed entities. 56 57 Examples: 58 govc permissions.ls 59 govc permissions.ls /dc1/host/cluster1` 60 } 61 62 func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error { 63 refs, err := cmd.ManagedObjects(ctx, f.Args()) 64 if err != nil { 65 return err 66 } 67 68 m, err := cmd.Manager(ctx) 69 if err != nil { 70 return err 71 } 72 73 for _, ref := range refs { 74 perms, err := m.RetrieveEntityPermissions(ctx, ref, cmd.inherited) 75 if err != nil { 76 return err 77 } 78 79 cmd.List.Add(perms) 80 } 81 82 return cmd.WriteResult(&cmd.List) 83 }