Skip to content

Commit

Permalink
Feature/app v3 (#51)
Browse files Browse the repository at this point in the history
* Update readme and ci

* Add import for hpgroup

* feat(cidaas_app): adapt to cidaas v3
  • Loading branch information
EldoranDev authored Aug 1, 2023
1 parent 7eaa234 commit 206d76b
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.18' ]
go-version: [ '1.19' ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Terraform provider to manage and read resources from cidaas instances.


Currently developed against cidaas version `2.0.12`
Currently developed against cidaas version `3`

* [Usage documentation for the Provider can be found in the Terraform Registry](https://registry.terraform.io/providers/real-digital/cidaas/latest/docs)
* [Additional examples can be found in the `./examples` folder within this repository](https://github.com/real-digital/terraform-provider-cidaas/tree/main/examples).
* [Usage documentation for the Provider can be found in the Terraform Registry](https://registry.terraform.io/providers/kaufland-ecommerce/cidaas/latest/docs)
* [Additional examples can be found in the `./examples` folder within this repository](https://github.com/kaufland-ecommerce/terraform-provider-cidaas/tree/main/examples).
45 changes: 45 additions & 0 deletions internal/client/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,51 @@ func (c *client) CreateApp(app *App) (*App, error) {
response.Data.PasswordPolicy = nil
}

// App creation does not return those if they are empty on the initial creation
if response.Data.OperationsAllowedGroups == nil {
response.Data.OperationsAllowedGroups = []AllowedGroup{}
}

if response.Data.AllowedGroups == nil {
response.Data.AllowedGroups = []AllowedGroup{}
}

if response.Data.AllowedMfa == nil {
response.Data.AllowedMfa = []string{}
}

if response.Data.ConsentRefs == nil {
response.Data.ConsentRefs = []string{}
}

if response.Data.AllowedOrigins == nil {
response.Data.AllowedOrigins = []string{}
}

if response.Data.AllowedFields == nil {
response.Data.AllowedFields = []string{}
}

if response.Data.AllowedWebOrigins == nil {
response.Data.AllowedWebOrigins = []string{}
}

if response.Data.RequiredFields == nil {
response.Data.RequiredFields = []string{}
}

if response.Data.AdditionalAccessTokenPayload == nil {
response.Data.AdditionalAccessTokenPayload = []string{}
}

if response.Data.RedirectUris == nil {
response.Data.RedirectUris = []string{}
}

if response.Data.AllowedLogoutUrls == nil {
response.Data.AllowedLogoutUrls = []string{}
}

return &response.Data, nil
}

Expand Down
10 changes: 7 additions & 3 deletions internal/client/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ type AllowedGroup struct {
}

type App struct {
ID string `json:"id"`
ClientId string `json:"client_id"`
ClientSecret string `json:"client_secret"`
ID string `json:"id,omitempty"`
AcceptRolesInTheRegistration bool `json:"accept_roles_in_the_registration"`
ClientId string `json:"client_id,omitempty"`
ClientSecret string `json:"client_secret,omitempty"`
ClientName string `json:"client_name"`
ClientDisplayName string `json:"client_display_name"`
IsRememberMeSelected bool `json:"is_remember_me_selected"`
Expand Down Expand Up @@ -105,6 +106,8 @@ type App struct {
AlwaysAskMfa bool `json:"always_ask_mfa"`
PasswordPolicy *string `json:"password_policy_ref,omitempty"`
RegisterWithLoginInformation bool `json:"register_with_login_information"`
AppOwner string `json:"app_owner,omitempty"`
BotProvider string `json:"bot_provider,omitempty"`

AppKey *AppKey `json:"appKey,omitempty"`

Expand All @@ -124,6 +127,7 @@ type App struct {
AllowedWebOrigins []string `json:"allowed_web_origins"`
AllowedOrigins []string `json:"allowed_origins"`
AllowedMfa []string `json:"allowed_mfa"`
AllowedRoles []string `json:"allowed_roles"`
}

type RegistrationField struct {
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/data_source_social_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func (d socialProviderDataSource) Read(ctx context.Context, req datasource.ReadR
var state SocialProvider

diags := req.Config.GetAttribute(ctx, path.Root("provider_name"), &providerName)
resp.Diagnostics.Append(diags...)

diags = req.Config.GetAttribute(ctx, path.Root("name"), &name)

resp.Diagnostics.Append(diags...)
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type HostedPageGroup struct {

type App struct {
ID types.String `tfsdk:"id"`
AppOwner types.String `tfsdk:"app_owner"`
BotProvider types.String `tfsdk:"bot_provider"`
ClientId types.String `tfsdk:"client_id"`
ClientSecret types.String `tfsdk:"client_secret"`
ClientName types.String `tfsdk:"client_name"`
Expand Down
25 changes: 25 additions & 0 deletions internal/provider/resource_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
Expand Down Expand Up @@ -49,6 +50,20 @@ func (r *appResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
},
},

"app_owner": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},

"bot_provider": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},

// App Details
"client_name": schema.StringAttribute{
Required: true,
Expand Down Expand Up @@ -98,10 +113,16 @@ func (r *appResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
"redirect_uris": schema.ListAttribute{
ElementType: types.StringType,
Required: true,
Validators: []validator.List{
listvalidator.SizeAtLeast(1),
},
},
"allowed_logout_urls": schema.ListAttribute{
ElementType: types.StringType,
Required: true,
Validators: []validator.List{
listvalidator.SizeAtLeast(1),
},
},

// Company Details
Expand Down Expand Up @@ -553,6 +574,8 @@ func applyAppToState(ctx context.Context, state *App, app *client.App) diag.Diag
var diags diag.Diagnostics

state.ID = types.StringValue(app.ID)
state.BotProvider = types.StringValue(app.BotProvider)
state.AppOwner = types.StringValue(app.AppOwner)
state.ClientId = types.StringValue(app.ClientId)
state.ClientSecret = types.StringValue(app.ClientSecret)
state.ClientName = types.StringValue(app.ClientName)
Expand Down Expand Up @@ -651,6 +674,8 @@ func planToApp(ctx context.Context, plan *App, state *App) (*client.App, diag.Di
var diags diag.Diagnostics
plannedApp := client.App{
ID: state.ID.ValueString(),
AppOwner: state.AppOwner.ValueString(),
BotProvider: state.BotProvider.ValueString(),
ClientSecret: state.ClientSecret.ValueString(),
ClientId: state.ClientId.ValueString(),
ClientDisplayName: plan.ClientDisplayName.ValueString(),
Expand Down
37 changes: 37 additions & 0 deletions internal/provider/resource_hpgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -316,3 +317,39 @@ func (r hostedPageGroupResource) Delete(ctx context.Context, req resource.Delete

resp.State.RemoveResource(ctx)
}

func (r hostedPageGroupResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
group, err := r.provider.client.GetHostedPagesGroup(req.ID)

if err != nil {
resp.Diagnostics.AddError("Error importing Hosted Page Group", err.Error())
return
}

var diags diag.Diagnostics

state := HostedPageGroup{
ID: types.StringValue(group.ID),
GroupOwner: types.StringValue(group.GroupOwner),
CreatedTime: types.StringValue(group.CreatedTime),
UpdatedTime: types.StringValue(group.UpdatedTime),
DefaultLocale: types.StringValue(group.DefaultLocale),
}

state.HostedPages, diags = types.ListValueFrom(ctx, types.ObjectType{
AttrTypes: map[string]attr.Type{
"id": types.StringType,
"content": types.StringType,
"locale": types.StringType,
"url": types.StringType,
},
}, group.HostedPages)

resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

diags = resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)
}

0 comments on commit 206d76b

Please sign in to comment.