add vendoring with go dep

This commit is contained in:
Adrian Todorov
2017-10-25 20:52:40 +00:00
parent 704f4d20d1
commit a59409f16b
1627 changed files with 489673 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
/*
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package permissions
import (
"context"
"flag"
"github.com/vmware/govmomi/govc/cli"
)
type ls struct {
*PermissionFlag
inherited bool
}
func init() {
cli.Register("permissions.ls", &ls{})
}
func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
cmd.PermissionFlag, ctx = NewPermissionFlag(ctx)
cmd.PermissionFlag.Register(ctx, f)
f.BoolVar(&cmd.inherited, "a", true, "Include inherited permissions defined by parent entities")
}
func (cmd *ls) Process(ctx context.Context) error {
if err := cmd.PermissionFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *ls) Usage() string {
return "[PATH]..."
}
func (cmd *ls) Description() string {
return `List the permissions defined on or effective on managed entities.
Examples:
govc permissions.ls
govc permissions.ls /dc1/host/cluster1`
}
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
refs, err := cmd.ManagedObjects(ctx, f.Args())
if err != nil {
return err
}
m, err := cmd.Manager(ctx)
if err != nil {
return err
}
for _, ref := range refs {
perms, err := m.RetrieveEntityPermissions(ctx, ref, cmd.inherited)
if err != nil {
return err
}
cmd.List.Add(perms)
}
return cmd.WriteResult(&cmd.List)
}

View File

@@ -0,0 +1,165 @@
/*
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package permissions
import (
"context"
"flag"
"fmt"
"io"
"text/tabwriter"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25/types"
)
type List struct {
Roles object.AuthorizationRoleList `json:",omitempty"`
Permissions []types.Permission `json:",omitempty"`
f *PermissionFlag
}
type PermissionFlag struct {
*flags.DatacenterFlag
*flags.OutputFlag
asRef bool
m *object.AuthorizationManager
List
}
func NewPermissionFlag(ctx context.Context) (*PermissionFlag, context.Context) {
f := &PermissionFlag{}
f.List.f = f
f.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
f.OutputFlag, ctx = flags.NewOutputFlag(ctx)
return f, ctx
}
func (f *PermissionFlag) Register(ctx context.Context, fs *flag.FlagSet) {
f.DatacenterFlag.Register(ctx, fs)
f.OutputFlag.Register(ctx, fs)
fs.BoolVar(&f.asRef, "i", false, "Use moref instead of inventory path")
}
func (f *PermissionFlag) Process(ctx context.Context) error {
if err := f.DatacenterFlag.Process(ctx); err != nil {
return err
}
if err := f.OutputFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (f *PermissionFlag) Manager(ctx context.Context) (*object.AuthorizationManager, error) {
if f.m != nil {
return f.m, nil
}
c, err := f.Client()
if err != nil {
return nil, err
}
f.m = object.NewAuthorizationManager(c)
f.Roles, err = f.m.RoleList(ctx)
return f.m, err
}
func (f *PermissionFlag) Role(name string) (*types.AuthorizationRole, error) {
role := f.Roles.ByName(name)
if role == nil {
return nil, fmt.Errorf("role %q not found", name)
}
return role, nil
}
func (f *PermissionFlag) ManagedObjects(ctx context.Context, args []string) ([]types.ManagedObjectReference, error) {
if !f.asRef {
return f.DatacenterFlag.ManagedObjects(ctx, args)
}
var refs []types.ManagedObjectReference
for _, arg := range args {
var ref types.ManagedObjectReference
if ref.FromString(arg) {
refs = append(refs, ref)
} else {
return nil, fmt.Errorf("invalid moref: %s", arg)
}
}
return refs, nil
}
func (l *List) Write(w io.Writer) error {
ctx := context.Background()
finder, err := l.f.Finder()
if err != nil {
return err
}
refs := make(map[types.ManagedObjectReference]string)
tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", "Role", "Entity", "Principal", "Propagate")
for _, perm := range l.Permissions {
propagate := "No"
if perm.Propagate {
propagate = "Yes"
}
name := l.Roles.ById(perm.RoleId).Name
p := "-"
if perm.Entity != nil {
if l.f.asRef {
p = perm.Entity.String()
} else {
// convert moref to inventory path
if p = refs[*perm.Entity]; p == "" {
e, err := finder.Element(ctx, *perm.Entity)
if err == nil {
p = e.Path
}
refs[*perm.Entity] = p
}
}
}
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", name, p, perm.Principal, propagate)
}
return tw.Flush()
}
func (l *List) Add(perms []types.Permission) {
l.Permissions = append(l.Permissions, perms...)
}

View File

@@ -0,0 +1,85 @@
/*
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package permissions
import (
"context"
"flag"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/vim25/types"
)
type remove struct {
*PermissionFlag
types.Permission
role string
}
func init() {
cli.Register("permissions.remove", &remove{})
}
func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) {
cmd.PermissionFlag, ctx = NewPermissionFlag(ctx)
cmd.PermissionFlag.Register(ctx, f)
f.StringVar(&cmd.Principal, "principal", "", "User or group for which the permission is defined")
f.BoolVar(&cmd.Group, "group", false, "True, if principal refers to a group name; false, for a user name")
}
func (cmd *remove) Process(ctx context.Context) error {
if err := cmd.PermissionFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *remove) Usage() string {
return "[PATH]..."
}
func (cmd *remove) Description() string {
return `Removes a permission rule from managed entities.
Examples:
govc permissions.remove -principal root
govc permissions.remove -principal $USER@vsphere.local -role Admin /dc1/host/cluster1`
}
func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
refs, err := cmd.ManagedObjects(ctx, f.Args())
if err != nil {
return err
}
m, err := cmd.Manager(ctx)
if err != nil {
return err
}
for _, ref := range refs {
err = m.RemoveEntityPermission(ctx, ref, cmd.Principal, cmd.Group)
if err != nil {
return err
}
}
return nil
}

View File

@@ -0,0 +1,96 @@
/*
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package permissions
import (
"context"
"flag"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/vim25/types"
)
type set struct {
*PermissionFlag
types.Permission
role string
}
func init() {
cli.Register("permissions.set", &set{})
}
func (cmd *set) Register(ctx context.Context, f *flag.FlagSet) {
cmd.PermissionFlag, ctx = NewPermissionFlag(ctx)
cmd.PermissionFlag.Register(ctx, f)
f.StringVar(&cmd.Principal, "principal", "", "User or group for which the permission is defined")
f.BoolVar(&cmd.Group, "group", false, "True, if principal refers to a group name; false, for a user name")
f.BoolVar(&cmd.Propagate, "propagate", true, "Whether or not this permission propagates down the hierarchy to sub-entities")
f.StringVar(&cmd.role, "role", "Admin", "Permission role name")
}
func (cmd *set) Process(ctx context.Context) error {
if err := cmd.PermissionFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *set) Usage() string {
return "[PATH]..."
}
func (cmd *set) Description() string {
return `Set the permissions managed entities.
Examples:
govc permissions.set -principal root -role Admin
govc permissions.set -principal $USER@vsphere.local -role Admin /dc1/host/cluster1`
}
func (cmd *set) Run(ctx context.Context, f *flag.FlagSet) error {
refs, err := cmd.ManagedObjects(ctx, f.Args())
if err != nil {
return err
}
m, err := cmd.Manager(ctx)
if err != nil {
return err
}
role, err := cmd.Role(cmd.role)
if err != nil {
return err
}
cmd.Permission.RoleId = role.RoleId
perms := []types.Permission{cmd.Permission}
for _, ref := range refs {
err = m.SetEntityPermissions(ctx, ref, perms)
if err != nil {
return err
}
}
return nil
}