Skip to content

Commit

Permalink
user groups
Browse files Browse the repository at this point in the history
  • Loading branch information
gypsydiver committed Dec 13, 2018
1 parent c482dfa commit 9c16060
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions jumpcloud/resource_user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,45 @@ func resourceUserGroup() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"posix_group_id": {
Type: schema.TypeInt,
Optional: true,
},
"posix_group_name": {
Type: schema.TypeString,
Optional: true,
// ValidateFunc: // Group names may contain a maximum of sixteen alphanumeric characters and hyphens.
},
"enable_samba": {
Type: schema.TypeBool,
Optional: true,
},
"xorgid": {
Type: schema.TypeString,
Optional: true,
},
},
}
}

func resourceUserGroupCreate(d *schema.ResourceData, m interface{}) error {
client := m.(*jcapiv2.APIClient)

posixID := d.Get("posix_group_id").(int)
posixName := d.Get("posix_group_name").(string)

req := map[string]interface{}{
"body": jcapiv2.UserGroupPost{
Name: d.Get("name").(string),
Attributes: &jcapiv2.UserGroupPostAttributes{
// Note: PosixGroups cannot be edited after group creation
// Note: PosixGroups cannot be edited after group creation, only first member of slice is considered
PosixGroups: []jcapiv2.UserGroupPostAttributesPosixGroups{
// jcapiv2.UserGroupPostAttributesPosixGroups{Id:0, Name:"foo"}, TODO: add to/read from schema
jcapiv2.UserGroupPostAttributesPosixGroups{Id: int32(posixID), Name: posixName},
},
SambaEnabled: d.Get("enable_samba").(bool),
},
},
// "xOrgId": "", TODO: add to/read from schema
"xOrgId": d.Get("xorgid").(string),
}
group, res, err := client.UserGroupsApi.GroupsUserPost(context.TODO(), "", Accept, req)
if err != nil {
Expand Down Expand Up @@ -72,7 +89,7 @@ func resourceUserGroupUpdate(d *schema.ResourceData, m interface{}) error {
client := m.(*jcapiv2.APIClient)

body := jcapiv2.UserGroupPut{
Name: d.Get("name").(string), // Always set since it is a required value
Name: d.Get("name").(string), // Always set since it is a required value, and PUT is not supported by JCAPI
}

if d.HasChange("enable_samba") {
Expand All @@ -81,7 +98,7 @@ func resourceUserGroupUpdate(d *schema.ResourceData, m interface{}) error {
}
}

req := map[string]interface{}{"body": body, "xOrgId": ""} // TODO: xOrgId: add to/read from schema
req := map[string]interface{}{"body": body, "xOrgId": d.Get("xorgid").(string)}
_, _, err := client.UserGroupsApi.GroupsUserPut(context.TODO(), d.Id(), "", Accept, req)
if err != nil {
return err
Expand All @@ -95,7 +112,7 @@ func resourceUserGroupDelete(d *schema.ResourceData, m interface{}) error {
res, err := client.UserGroupsApi.GroupsUserDelete(context.TODO(), d.Id(), "", Accept, nil)
if err != nil {
// TODO: sort out error essentials
return fmt.Errorf("error deleting: %s - response = %+v", err, res)
return fmt.Errorf("error deleting user group: %s - response = %+v", err, res)
}
return nil
}

0 comments on commit 9c16060

Please sign in to comment.