github.com/vmware/govmomi@v0.37.1/vapi/appliance/access/shell/shell.go (about) 1 /* 2 Copyright (c) 2022 VMware, Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0. 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 shell 18 19 import ( 20 "context" 21 "net/http" 22 23 "github.com/vmware/govmomi/vapi/rest" 24 ) 25 26 const Path = "/api/appliance/access/shell" 27 28 // Manager provides convenience methods to get/set enabled state of BASH. 29 type Manager struct { 30 *rest.Client 31 } 32 33 // NewManager creates a new Manager with the given client 34 func NewManager(client *rest.Client) *Manager { 35 return &Manager{ 36 Client: client, 37 } 38 } 39 40 // Get returns enabled state of BASH, that is, access to BASH from within the controlled CLI. 41 func (m *Manager) Get(ctx context.Context) (Access, error) { 42 r := m.Resource(Path) 43 44 var status Access 45 return status, m.Do(ctx, r.Request(http.MethodGet), &status) 46 } 47 48 // Access represents shell configuration. 49 type Access struct { 50 Enabled bool `json:"enabled"` 51 Timeout int `json:"timeout"` 52 } 53 54 // Set enables state of BASH, that is access to BASH from within the controlled CLI. 55 func (m *Manager) Set(ctx context.Context, inp Access) error { 56 r := m.Resource(Path) 57 58 return m.Do(ctx, r.Request(http.MethodPut, inp), nil) 59 }