1/*
2Copyright (c) 2017 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 object
18
19import (
20	"context"
21
22	"github.com/vmware/govmomi/vim25/soap"
23	"github.com/vmware/govmomi/vim25/types"
24)
25
26type DisabledMethodRequest struct {
27	Method string `xml:"method"`
28	Reason string `xml:"reasonId"`
29}
30
31type disableMethodsRequest struct {
32	This   types.ManagedObjectReference   `xml:"_this"`
33	Entity []types.ManagedObjectReference `xml:"entity"`
34	Method []DisabledMethodRequest        `xml:"method"`
35	Source string                         `xml:"sourceId"`
36	Scope  bool                           `xml:"sessionScope,omitempty"`
37}
38
39type disableMethodsBody struct {
40	Req *disableMethodsRequest `xml:"urn:internalvim25 DisableMethods,omitempty"`
41	Res interface{}            `xml:"urn:vim25 DisableMethodsResponse,omitempty"`
42	Err *soap.Fault            `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
43}
44
45func (b *disableMethodsBody) Fault() *soap.Fault { return b.Err }
46
47func (m AuthorizationManager) DisableMethods(ctx context.Context, entity []types.ManagedObjectReference, method []DisabledMethodRequest, source string) error {
48	var reqBody, resBody disableMethodsBody
49
50	reqBody.Req = &disableMethodsRequest{
51		This:   m.Reference(),
52		Entity: entity,
53		Method: method,
54		Source: source,
55	}
56
57	return m.Client().RoundTrip(ctx, &reqBody, &resBody)
58}
59
60type enableMethodsRequest struct {
61	This   types.ManagedObjectReference   `xml:"_this"`
62	Entity []types.ManagedObjectReference `xml:"entity"`
63	Method []string                       `xml:"method"`
64	Source string                         `xml:"sourceId"`
65}
66
67type enableMethodsBody struct {
68	Req *enableMethodsRequest `xml:"urn:internalvim25 EnableMethods,omitempty"`
69	Res interface{}           `xml:"urn:vim25 EnableMethodsResponse,omitempty"`
70	Err *soap.Fault           `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
71}
72
73func (b *enableMethodsBody) Fault() *soap.Fault { return b.Err }
74
75func (m AuthorizationManager) EnableMethods(ctx context.Context, entity []types.ManagedObjectReference, method []string, source string) error {
76	var reqBody, resBody enableMethodsBody
77
78	reqBody.Req = &enableMethodsRequest{
79		This:   m.Reference(),
80		Entity: entity,
81		Method: method,
82		Source: source,
83	}
84
85	return m.Client().RoundTrip(ctx, &reqBody, &resBody)
86}
87