这是indexloc提供的服务,不要输入任何密码
Skip to content

[vercel_team_config] Fix saml dsync for access groups #298

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 10 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions client/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ type SamlRoleAccessGroupID struct {
AccessGroupID string `json:"accessGroupId"`
}

type SamlRole struct {
type SamlRoleAPI struct {
Role *string
AccessGroupID *SamlRoleAccessGroupID
}

func (f *SamlRole) UnmarshalJSON(data []byte) error {
type SamlRolesAPI map[string]SamlRoleAPI

type SamlRole struct {
Role *string `json:"role"`
AccessGroupID *string `json:"accessGroupId"`
}

type SamlRoles map[string]SamlRole

func (f *SamlRoleAPI) UnmarshalJSON(data []byte) error {
var role string
if err := json.Unmarshal(data, &role); err == nil {
f.Role = &role
Expand All @@ -38,10 +47,8 @@ func (f *SamlRole) UnmarshalJSON(data []byte) error {
return fmt.Errorf("received json is neither Role string nor AccessGroupID map")
}

type SamlRoles map[string]string

func (f *SamlRoles) UnmarshalJSON(data []byte) error {
var result map[string]SamlRole
var result SamlRolesAPI
if err := json.Unmarshal(data, &result); err != nil {
return err
}
Expand All @@ -50,7 +57,14 @@ func (f *SamlRoles) UnmarshalJSON(data []byte) error {
k := k
v := v
if v.Role != nil {
tmp[k] = *(v.Role)
tmp[k] = SamlRole{
Role: v.Role,
}
}
if v.AccessGroupID != nil {
tmp[k] = SamlRole{
AccessGroupID: &v.AccessGroupID.AccessGroupID,
}
}
}
*f = tmp
Expand Down Expand Up @@ -119,9 +133,37 @@ func (c *Client) GetTeam(ctx context.Context, idOrSlug string) (t Team, err erro
return t, err
}

type UpdateSamlConfigRole struct {
Role *string `json:"role"`
AccessGroupID *string `json:"accessGroupId"`
}

type UpdateSamlConfig struct {
Enforced bool `json:"enforced"`
Roles map[string]string `json:"roles"`
Enforced bool `json:"enforced"`
Roles map[string]UpdateSamlConfigRole `json:"roles"`
}

func (r *UpdateSamlConfig) MarshalJSON() ([]byte, error) {
roles := map[string]any{}
for k, v := range r.Roles {
if v.Role != nil && v.AccessGroupID != nil {
return nil, fmt.Errorf("bad union")
}
if v.Role != nil {
roles[k] = v.Role
} else if v.AccessGroupID != nil {
roles[k] = map[string]any{
"accessGroupId": v.AccessGroupID,
}
} else {
return nil, fmt.Errorf("bad union")
}

}
return json.Marshal(map[string]any{
"enforced": r.Enforced,
"roles": roles,
})
}

type UpdateTeamRequest struct {
Expand Down
11 changes: 9 additions & 2 deletions docs/data-sources/team_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ Read-Only:

Read-Only:

- `access_group_id` (String) The ID of the access group to use for the team.
- `enforced` (Boolean) Indicates if SAML is enforced for the team.
- `roles` (Map of String) Directory groups to role or access group mappings.
- `roles` (Attributes Map) Directory groups to role or access group mappings. For each directory group, either a role or access group id is specified. (see [below for nested schema](#nestedatt--saml--roles))

<a id="nestedatt--saml--roles"></a>
### Nested Schema for `saml.roles`

Read-Only:

- `access_group_id` (String) The access group the assign is assigned to.
- `role` (String) The team level role the user is assigned. One of 'MEMBER', 'OWNER', 'VIEWER', 'DEVELOPER', 'BILLING' or 'CONTRIBUTOR'.
11 changes: 9 additions & 2 deletions docs/resources/team_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,12 @@ Required:

Optional:

- `access_group_id` (String) The ID of the access group to use for the team.
- `roles` (Map of String) Directory groups to role or access group mappings.
- `roles` (Attributes Map) Directory groups to role or access group mappings. For each directory group, specify either a role or access group id. (see [below for nested schema](#nestedatt--saml--roles))

<a id="nestedatt--saml--roles"></a>
### Nested Schema for `saml.roles`

Optional:

- `access_group_id` (String) The access group id to assign to the user.
- `role` (String) The team level role to assign to the user. One of 'MEMBER', 'OWNER', 'VIEWER', 'DEVELOPER', 'BILLING' or 'CONTRIBUTOR'.
21 changes: 14 additions & 7 deletions vercel/data_source_team_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,21 @@ func (d *teamConfigDataSource) Schema(_ context.Context, _ datasource.SchemaRequ
Description: "Indicates if SAML is enforced for the team.",
Computed: true,
},
"roles": schema.MapAttribute{
Description: "Directory groups to role or access group mappings.",
Computed: true,
ElementType: types.StringType,
},
"access_group_id": schema.StringAttribute{
Description: "The ID of the access group to use for the team.",
"roles": schema.MapNestedAttribute{
Description: "Directory groups to role or access group mappings. For each directory group, either a role or access group id is specified.",
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"role": schema.StringAttribute{
Description: "The team level role the user is assigned. One of 'MEMBER', 'OWNER', 'VIEWER', 'DEVELOPER', 'BILLING' or 'CONTRIBUTOR'.",
Computed: true,
},
"access_group_id": schema.StringAttribute{
Description: "The access group the assign is assigned to.",
Computed: true,
},
},
},
},
},
Computed: true,
Expand Down
Loading
Loading