forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source_github_organization_repository_roles.go
More file actions
84 lines (74 loc) · 2.24 KB
/
data_source_github_organization_repository_roles.go
File metadata and controls
84 lines (74 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package github
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceGithubOrganizationRepositoryRoles() *schema.Resource {
return &schema.Resource{
Description: "Lookup all custom repository roles in an organization.",
Read: dataSourceGithubOrganizationRepositoryRolesRead,
Schema: map[string]*schema.Schema{
"roles": {
Description: "Available organization repository roles.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"role_id": {
Description: "The ID of the organization repository role.",
Type: schema.TypeInt,
Computed: true,
},
"name": {
Description: "The name of the organization repository role.",
Type: schema.TypeString,
Computed: true,
},
"description": {
Description: "The description of the organization repository role.",
Type: schema.TypeString,
Computed: true,
},
"base_role": {
Description: "The system role from which this role inherits permissions.",
Type: schema.TypeString,
Computed: true,
},
"permissions": {
Description: "The permissions included in this role.",
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
},
},
},
},
}
}
func dataSourceGithubOrganizationRepositoryRolesRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Owner).v3client
ctx := context.Background()
orgName := meta.(*Owner).name
ret, _, err := client.Organizations.ListCustomRepoRoles(ctx, orgName)
if err != nil {
return err
}
allRoles := make([]any, ret.GetTotalCount())
for i, role := range ret.CustomRepoRoles {
r := map[string]any{
"role_id": role.GetID(),
"name": role.GetName(),
"description": role.GetDescription(),
"base_role": role.GetBaseRole(),
"permissions": role.Permissions,
}
allRoles[i] = r
}
d.SetId(fmt.Sprintf("%s/github-org-repo-roles", orgName))
if err := d.Set("roles", allRoles); err != nil {
return fmt.Errorf("error setting roles: %s", err)
}
return nil
}