github.com/vmware/govmomi@v0.43.0/govc/sso/idp/default.ls.go (about) 1 /* 2 Copyright (c) 2023-2023 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 idp 18 19 import ( 20 "context" 21 "flag" 22 "fmt" 23 "io" 24 "strings" 25 26 "github.com/vmware/govmomi/govc/cli" 27 "github.com/vmware/govmomi/govc/flags" 28 "github.com/vmware/govmomi/govc/sso" 29 "github.com/vmware/govmomi/ssoadmin" 30 ) 31 32 type didp struct { 33 *flags.ClientFlag 34 *flags.OutputFlag 35 } 36 37 func init() { 38 cli.Register("sso.idp.default.ls", &didp{}) 39 } 40 41 func (cmd *didp) Register(ctx context.Context, f *flag.FlagSet) { 42 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 43 cmd.ClientFlag.Register(ctx, f) 44 45 cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx) 46 cmd.OutputFlag.Register(ctx, f) 47 } 48 49 func (cmd *didp) Description() string { 50 return `List SSO default identity provider sources. 51 52 Examples: 53 govc sso.idp.default.ls 54 govc sso.idp.default.ls -json` 55 } 56 57 func (cmd *didp) Process(ctx context.Context) error { 58 if err := cmd.ClientFlag.Process(ctx); err != nil { 59 return err 60 } 61 return cmd.OutputFlag.Process(ctx) 62 } 63 64 type didpInfo struct { 65 DefaultIdentitySource []string 66 } 67 68 func (r *didpInfo) Write(w io.Writer) error { 69 fmt.Fprintf(w, "Default identity provider source(s): %s\n", strings.Join(r.DefaultIdentitySource, ",")) 70 return nil 71 } 72 73 func (cmd *didp) Run(ctx context.Context, f *flag.FlagSet) error { 74 return sso.WithClient(ctx, cmd.ClientFlag, func(c *ssoadmin.Client) error { 75 var errids error 76 var defaultids didpInfo 77 78 defaultids.DefaultIdentitySource, errids = c.GetDefaultDomains(ctx) 79 if errids != nil { 80 return errids 81 } 82 return cmd.WriteResult(&defaultids) 83 }) 84 }