forked from vmware/govmomi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
govc: Add feature to get and set default idp
Closes: vmware#3023
- Loading branch information
Hrabur Stoyanov
committed
Jan 9, 2023
1 parent
68d1994
commit e935b5a
Showing
7 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
Copyright (c) 2023-2023 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 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package idp | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"github.com/vmware/govmomi/govc/cli" | ||
"github.com/vmware/govmomi/govc/flags" | ||
"github.com/vmware/govmomi/govc/sso" | ||
"github.com/vmware/govmomi/ssoadmin" | ||
) | ||
|
||
type didp struct { | ||
*flags.ClientFlag | ||
*flags.OutputFlag | ||
} | ||
|
||
func init() { | ||
cli.Register("sso.idp.default.ls", &didp{}) | ||
} | ||
|
||
func (cmd *didp) Register(ctx context.Context, f *flag.FlagSet) { | ||
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) | ||
cmd.ClientFlag.Register(ctx, f) | ||
|
||
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx) | ||
cmd.OutputFlag.Register(ctx, f) | ||
} | ||
|
||
func (cmd *didp) Description() string { | ||
return `List SSO default identity provider sources. | ||
Examples: | ||
govc sso.idp.default.ls | ||
govc sso.idp.default.ls -json` | ||
} | ||
|
||
func (cmd *didp) Process(ctx context.Context) error { | ||
if err := cmd.ClientFlag.Process(ctx); err != nil { | ||
return err | ||
} | ||
return cmd.OutputFlag.Process(ctx) | ||
} | ||
|
||
type didpInfo struct { | ||
DefaultIdentitySource []string | ||
} | ||
|
||
func (r *didpInfo) Write(w io.Writer) error { | ||
fmt.Fprintf(w, "Default identity provider source(s): %s\n", strings.Join(r.DefaultIdentitySource, ",")) | ||
return nil | ||
} | ||
|
||
func (cmd *didp) Run(ctx context.Context, f *flag.FlagSet) error { | ||
return sso.WithClient(ctx, cmd.ClientFlag, func(c *ssoadmin.Client) error { | ||
var errids error | ||
var defaultids didpInfo | ||
|
||
defaultids.DefaultIdentitySource, errids = c.GetDefaultDomains(ctx) | ||
if errids != nil { | ||
return errids | ||
} | ||
return cmd.WriteResult(&defaultids) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright (c) 2023-2023 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 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package idp | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
|
||
"github.com/vmware/govmomi/govc/cli" | ||
"github.com/vmware/govmomi/govc/flags" | ||
"github.com/vmware/govmomi/govc/sso" | ||
"github.com/vmware/govmomi/ssoadmin" | ||
) | ||
|
||
type didpupd struct { | ||
*flags.ClientFlag | ||
} | ||
|
||
func init() { | ||
cli.Register("sso.idp.default.update", &didpupd{}) | ||
} | ||
|
||
func (cmd *didpupd) Register(ctx context.Context, f *flag.FlagSet) { | ||
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) | ||
cmd.ClientFlag.Register(ctx, f) | ||
} | ||
|
||
func (cmd *didpupd) Usage() string { | ||
return "NAME" | ||
} | ||
|
||
func (cmd *didpupd) Description() string { | ||
return `Set SSO default identity provider source. | ||
Examples: | ||
govc sso.idp.default.update NAME` | ||
} | ||
|
||
func (cmd *didpupd) Run(ctx context.Context, f *flag.FlagSet) error { | ||
return sso.WithClient(ctx, cmd.ClientFlag, func(c *ssoadmin.Client) error { | ||
return c.SetDefaultDomains(ctx, f.Arg(0)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters