99 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1010 "github.com/spectrocloud/palette-sdk-go/api/models"
1111 "github.com/spectrocloud/palette-sdk-go/client"
12+ "regexp"
1213 "strings"
1314 "time"
1415)
@@ -84,12 +85,26 @@ func resourceSSO() *schema.Resource {
8485 Type : schema .TypeString ,
8586 Required : true ,
8687 Description : "Client ID for OIDC authentication." ,
88+ ValidateFunc : func (val interface {}, key string ) (warns []string , errs []error ) {
89+ v := val .(string )
90+ if v == "" {
91+ errs = append (errs , fmt .Errorf ("%q must not be empty" , key ))
92+ }
93+ return
94+ },
8795 },
8896 "client_secret" : {
8997 Type : schema .TypeString ,
9098 Required : true ,
9199 Sensitive : true ,
92100 Description : "Client secret for OIDC authentication (sensitive)." ,
101+ ValidateFunc : func (val interface {}, key string ) (warns []string , errs []error ) {
102+ v := val .(string )
103+ if v == "" {
104+ errs = append (errs , fmt .Errorf ("%q must not be empty" , key ))
105+ }
106+ return
107+ },
93108 },
94109 "callback_url" : {
95110 Type : schema .TypeString ,
@@ -133,6 +148,19 @@ func resourceSSO() *schema.Resource {
133148 Type : schema .TypeString ,
134149 Required : true ,
135150 Description : "User's email address retrieved from identity provider." ,
151+ ValidateFunc : func (val interface {}, key string ) (warns []string , errs []error ) {
152+ v := val .(string )
153+ if v == "" {
154+ errs = append (errs , fmt .Errorf ("%q must not be empty" , key ))
155+ return
156+ }
157+ emailRegex := `^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`
158+ matched , err := regexp .MatchString (emailRegex , v )
159+ if err != nil || ! matched {
160+ errs = append (errs , fmt .Errorf ("%q must be a valid email address" , key ))
161+ }
162+ return
163+ },
136164 },
137165 "spectro_team" : {
138166 Type : schema .TypeString ,
@@ -159,6 +187,19 @@ func resourceSSO() *schema.Resource {
159187 Type : schema .TypeString ,
160188 Required : true ,
161189 Description : "User's email address retrieved from identity provider." ,
190+ ValidateFunc : func (val interface {}, key string ) (warns []string , errs []error ) {
191+ v := val .(string )
192+ if v == "" {
193+ errs = append (errs , fmt .Errorf ("%q must not be empty" , key ))
194+ return
195+ }
196+ emailRegex := `^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`
197+ matched , err := regexp .MatchString (emailRegex , v )
198+ if err != nil || ! matched {
199+ errs = append (errs , fmt .Errorf ("%q must be a valid email address" , key ))
200+ }
201+ return
202+ },
162203 },
163204 "spectro_team" : {
164205 Type : schema .TypeString ,
@@ -251,6 +292,19 @@ func resourceSSO() *schema.Resource {
251292 Optional : true ,
252293 Default : "Email" ,
253294 Description : "User's email address retrieved from identity provider." ,
295+ ValidateFunc : func (val interface {}, key string ) (warns []string , errs []error ) {
296+ v := val .(string )
297+ if v == "" {
298+ errs = append (errs , fmt .Errorf ("%q must not be empty" , key ))
299+ return
300+ }
301+ emailRegex := `^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`
302+ matched , err := regexp .MatchString (emailRegex , v )
303+ if err != nil || ! matched {
304+ errs = append (errs , fmt .Errorf ("%q must be a valid email address" , key ))
305+ }
306+ return
307+ },
254308 },
255309 "spectro_team" : {
256310 Type : schema .TypeString ,
0 commit comments