Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a59ee1

Browse files
committed
chore: add cli command to fetch group sync settings as json
1 parent45420b9 commit6a59ee1

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

‎cli/organization.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func (r *RootCmd) organizations() *serpent.Command {
2626
r.createOrganization(),
2727
r.organizationMembers(orgContext),
2828
r.organizationRoles(orgContext),
29+
r.organizationSettings(orgContext),
2930
},
3031
}
3132

‎cli/organizationsettings.go‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package cli
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"strings"
8+
9+
"github.com/coder/coder/v2/codersdk"
10+
"github.com/coder/serpent"
11+
)
12+
13+
func (r*RootCmd)organizationSettings(orgContext*OrganizationContext)*serpent.Command {
14+
cmd:=&serpent.Command{
15+
Use:"settings",
16+
Short:"Manage organization settings.",
17+
Aliases: []string{"setting"},
18+
Handler:func(inv*serpent.Invocation)error {
19+
returninv.Command.HelpHandler(inv)
20+
},
21+
Hidden:true,
22+
Children: []*serpent.Command{
23+
r.printOrganizationSetting(orgContext),
24+
},
25+
}
26+
returncmd
27+
}
28+
29+
func (r*RootCmd)printOrganizationSetting(orgContext*OrganizationContext)*serpent.Command {
30+
client:=new(codersdk.Client)
31+
cmd:=&serpent.Command{
32+
Use:"show <groupsync | rolesync>",
33+
Short:"Outputs specified organization setting.",
34+
Long:FormatExamples(
35+
Example{
36+
Description:"Output group sync settings.",
37+
Command:"coder organization settings show groupsync",
38+
},
39+
),
40+
Options: []serpent.Option{},
41+
Middleware:serpent.Chain(
42+
serpent.RequireNArgs(1),
43+
r.InitClient(client),
44+
),
45+
Handler:func(inv*serpent.Invocation)error {
46+
ctx:=inv.Context()
47+
org,err:=orgContext.Selected(inv,client)
48+
iferr!=nil {
49+
returnerr
50+
}
51+
52+
varsettingany
53+
switchstrings.ToLower(inv.Args[0]) {
54+
case"groupsync","group-sync":
55+
setting,err=client.GroupIDPSyncSettings(ctx,org.ID.String())
56+
case"rolesync","role-sync":
57+
// TODO: Implement role sync settings.
58+
returnfmt.Errorf("role sync settings are not implemented")
59+
default:
60+
_,_=fmt.Fprintln(inv.Stderr,"Valid organization settings are: 'groupsync', 'rolesync'")
61+
returnfmt.Errorf("unknown organization setting %s",inv.Args[0])
62+
}
63+
64+
iferr!=nil {
65+
returnfmt.Errorf("failed to get organization setting %s: %w",inv.Args[0],err)
66+
}
67+
68+
settingJson,err:=json.Marshal(setting)
69+
iferr!=nil {
70+
returnfmt.Errorf("failed to marshal organization setting %s: %w",inv.Args[0],err)
71+
}
72+
73+
vardst bytes.Buffer
74+
err=json.Indent(&dst,settingJson,"","\t")
75+
iferr!=nil {
76+
returnfmt.Errorf("failed to indent organization setting as json %s: %w",inv.Args[0],err)
77+
}
78+
79+
_,err=fmt.Fprintln(inv.Stdout,dst.String())
80+
returnerr
81+
},
82+
}
83+
returncmd
84+
}

‎cli/root.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"golang.org/x/mod/semver"
3030
"golang.org/x/xerrors"
3131

32+
"github.com/coder/coder/v2/coderd/database/db2sdk"
3233
"github.com/coder/pretty"
3334

3435
"github.com/coder/coder/v2/buildinfo"
@@ -657,7 +658,10 @@ func (o *OrganizationContext) Selected(inv *serpent.Invocation, client *codersdk
657658
}
658659

659660
// No org selected, and we are more than 1? Return an error.
660-
return codersdk.Organization{},xerrors.Errorf("Must select an organization with --org=<org_name>.")
661+
validOrgs:=db2sdk.List(orgs,func(org codersdk.Organization)string {
662+
returnfmt.Sprintf("%q",org.Name)
663+
})
664+
return codersdk.Organization{},xerrors.Errorf("Must select an organization with --org=<org_name>. Choose from: %s",strings.Join(validOrgs,", "))
661665
}
662666

663667
funcsplitNamedWorkspace(identifierstring) (ownerstring,workspaceNamestring,errerror) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp