Skip to content

Commit

Permalink
govc: add host.cert.info -show flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Jun 24, 2024
1 parent 22607cd commit 7f0c9f0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions govc/host/cert/info.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Copyright (c) 2016-2024 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
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,
Expand All @@ -19,14 +19,18 @@ package cert
import (
"context"
"flag"
"fmt"

"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vim25/mo"
)

type info struct {
*flags.HostSystemFlag
*flags.OutputFlag

show bool
}

func init() {
Expand All @@ -39,6 +43,8 @@ func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {

cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
cmd.OutputFlag.Register(ctx, f)

f.BoolVar(&cmd.show, "show", false, "Show PEM encoded server certificate only")
}

func (cmd *info) Description() string {
Expand All @@ -61,6 +67,16 @@ func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
return err
}

if cmd.show {
var props mo.HostSystem
err = host.Properties(ctx, host.Reference(), []string{"config.certificate"}, &props)
if err != nil {
return err
}
_, err = fmt.Fprint(cmd.Out, string(props.Config.Certificate))
return err
}

m, err := host.ConfigManager().CertificateManager(ctx)
if err != nil {
return err
Expand Down

0 comments on commit 7f0c9f0

Please sign in to comment.