Skip to content

Commit 615a000

Browse files
refactor: Use go-github v81 native SCIM types and remove excludedAttributes
- Replace local SCIM types with github.SCIMEnterprise* from go-github v81 - Remove enterpriseSCIMListURL, enterpriseSCIMGet helper functions - Use client.Enterprise.ListProvisionedSCIMGroups/Users directly - Remove excluded_attributes parameter from all data sources - Fix GitHub brand name capitalization in documentation - Update tests to match new API calls
1 parent 974f0be commit 615a000

13 files changed

+165
-297
lines changed

github/data_source_github_enterprise_scim_group.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ func dataSourceGithubEnterpriseSCIMGroup() *schema.Resource {
2424
Type: schema.TypeString,
2525
Required: true,
2626
},
27-
"excluded_attributes": {
28-
Description: "Optional SCIM excludedAttributes query parameter.",
29-
Type: schema.TypeString,
30-
Optional: true,
31-
},
3227

3328
"schemas": {
3429
Type: schema.TypeList,
@@ -72,26 +67,24 @@ func dataSourceGithubEnterpriseSCIMGroupRead(ctx context.Context, d *schema.Reso
7267

7368
enterprise := d.Get("enterprise").(string)
7469
scimGroupID := d.Get("scim_group_id").(string)
75-
excluded := d.Get("excluded_attributes").(string)
7670

77-
path := fmt.Sprintf("scim/v2/enterprises/%s/Groups/%s", enterprise, scimGroupID)
78-
urlStr, err := enterpriseSCIMListURL(path, enterpriseSCIMListOptions{ExcludedAttributes: excluded})
79-
if err != nil {
80-
return diag.FromErr(err)
81-
}
82-
83-
group := enterpriseSCIMGroup{}
84-
_, err = enterpriseSCIMGet(ctx, client, urlStr, &group)
71+
group, _, err := client.Enterprise.GetProvisionedSCIMGroup(ctx, enterprise, scimGroupID, nil)
8572
if err != nil {
8673
return diag.FromErr(err)
8774
}
8875

8976
d.SetId(fmt.Sprintf("%s/%s", enterprise, scimGroupID))
9077

9178
_ = d.Set("schemas", group.Schemas)
92-
_ = d.Set("id", group.ID)
93-
_ = d.Set("external_id", group.ExternalID)
94-
_ = d.Set("display_name", group.DisplayName)
79+
if group.ID != nil {
80+
_ = d.Set("id", *group.ID)
81+
}
82+
if group.ExternalID != nil {
83+
_ = d.Set("external_id", *group.ExternalID)
84+
}
85+
if group.DisplayName != nil {
86+
_ = d.Set("display_name", *group.DisplayName)
87+
}
9588
_ = d.Set("members", flattenEnterpriseSCIMGroupMembers(group.Members))
9689
_ = d.Set("meta", flattenEnterpriseSCIMMeta(group.Meta))
9790

github/data_source_github_enterprise_scim_group_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/url"
77
"testing"
88

9-
gh "github.com/google/go-github/v67/github"
9+
gh "github.com/google/go-github/v81/github"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111
)
1212

@@ -15,7 +15,7 @@ func TestDataSourceGithubEnterpriseSCIMGroupRead(t *testing.T) {
1515
{
1616
ExpectedUri: "/scim/v2/enterprises/ent/Groups/g1",
1717
ExpectedHeaders: map[string]string{
18-
"Accept": enterpriseSCIMAcceptHeader,
18+
"Accept": "application/scim+json",
1919
},
2020
StatusCode: 200,
2121
ResponseBody: `{
@@ -39,9 +39,8 @@ func TestDataSourceGithubEnterpriseSCIMGroupRead(t *testing.T) {
3939

4040
r := dataSourceGithubEnterpriseSCIMGroup()
4141
d := schema.TestResourceDataRaw(t, r.Schema, map[string]any{
42-
"enterprise": "ent",
43-
"scim_group_id": "g1",
44-
"excluded_attributes": "",
42+
"enterprise": "ent",
43+
"scim_group_id": "g1",
4544
})
4645

4746
diags := dataSourceGithubEnterpriseSCIMGroupRead(context.Background(), d, owner)

github/data_source_github_enterprise_scim_groups.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ func dataSourceGithubEnterpriseSCIMGroups() *schema.Resource {
2626
Type: schema.TypeString,
2727
Optional: true,
2828
},
29-
"excluded_attributes": {
30-
Description: "Optional SCIM excludedAttributes query parameter.",
31-
Type: schema.TypeString,
32-
Optional: true,
33-
},
3429
"results_per_page": {
3530
Description: "Number of results per request (mapped to SCIM 'count'). Used while auto-fetching all pages.",
3631
Type: schema.TypeInt,
@@ -77,10 +72,9 @@ func dataSourceGithubEnterpriseSCIMGroupsRead(ctx context.Context, d *schema.Res
7772

7873
enterprise := d.Get("enterprise").(string)
7974
filter := d.Get("filter").(string)
80-
excluded := d.Get("excluded_attributes").(string)
8175
count := d.Get("results_per_page").(int)
8276

83-
groups, first, err := enterpriseSCIMListAllGroups(ctx, client, enterprise, filter, excluded, count)
77+
groups, first, err := enterpriseSCIMListAllGroups(ctx, client, enterprise, filter, count)
8478
if err != nil {
8579
return diag.FromErr(err)
8680
}
@@ -94,25 +88,20 @@ func dataSourceGithubEnterpriseSCIMGroupsRead(ctx context.Context, d *schema.Res
9488
if filter != "" {
9589
id = fmt.Sprintf("%s?filter=%s", id, url.QueryEscape(filter))
9690
}
97-
if excluded != "" {
98-
if filter == "" {
99-
id = fmt.Sprintf("%s?excluded_attributes=%s", id, url.QueryEscape(excluded))
100-
} else {
101-
id = fmt.Sprintf("%s&excluded_attributes=%s", id, url.QueryEscape(excluded))
102-
}
103-
}
10491

10592
d.SetId(id)
10693

10794
_ = d.Set("schemas", first.Schemas)
108-
_ = d.Set("total_results", first.TotalResults)
109-
if first.StartIndex > 0 {
110-
_ = d.Set("start_index", first.StartIndex)
95+
if first.TotalResults != nil {
96+
_ = d.Set("total_results", *first.TotalResults)
97+
}
98+
if first.StartIndex != nil && *first.StartIndex > 0 {
99+
_ = d.Set("start_index", *first.StartIndex)
111100
} else {
112101
_ = d.Set("start_index", 1)
113102
}
114-
if first.ItemsPerPage > 0 {
115-
_ = d.Set("items_per_page", first.ItemsPerPage)
103+
if first.ItemsPerPage != nil && *first.ItemsPerPage > 0 {
104+
_ = d.Set("items_per_page", *first.ItemsPerPage)
116105
} else {
117106
_ = d.Set("items_per_page", count)
118107
}

github/data_source_github_enterprise_scim_groups_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/url"
77
"testing"
88

9-
gh "github.com/google/go-github/v67/github"
9+
gh "github.com/google/go-github/v81/github"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111
)
1212

@@ -15,7 +15,7 @@ func TestDataSourceGithubEnterpriseSCIMGroupsRead_fetchAllPages(t *testing.T) {
1515
{
1616
ExpectedUri: "/scim/v2/enterprises/ent/Groups?count=2&startIndex=1",
1717
ExpectedHeaders: map[string]string{
18-
"Accept": enterpriseSCIMAcceptHeader,
18+
"Accept": "application/scim+json",
1919
},
2020
StatusCode: 200,
2121
ResponseBody: `{
@@ -32,7 +32,7 @@ func TestDataSourceGithubEnterpriseSCIMGroupsRead_fetchAllPages(t *testing.T) {
3232
{
3333
ExpectedUri: "/scim/v2/enterprises/ent/Groups?count=2&startIndex=3",
3434
ExpectedHeaders: map[string]string{
35-
"Accept": enterpriseSCIMAcceptHeader,
35+
"Accept": "application/scim+json",
3636
},
3737
StatusCode: 200,
3838
ResponseBody: `{
@@ -57,10 +57,9 @@ func TestDataSourceGithubEnterpriseSCIMGroupsRead_fetchAllPages(t *testing.T) {
5757

5858
r := dataSourceGithubEnterpriseSCIMGroups()
5959
d := schema.TestResourceDataRaw(t, r.Schema, map[string]any{
60-
"enterprise": "ent",
61-
"results_per_page": 2,
62-
"filter": "",
63-
"excluded_attributes": "",
60+
"enterprise": "ent",
61+
"results_per_page": 2,
62+
"filter": "",
6463
})
6564

6665
diags := dataSourceGithubEnterpriseSCIMGroupsRead(context.Background(), d, owner)

github/data_source_github_enterprise_scim_user.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ func dataSourceGithubEnterpriseSCIMUser() *schema.Resource {
2424
Type: schema.TypeString,
2525
Required: true,
2626
},
27-
"excluded_attributes": {
28-
Description: "Optional SCIM excludedAttributes query parameter.",
29-
Type: schema.TypeString,
30-
Optional: true,
31-
},
3227

3328
"schemas": {
3429
Type: schema.TypeList,
@@ -94,24 +89,18 @@ func dataSourceGithubEnterpriseSCIMUserRead(ctx context.Context, d *schema.Resou
9489

9590
enterprise := d.Get("enterprise").(string)
9691
scimUserID := d.Get("scim_user_id").(string)
97-
excluded := d.Get("excluded_attributes").(string)
9892

99-
path := fmt.Sprintf("scim/v2/enterprises/%s/Users/%s", enterprise, scimUserID)
100-
urlStr, err := enterpriseSCIMListURL(path, enterpriseSCIMListOptions{ExcludedAttributes: excluded})
101-
if err != nil {
102-
return diag.FromErr(err)
103-
}
104-
105-
user := enterpriseSCIMUser{}
106-
_, err = enterpriseSCIMGet(ctx, client, urlStr, &user)
93+
user, _, err := client.Enterprise.GetProvisionedSCIMUser(ctx, enterprise, scimUserID)
10794
if err != nil {
10895
return diag.FromErr(err)
10996
}
11097

11198
d.SetId(fmt.Sprintf("%s/%s", enterprise, scimUserID))
11299

113100
_ = d.Set("schemas", user.Schemas)
114-
_ = d.Set("id", user.ID)
101+
if user.ID != nil {
102+
_ = d.Set("id", *user.ID)
103+
}
115104
_ = d.Set("external_id", user.ExternalID)
116105
_ = d.Set("user_name", user.UserName)
117106
_ = d.Set("display_name", user.DisplayName)

github/data_source_github_enterprise_scim_user_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/url"
77
"testing"
88

9-
gh "github.com/google/go-github/v67/github"
9+
gh "github.com/google/go-github/v81/github"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111
)
1212

@@ -15,7 +15,7 @@ func TestDataSourceGithubEnterpriseSCIMUserRead(t *testing.T) {
1515
{
1616
ExpectedUri: "/scim/v2/enterprises/ent/Users/u1",
1717
ExpectedHeaders: map[string]string{
18-
"Accept": enterpriseSCIMAcceptHeader,
18+
"Accept": "application/scim+json",
1919
},
2020
StatusCode: 200,
2121
ResponseBody: `{
@@ -43,9 +43,8 @@ func TestDataSourceGithubEnterpriseSCIMUserRead(t *testing.T) {
4343

4444
r := dataSourceGithubEnterpriseSCIMUser()
4545
d := schema.TestResourceDataRaw(t, r.Schema, map[string]any{
46-
"enterprise": "ent",
47-
"scim_user_id": "u1",
48-
"excluded_attributes": "",
46+
"enterprise": "ent",
47+
"scim_user_id": "u1",
4948
})
5049

5150
diags := dataSourceGithubEnterpriseSCIMUserRead(context.Background(), d, owner)

github/data_source_github_enterprise_scim_users.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ func dataSourceGithubEnterpriseSCIMUsers() *schema.Resource {
2626
Type: schema.TypeString,
2727
Optional: true,
2828
},
29-
"excluded_attributes": {
30-
Description: "Optional SCIM excludedAttributes query parameter.",
31-
Type: schema.TypeString,
32-
Optional: true,
33-
},
3429
"results_per_page": {
3530
Description: "Number of results per request (mapped to SCIM 'count'). Used while auto-fetching all pages.",
3631
Type: schema.TypeInt,
@@ -77,10 +72,9 @@ func dataSourceGithubEnterpriseSCIMUsersRead(ctx context.Context, d *schema.Reso
7772

7873
enterprise := d.Get("enterprise").(string)
7974
filter := d.Get("filter").(string)
80-
excluded := d.Get("excluded_attributes").(string)
8175
count := d.Get("results_per_page").(int)
8276

83-
users, first, err := enterpriseSCIMListAllUsers(ctx, client, enterprise, filter, excluded, count)
77+
users, first, err := enterpriseSCIMListAllUsers(ctx, client, enterprise, filter, count)
8478
if err != nil {
8579
return diag.FromErr(err)
8680
}
@@ -94,25 +88,20 @@ func dataSourceGithubEnterpriseSCIMUsersRead(ctx context.Context, d *schema.Reso
9488
if filter != "" {
9589
id = fmt.Sprintf("%s?filter=%s", id, url.QueryEscape(filter))
9690
}
97-
if excluded != "" {
98-
if filter == "" {
99-
id = fmt.Sprintf("%s?excluded_attributes=%s", id, url.QueryEscape(excluded))
100-
} else {
101-
id = fmt.Sprintf("%s&excluded_attributes=%s", id, url.QueryEscape(excluded))
102-
}
103-
}
10491

10592
d.SetId(id)
10693

10794
_ = d.Set("schemas", first.Schemas)
108-
_ = d.Set("total_results", first.TotalResults)
109-
if first.StartIndex > 0 {
110-
_ = d.Set("start_index", first.StartIndex)
95+
if first.TotalResults != nil {
96+
_ = d.Set("total_results", *first.TotalResults)
97+
}
98+
if first.StartIndex != nil && *first.StartIndex > 0 {
99+
_ = d.Set("start_index", *first.StartIndex)
111100
} else {
112101
_ = d.Set("start_index", 1)
113102
}
114-
if first.ItemsPerPage > 0 {
115-
_ = d.Set("items_per_page", first.ItemsPerPage)
103+
if first.ItemsPerPage != nil && *first.ItemsPerPage > 0 {
104+
_ = d.Set("items_per_page", *first.ItemsPerPage)
116105
} else {
117106
_ = d.Set("items_per_page", count)
118107
}

github/data_source_github_enterprise_scim_users_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import (
66
"net/url"
77
"testing"
88

9-
gh "github.com/google/go-github/v67/github"
9+
gh "github.com/google/go-github/v81/github"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111
)
1212

1313
func TestDataSourceGithubEnterpriseSCIMUsersRead_fetchAllPages_withFilter(t *testing.T) {
1414
filter := "userName eq \"test\""
1515
ts := githubApiMock([]*mockResponse{
1616
{
17-
ExpectedUri: "/scim/v2/enterprises/ent/Users?count=2&excludedAttributes=members&filter=userName+eq+%22test%22&startIndex=1",
17+
ExpectedUri: "/scim/v2/enterprises/ent/Users?count=2&filter=userName+eq+%22test%22&startIndex=1",
1818
ExpectedHeaders: map[string]string{
19-
"Accept": enterpriseSCIMAcceptHeader,
19+
"Accept": "application/scim+json",
2020
},
2121
StatusCode: 200,
2222
ResponseBody: `{
@@ -31,9 +31,9 @@ func TestDataSourceGithubEnterpriseSCIMUsersRead_fetchAllPages_withFilter(t *tes
3131
}`,
3232
},
3333
{
34-
ExpectedUri: "/scim/v2/enterprises/ent/Users?count=2&excludedAttributes=members&filter=userName+eq+%22test%22&startIndex=3",
34+
ExpectedUri: "/scim/v2/enterprises/ent/Users?count=2&filter=userName+eq+%22test%22&startIndex=3",
3535
ExpectedHeaders: map[string]string{
36-
"Accept": enterpriseSCIMAcceptHeader,
36+
"Accept": "application/scim+json",
3737
},
3838
StatusCode: 200,
3939
ResponseBody: `{
@@ -58,10 +58,9 @@ func TestDataSourceGithubEnterpriseSCIMUsersRead_fetchAllPages_withFilter(t *tes
5858

5959
r := dataSourceGithubEnterpriseSCIMUsers()
6060
d := schema.TestResourceDataRaw(t, r.Schema, map[string]any{
61-
"enterprise": "ent",
62-
"results_per_page": 2,
63-
"filter": filter,
64-
"excluded_attributes": "members",
61+
"enterprise": "ent",
62+
"results_per_page": 2,
63+
"filter": filter,
6564
})
6665

6766
diags := dataSourceGithubEnterpriseSCIMUsersRead(context.Background(), d, owner)

0 commit comments

Comments
 (0)