github.com/vmware/govmomi@v0.37.2/guest/auth_manager.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 guest
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/vmware/govmomi/vim25"
    23  	"github.com/vmware/govmomi/vim25/methods"
    24  	"github.com/vmware/govmomi/vim25/types"
    25  )
    26  
    27  type AuthManager struct {
    28  	types.ManagedObjectReference
    29  
    30  	vm types.ManagedObjectReference
    31  
    32  	c *vim25.Client
    33  }
    34  
    35  func (m AuthManager) Reference() types.ManagedObjectReference {
    36  	return m.ManagedObjectReference
    37  }
    38  
    39  func (m AuthManager) AcquireCredentials(ctx context.Context, requestedAuth types.BaseGuestAuthentication, sessionID int64) (types.BaseGuestAuthentication, error) {
    40  	req := types.AcquireCredentialsInGuest{
    41  		This:          m.Reference(),
    42  		Vm:            m.vm,
    43  		RequestedAuth: requestedAuth,
    44  		SessionID:     sessionID,
    45  	}
    46  
    47  	res, err := methods.AcquireCredentialsInGuest(ctx, m.c, &req)
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  
    52  	return res.Returnval, nil
    53  }
    54  
    55  func (m AuthManager) ReleaseCredentials(ctx context.Context, auth types.BaseGuestAuthentication) error {
    56  	req := types.ReleaseCredentialsInGuest{
    57  		This: m.Reference(),
    58  		Vm:   m.vm,
    59  		Auth: auth,
    60  	}
    61  
    62  	_, err := methods.ReleaseCredentialsInGuest(ctx, m.c, &req)
    63  
    64  	return err
    65  }
    66  
    67  func (m AuthManager) ValidateCredentials(ctx context.Context, auth types.BaseGuestAuthentication) error {
    68  	req := types.ValidateCredentialsInGuest{
    69  		This: m.Reference(),
    70  		Vm:   m.vm,
    71  		Auth: auth,
    72  	}
    73  
    74  	_, err := methods.ValidateCredentialsInGuest(ctx, m.c, &req)
    75  	if err != nil {
    76  		return err
    77  	}
    78  
    79  	return nil
    80  }