@@ -15,17 +15,38 @@ import (
1515// SyncRule defines how to sync Okta groups to GitHub teams.
1616type SyncRule struct {
1717 Name string `json:"name"`
18- Enabled bool `json:"enabled"`
18+ Enabled * bool `json:"enabled,omitempty "`
1919 OktaGroupPattern string `json:"okta_group_pattern,omitempty"`
2020 OktaGroupName string `json:"okta_group_name,omitempty"`
2121 GitHubTeamPrefix string `json:"github_team_prefix,omitempty"`
2222 GitHubTeamName string `json:"github_team_name,omitempty"`
2323 StripPrefix string `json:"strip_prefix,omitempty"`
24- SyncMembers bool `json:"sync_members"`
24+ SyncMembers * bool `json:"sync_members,omitempty "`
2525 CreateTeamIfMissing bool `json:"create_team_if_missing"`
2626 TeamPrivacy string `json:"team_privacy,omitempty"`
2727}
2828
29+ // IsEnabled returns true if the rule is enabled (defaults to true).
30+ func (r SyncRule ) IsEnabled () bool {
31+ return r .Enabled == nil || * r .Enabled
32+ }
33+
34+ // ShouldSyncMembers returns true if members should be synced (defaults to true).
35+ func (r SyncRule ) ShouldSyncMembers () bool {
36+ return r .SyncMembers == nil || * r .SyncMembers
37+ }
38+
39+ // GetName returns the rule name, defaulting to GitHubTeamName if not set.
40+ func (r SyncRule ) GetName () string {
41+ if r .Name != "" {
42+ return r .Name
43+ }
44+ if r .GitHubTeamName != "" {
45+ return r .GitHubTeamName
46+ }
47+ return r .OktaGroupName
48+ }
49+
2950// SyncReport contains the results of syncing a single Okta group to GitHub
3051// team.
3152type SyncReport struct {
@@ -88,16 +109,16 @@ func (s *Syncer) Sync(ctx context.Context) (*SyncResult, error) {
88109 var syncErrors []string
89110
90111 for _ , rule := range s .rules {
91- if ! rule .Enabled {
112+ if ! rule .IsEnabled () {
92113 continue
93114 }
94115
95116 ruleReports , err := s .syncRule (ctx , rule )
96117 if err != nil {
97- errMsg := fmt .Sprintf ("rule '%s' failed: %v" , rule .Name , err )
118+ errMsg := fmt .Sprintf ("rule '%s' failed: %v" , rule .GetName () , err )
98119 syncErrors = append (syncErrors , errMsg )
99120 s .logger .Error ("sync rule failed" ,
100- slog .String ("rule" , rule .Name ),
121+ slog .String ("rule" , rule .GetName () ),
101122 slog .String ("error" , err .Error ()))
102123 continue
103124 }
@@ -216,7 +237,7 @@ func (s *Syncer) computeTeamName(oktaGroupName string, rule SyncRule) string {
216237// creates team if missing and syncs members if enabled.
217238func (s * Syncer ) syncGroupToTeam (ctx context.Context , rule SyncRule , group * GroupInfo , teamName string ) * SyncReport {
218239 report := & SyncReport {
219- Rule : rule .Name ,
240+ Rule : rule .GetName () ,
220241 OktaGroup : group .Name ,
221242 GitHubTeam : teamName ,
222243 MembersSkippedNoGHUsername : group .SkippedNoGitHubUsername ,
@@ -247,7 +268,7 @@ func (s *Syncer) syncGroupToTeam(ctx context.Context, rule SyncRule, group *Grou
247268 return report
248269 }
249270
250- if ! rule .SyncMembers {
271+ if ! rule .ShouldSyncMembers () {
251272 return report
252273 }
253274
0 commit comments