-
Notifications
You must be signed in to change notification settings - Fork 943
chore: add cli command to fetch group sync settings as json #14694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6a59ee1
chore: add cli command to fetch group sync settings as json
Emyrk 4e0146f
linting
Emyrk 87b9c45
work on cli test
Emyrk 6225ddf
chore add unit test for role sync
Emyrk c048019
linting
Emyrk 5bdbd39
linting
Emyrk c4482e6
update golden files
Emyrk ec78d00
make cobra sub commands
Emyrk 3dc174f
make gen
Emyrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
chore: add cli command to fetch group sync settings as json
- Loading branch information
commit 6a59ee11636821a83e3b143d24cd5e5ce4ea5be6
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 @@ | ||
package cli | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/serpent" | ||
) | ||
|
||
func (r *RootCmd) organizationSettings(orgContext *OrganizationContext) *serpent.Command { | ||
cmd := &serpent.Command{ | ||
Use: "settings", | ||
Short: "Manage organization settings.", | ||
Aliases: []string{"setting"}, | ||
Handler: func(inv *serpent.Invocation) error { | ||
return inv.Command.HelpHandler(inv) | ||
}, | ||
Hidden: true, | ||
Children: []*serpent.Command{ | ||
r.printOrganizationSetting(orgContext), | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func (r *RootCmd) printOrganizationSetting(orgContext *OrganizationContext) *serpent.Command { | ||
client := new(codersdk.Client) | ||
cmd := &serpent.Command{ | ||
Use: "show <groupsync | rolesync>", | ||
Short: "Outputs specified organization setting.", | ||
Long: FormatExamples( | ||
Example{ | ||
Description: "Output group sync settings.", | ||
Command: "coder organization settings show groupsync", | ||
}, | ||
), | ||
Options: []serpent.Option{}, | ||
Middleware: serpent.Chain( | ||
serpent.RequireNArgs(1), | ||
r.InitClient(client), | ||
), | ||
Handler: func(inv *serpent.Invocation) error { | ||
ctx := inv.Context() | ||
org, err := orgContext.Selected(inv, client) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var setting any | ||
switch strings.ToLower(inv.Args[0]) { | ||
Emyrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case "groupsync", "group-sync": | ||
setting, err = client.GroupIDPSyncSettings(ctx, org.ID.String()) | ||
case "rolesync", "role-sync": | ||
// TODO: Implement role sync settings. | ||
return fmt.Errorf("role sync settings are not implemented") | ||
default: | ||
_, _ = fmt.Fprintln(inv.Stderr, "Valid organization settings are: 'groupsync', 'rolesync'") | ||
return fmt.Errorf("unknown organization setting %s", inv.Args[0]) | ||
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to get organization setting %s: %w", inv.Args[0], err) | ||
} | ||
|
||
settingJson, err := json.Marshal(setting) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal organization setting %s: %w", inv.Args[0], err) | ||
} | ||
|
||
var dst bytes.Buffer | ||
err = json.Indent(&dst, settingJson, "", "\t") | ||
if err != nil { | ||
return fmt.Errorf("failed to indent organization setting as json %s: %w", inv.Args[0], err) | ||
} | ||
|
||
_, err = fmt.Fprintln(inv.Stdout, dst.String()) | ||
return err | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.