Skip to content

Commit

Permalink
FR-13836: super user support (#120)
Browse files Browse the repository at this point in the history
* super user support

* super user support

* super user support

* fix

* formatting

* formatting
  • Loading branch information
raz-shlomo-frontegg authored Oct 25, 2023
1 parent 5f6c209 commit 44c4573
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Configures a Frontegg user.
- `automatically_verify` (Boolean) Whether the user gets verified upon creation.
- `password` (String, Sensitive) The user's login password.
- `skip_invite_email` (Boolean) Skip sending the invite email. If true, user is automatically verified on creation.
- `superuser` (Boolean) Whether the user is a super user.

### Read-Only

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
Expand Down Expand Up @@ -182,6 +183,7 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mitchellh/cli v1.1.4 h1:qj8czE26AU4PbiaPXK5uVmMSM+V5BYsFBiM9HhGRLUA=
github.com/mitchellh/cli v1.1.4/go.mod h1:vTLESy5mRhKOs9KDp0/RATawxP1UqBmdrpVRMnpcvKQ=
github.com/mitchellh/cli v1.1.5 h1:OxRIeJXpAMztws/XHlN2vu6imG5Dpq+j61AzAX5fLng=
github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
Expand Down
33 changes: 33 additions & 0 deletions provider/resource_frontegg_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

type fronteggSuperUser struct {
SuperUser bool `json:"superUser"`
}

type fronteggUserRole struct {
Id string `json:"id,omitempty"`
Key string `json:"key,omitempty"`
Expand All @@ -24,6 +28,7 @@ type fronteggUser struct {
ReadRoleIDs []fronteggUserRole `json:"roles,omitempty"`
SkipInviteEmail bool `json:"skipInviteEmail,omitempty"`
Verified bool `json:"verified,omitempty"`
SuperUser bool `json:"superUser,omitempty"`
}

const fronteggUserPath = "/identity/resources/users/v2"
Expand Down Expand Up @@ -77,6 +82,11 @@ func resourceFronteggUser() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"superuser": {
Description: "Whether the user is a super user.",
Type: schema.TypeBool,
Optional: true,
},
},
}
}
Expand All @@ -88,6 +98,7 @@ func resourceFronteggUserSerialize(d *schema.ResourceData) fronteggUser {
Password: d.Get("password").(string),
SkipInviteEmail: d.Get("skip_invite_email").(bool),
CreateRoleIDs: d.Get("role_ids").(*schema.Set).List(),
SuperUser: d.Get("superuser").(bool),
}
}

Expand Down Expand Up @@ -115,10 +126,21 @@ func resourceFronteggUserCreate(ctx context.Context, d *schema.ResourceData, met
if err := clientHolder.ApiClient.RequestWithHeaders(ctx, "POST", fronteggUserPath, headers, in, &out); err != nil {
return diag.FromErr(err)
}

if err := resourceFronteggUserDeserialize(d, out); err != nil {
return diag.FromErr(err)
}

superUser := d.Get("superuser").(bool)
if superUser {
in := fronteggSuperUser{
SuperUser: superUser,
}
if err := clientHolder.ApiClient.Put(ctx, fmt.Sprintf("%s/%s/superuser", fronteggUserPathV1, out.Key), in, nil); err != nil {
return diag.FromErr(err)
}
}

if !d.Get("automatically_verify").(bool) {
return nil
}
Expand Down Expand Up @@ -197,6 +219,17 @@ func resourceFronteggUserUpdate(ctx context.Context, d *schema.ResourceData, met
}
}

// Super User:
if d.HasChange("superuser") {
superUser := d.Get("superuser").(bool)
in := fronteggSuperUser{
SuperUser: superUser,
}
if err := clientHolder.ApiClient.Put(ctx, fmt.Sprintf("%s/%s/superuser", fronteggUserPathV1, d.Id()), in, nil); err != nil {
return diag.FromErr(err)
}
}

// Roles:
if d.HasChange("role_ids") {
headers := http.Header{}
Expand Down

0 comments on commit 44c4573

Please sign in to comment.