Skip to content

Commit 206d76b

Browse files
authored
Feature/app v3 (#51)
* Update readme and ci * Add import for hpgroup * feat(cidaas_app): adapt to cidaas v3
1 parent 7eaa234 commit 206d76b

File tree

8 files changed

+122
-7
lines changed

8 files changed

+122
-7
lines changed

.github/workflows/ci-go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
runs-on: ubuntu-latest
2929
strategy:
3030
matrix:
31-
go-version: [ '1.18' ]
31+
go-version: [ '1.19' ]
3232
steps:
3333
- uses: actions/checkout@v3
3434
- uses: actions/setup-go@v4

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Terraform provider to manage and read resources from cidaas instances.
77

88

9-
Currently developed against cidaas version `2.0.12`
9+
Currently developed against cidaas version `3`
1010

11-
* [Usage documentation for the Provider can be found in the Terraform Registry](https://registry.terraform.io/providers/real-digital/cidaas/latest/docs)
12-
* [Additional examples can be found in the `./examples` folder within this repository](https://github.com/real-digital/terraform-provider-cidaas/tree/main/examples).
11+
* [Usage documentation for the Provider can be found in the Terraform Registry](https://registry.terraform.io/providers/kaufland-ecommerce/cidaas/latest/docs)
12+
* [Additional examples can be found in the `./examples` folder within this repository](https://github.com/kaufland-ecommerce/terraform-provider-cidaas/tree/main/examples).

internal/client/app.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,51 @@ func (c *client) CreateApp(app *App) (*App, error) {
4646
response.Data.PasswordPolicy = nil
4747
}
4848

49+
// App creation does not return those if they are empty on the initial creation
50+
if response.Data.OperationsAllowedGroups == nil {
51+
response.Data.OperationsAllowedGroups = []AllowedGroup{}
52+
}
53+
54+
if response.Data.AllowedGroups == nil {
55+
response.Data.AllowedGroups = []AllowedGroup{}
56+
}
57+
58+
if response.Data.AllowedMfa == nil {
59+
response.Data.AllowedMfa = []string{}
60+
}
61+
62+
if response.Data.ConsentRefs == nil {
63+
response.Data.ConsentRefs = []string{}
64+
}
65+
66+
if response.Data.AllowedOrigins == nil {
67+
response.Data.AllowedOrigins = []string{}
68+
}
69+
70+
if response.Data.AllowedFields == nil {
71+
response.Data.AllowedFields = []string{}
72+
}
73+
74+
if response.Data.AllowedWebOrigins == nil {
75+
response.Data.AllowedWebOrigins = []string{}
76+
}
77+
78+
if response.Data.RequiredFields == nil {
79+
response.Data.RequiredFields = []string{}
80+
}
81+
82+
if response.Data.AdditionalAccessTokenPayload == nil {
83+
response.Data.AdditionalAccessTokenPayload = []string{}
84+
}
85+
86+
if response.Data.RedirectUris == nil {
87+
response.Data.RedirectUris = []string{}
88+
}
89+
90+
if response.Data.AllowedLogoutUrls == nil {
91+
response.Data.AllowedLogoutUrls = []string{}
92+
}
93+
4994
return &response.Data, nil
5095
}
5196

internal/client/model.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ type AllowedGroup struct {
7474
}
7575

7676
type App struct {
77-
ID string `json:"id"`
78-
ClientId string `json:"client_id"`
79-
ClientSecret string `json:"client_secret"`
77+
ID string `json:"id,omitempty"`
78+
AcceptRolesInTheRegistration bool `json:"accept_roles_in_the_registration"`
79+
ClientId string `json:"client_id,omitempty"`
80+
ClientSecret string `json:"client_secret,omitempty"`
8081
ClientName string `json:"client_name"`
8182
ClientDisplayName string `json:"client_display_name"`
8283
IsRememberMeSelected bool `json:"is_remember_me_selected"`
@@ -105,6 +106,8 @@ type App struct {
105106
AlwaysAskMfa bool `json:"always_ask_mfa"`
106107
PasswordPolicy *string `json:"password_policy_ref,omitempty"`
107108
RegisterWithLoginInformation bool `json:"register_with_login_information"`
109+
AppOwner string `json:"app_owner,omitempty"`
110+
BotProvider string `json:"bot_provider,omitempty"`
108111

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

@@ -124,6 +127,7 @@ type App struct {
124127
AllowedWebOrigins []string `json:"allowed_web_origins"`
125128
AllowedOrigins []string `json:"allowed_origins"`
126129
AllowedMfa []string `json:"allowed_mfa"`
130+
AllowedRoles []string `json:"allowed_roles"`
127131
}
128132

129133
type RegistrationField struct {

internal/provider/data_source_social_provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func (d socialProviderDataSource) Read(ctx context.Context, req datasource.ReadR
5454
var state SocialProvider
5555

5656
diags := req.Config.GetAttribute(ctx, path.Root("provider_name"), &providerName)
57+
resp.Diagnostics.Append(diags...)
58+
5759
diags = req.Config.GetAttribute(ctx, path.Root("name"), &name)
5860

5961
resp.Diagnostics.Append(diags...)

internal/provider/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ type HostedPageGroup struct {
5656

5757
type App struct {
5858
ID types.String `tfsdk:"id"`
59+
AppOwner types.String `tfsdk:"app_owner"`
60+
BotProvider types.String `tfsdk:"bot_provider"`
5961
ClientId types.String `tfsdk:"client_id"`
6062
ClientSecret types.String `tfsdk:"client_secret"`
6163
ClientName types.String `tfsdk:"client_name"`

internal/provider/resource_app.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
7+
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
78
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
89
"github.com/hashicorp/terraform-plugin-framework/attr"
910
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -49,6 +50,20 @@ func (r *appResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
4950
},
5051
},
5152

53+
"app_owner": schema.StringAttribute{
54+
Computed: true,
55+
PlanModifiers: []planmodifier.String{
56+
stringplanmodifier.UseStateForUnknown(),
57+
},
58+
},
59+
60+
"bot_provider": schema.StringAttribute{
61+
Computed: true,
62+
PlanModifiers: []planmodifier.String{
63+
stringplanmodifier.UseStateForUnknown(),
64+
},
65+
},
66+
5267
// App Details
5368
"client_name": schema.StringAttribute{
5469
Required: true,
@@ -98,10 +113,16 @@ func (r *appResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
98113
"redirect_uris": schema.ListAttribute{
99114
ElementType: types.StringType,
100115
Required: true,
116+
Validators: []validator.List{
117+
listvalidator.SizeAtLeast(1),
118+
},
101119
},
102120
"allowed_logout_urls": schema.ListAttribute{
103121
ElementType: types.StringType,
104122
Required: true,
123+
Validators: []validator.List{
124+
listvalidator.SizeAtLeast(1),
125+
},
105126
},
106127

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

555576
state.ID = types.StringValue(app.ID)
577+
state.BotProvider = types.StringValue(app.BotProvider)
578+
state.AppOwner = types.StringValue(app.AppOwner)
556579
state.ClientId = types.StringValue(app.ClientId)
557580
state.ClientSecret = types.StringValue(app.ClientSecret)
558581
state.ClientName = types.StringValue(app.ClientName)
@@ -651,6 +674,8 @@ func planToApp(ctx context.Context, plan *App, state *App) (*client.App, diag.Di
651674
var diags diag.Diagnostics
652675
plannedApp := client.App{
653676
ID: state.ID.ValueString(),
677+
AppOwner: state.AppOwner.ValueString(),
678+
BotProvider: state.BotProvider.ValueString(),
654679
ClientSecret: state.ClientSecret.ValueString(),
655680
ClientId: state.ClientId.ValueString(),
656681
ClientDisplayName: plan.ClientDisplayName.ValueString(),

internal/provider/resource_hpgroup.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
66
"github.com/hashicorp/terraform-plugin-framework/attr"
7+
"github.com/hashicorp/terraform-plugin-framework/diag"
78
"github.com/hashicorp/terraform-plugin-framework/path"
89
"github.com/hashicorp/terraform-plugin-framework/resource"
910
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -316,3 +317,39 @@ func (r hostedPageGroupResource) Delete(ctx context.Context, req resource.Delete
316317

317318
resp.State.RemoveResource(ctx)
318319
}
320+
321+
func (r hostedPageGroupResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
322+
group, err := r.provider.client.GetHostedPagesGroup(req.ID)
323+
324+
if err != nil {
325+
resp.Diagnostics.AddError("Error importing Hosted Page Group", err.Error())
326+
return
327+
}
328+
329+
var diags diag.Diagnostics
330+
331+
state := HostedPageGroup{
332+
ID: types.StringValue(group.ID),
333+
GroupOwner: types.StringValue(group.GroupOwner),
334+
CreatedTime: types.StringValue(group.CreatedTime),
335+
UpdatedTime: types.StringValue(group.UpdatedTime),
336+
DefaultLocale: types.StringValue(group.DefaultLocale),
337+
}
338+
339+
state.HostedPages, diags = types.ListValueFrom(ctx, types.ObjectType{
340+
AttrTypes: map[string]attr.Type{
341+
"id": types.StringType,
342+
"content": types.StringType,
343+
"locale": types.StringType,
344+
"url": types.StringType,
345+
},
346+
}, group.HostedPages)
347+
348+
resp.Diagnostics.Append(diags...)
349+
if resp.Diagnostics.HasError() {
350+
return
351+
}
352+
353+
diags = resp.State.Set(ctx, &state)
354+
resp.Diagnostics.Append(diags...)
355+
}

0 commit comments

Comments
 (0)