Skip to content

Commit

Permalink
fix issue when content security policy is null
Browse files Browse the repository at this point in the history
Signed-off-by: Tien Nguyen <duytien.nguyen@okta.com>
  • Loading branch information
duytiennguyen-okta committed Jul 17, 2024
1 parent c7f45bf commit 7697c4f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 45 deletions.
94 changes: 51 additions & 43 deletions okta/customization.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,53 +114,61 @@ func buildSignInPageRequest(ctx context.Context, model signinPageModel) (okta.Si
sp.SetPageContent(model.PageContent.ValueString())
sp.SetWidgetVersion(model.WidgetVersion.ValueString())

wc := okta.SignInPageAllOfWidgetCustomizations{}
wcm := &widgetCustomizationsModel{}
model.WidgetCustomizations.As(ctx, wcm, basetypes.ObjectAsOptions{})
if !model.WidgetVersion.IsNull() {
wc := okta.SignInPageAllOfWidgetCustomizations{}
wcm := &widgetCustomizationsModel{}
diags := model.WidgetCustomizations.As(ctx, wcm, basetypes.ObjectAsOptions{})
if diags.HasError() {
return *okta.NewSignInPage(), diags
}
wc.SignInLabel = wcm.SignInLabel.ValueStringPointer()
wc.UsernameLabel = wcm.UsernameLabel.ValueStringPointer()
wc.UsernameInfoTip = wcm.UsernameInfoTip.ValueStringPointer()
wc.PasswordLabel = wcm.PasswordLabel.ValueStringPointer()
wc.PasswordInfoTip = wcm.PasswordInfoTip.ValueStringPointer()
wc.ShowPasswordVisibilityToggle = wcm.ShowPasswordVisibilityToggle.ValueBoolPointer()
wc.ShowUserIdentifier = wcm.ShowUserIdentifier.ValueBoolPointer()
wc.ForgotPasswordLabel = wcm.ForgotPasswordLabel.ValueStringPointer()
wc.ForgotPasswordUrl = wcm.ForgotPasswordURL.ValueStringPointer()
wc.UnlockAccountLabel = wcm.UnlockAccountLabel.ValueStringPointer()
wc.UnlockAccountUrl = wcm.UnlockAccountURL.ValueStringPointer()
wc.HelpLabel = wcm.HelpLabel.ValueStringPointer()
wc.HelpUrl = wcm.HelpURL.ValueStringPointer()
wc.CustomLink1Label = wcm.CustomLink1Label.ValueStringPointer()
wc.CustomLink1Url = wcm.CustomLink1URL.ValueStringPointer()
wc.CustomLink2Label = wcm.CustomLink2Label.ValueStringPointer()
wc.CustomLink2Url = wcm.CustomLink2URL.ValueStringPointer()
wc.AuthenticatorPageCustomLinkLabel = wcm.AuthenticatorPageCustomLinkLabel.ValueStringPointer()
wc.AuthenticatorPageCustomLinkUrl = wcm.AuthenticatorPageCustomLinkURL.ValueStringPointer()
wc.ClassicRecoveryFlowEmailOrUsernameLabel = wcm.ClassicRecoveryFlowEmailOrUsernameLabel.ValueStringPointer()
wc.SetWidgetGeneration(wcm.WidgetGeneration.ValueString())

wc.SignInLabel = wcm.SignInLabel.ValueStringPointer()
wc.UsernameLabel = wcm.UsernameLabel.ValueStringPointer()
wc.UsernameInfoTip = wcm.UsernameInfoTip.ValueStringPointer()
wc.PasswordLabel = wcm.PasswordLabel.ValueStringPointer()
wc.PasswordInfoTip = wcm.PasswordInfoTip.ValueStringPointer()
wc.ShowPasswordVisibilityToggle = wcm.ShowPasswordVisibilityToggle.ValueBoolPointer()
wc.ShowUserIdentifier = wcm.ShowUserIdentifier.ValueBoolPointer()
wc.ForgotPasswordLabel = wcm.ForgotPasswordLabel.ValueStringPointer()
wc.ForgotPasswordUrl = wcm.ForgotPasswordURL.ValueStringPointer()
wc.UnlockAccountLabel = wcm.UnlockAccountLabel.ValueStringPointer()
wc.UnlockAccountUrl = wcm.UnlockAccountURL.ValueStringPointer()
wc.HelpLabel = wcm.HelpLabel.ValueStringPointer()
wc.HelpUrl = wcm.HelpURL.ValueStringPointer()
wc.CustomLink1Label = wcm.CustomLink1Label.ValueStringPointer()
wc.CustomLink1Url = wcm.CustomLink1URL.ValueStringPointer()
wc.CustomLink2Label = wcm.CustomLink2Label.ValueStringPointer()
wc.CustomLink2Url = wcm.CustomLink2URL.ValueStringPointer()
wc.AuthenticatorPageCustomLinkLabel = wcm.AuthenticatorPageCustomLinkLabel.ValueStringPointer()
wc.AuthenticatorPageCustomLinkUrl = wcm.AuthenticatorPageCustomLinkURL.ValueStringPointer()
wc.ClassicRecoveryFlowEmailOrUsernameLabel = wcm.ClassicRecoveryFlowEmailOrUsernameLabel.ValueStringPointer()
wc.SetWidgetGeneration(wcm.WidgetGeneration.ValueString())
sp.SetWidgetCustomizations(wc)
}

sp.SetWidgetCustomizations(wc)
if !model.ContentSecurityPolicySetting.IsNull() {
csp := okta.ContentSecurityPolicySetting{}
cspm := &contentSecurityPolicySettingModel{}
diags := model.ContentSecurityPolicySetting.As(ctx, cspm, basetypes.ObjectAsOptions{})
if diags.HasError() {
return *okta.NewSignInPage(), diags
}
csp.Mode = cspm.Mode.ValueStringPointer()
csp.ReportUri = cspm.ReportUri.ValueStringPointer()
elements := make([]types.String, 0, len(cspm.SrcList.Elements()))
diags = cspm.SrcList.ElementsAs(ctx, &elements, false)
if diags.HasError() {
return *okta.NewSignInPage(), diags
}
convertElements := make([]string, 0)
for _, v := range elements {
convertElements = append(convertElements, v.ValueString())
}
csp.SrcList = convertElements

csp := okta.ContentSecurityPolicySetting{}
cspm := &contentSecurityPolicySettingModel{}
diags := model.ContentSecurityPolicySetting.As(ctx, cspm, basetypes.ObjectAsOptions{})
if diags.HasError() {
return *okta.NewSignInPage(), diags
}
csp.Mode = cspm.Mode.ValueStringPointer()
csp.ReportUri = cspm.ReportUri.ValueStringPointer()
elements := make([]types.String, 0, len(cspm.SrcList.Elements()))
diags = cspm.SrcList.ElementsAs(ctx, &elements, false)
if diags.HasError() {
return *okta.NewSignInPage(), diags
sp.SetContentSecurityPolicySetting(csp)
}
convertElements := make([]string, 0)
for _, v := range elements {
convertElements = append(convertElements, v.ValueString())
}
csp.SrcList = convertElements
sp.SetContentSecurityPolicySetting(csp)

return sp, nil
}

Expand Down
6 changes: 4 additions & 2 deletions okta/resource_okta_customized_signin_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func (r *customizedSigninPageResource) Create(ctx context.Context, req resource.
}

reqBody, diags := buildSignInPageRequest(ctx, state)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

Expand Down Expand Up @@ -118,7 +119,8 @@ func (r *customizedSigninPageResource) Update(ctx context.Context, req resource.
}

reqBody, diags := buildSignInPageRequest(ctx, state)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

Expand Down

0 comments on commit 7697c4f

Please sign in to comment.