Skip to content

Commit e458a51

Browse files
Tejashree-RSdependabot[bot]VishrutiBuddhadev
authored
[FIX] NPA-1042 - Added Validation for Vdiscoverytask Port, Protocol, and DriverType Fields (#279)
* added validator for use_identity and allow_unsecured_connection attributes * modified comment * chore(deps): bump golang.org/x/crypto from 0.43.0 to 0.45.0 (#265) Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.43.0 to 0.45.0. - [Commits](golang/crypto@v0.43.0...v0.45.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-version: 0.45.0 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Vishruti Buddhadev <[email protected]>
1 parent 6f3682c commit e458a51

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

internal/service/discovery/vdiscoverytask_resource.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,56 @@ func (r *VdiscoverytaskResource) ValidateConfig(ctx context.Context, req resourc
282282
}
283283
}
284284
}
285+
286+
if !data.UseIdentity.IsNull() && !data.UseIdentity.IsUnknown() && data.UseIdentity.ValueBool() {
287+
// When use_identity is true, enforce standard ports
288+
if !data.Protocol.IsNull() && !data.Protocol.IsUnknown() && !data.Port.IsNull() && !data.Port.IsUnknown() {
289+
protocol := data.Protocol.ValueString()
290+
port := data.Port.ValueInt64()
291+
292+
if protocol == "HTTPS" && port != 443 {
293+
resp.Diagnostics.AddAttributeError(
294+
path.Root("port"),
295+
"Invalid Port Configuration",
296+
fmt.Sprintf("When use_identity is true and protocol is HTTPS, port must be 443. Got: %d", port),
297+
)
298+
}
299+
300+
if protocol == "HTTP" && port != 80 {
301+
resp.Diagnostics.AddAttributeError(
302+
path.Root("port"),
303+
"Invalid Port Configuration",
304+
fmt.Sprintf("When use_identity is true and protocol is HTTP, port must be 80. Got: %d", port),
305+
)
306+
}
307+
}
308+
}
309+
310+
// Validate allow_unsecured_connection requirements
311+
if !data.AllowUnsecuredConnection.IsNull() && !data.AllowUnsecuredConnection.IsUnknown() && data.AllowUnsecuredConnection.ValueBool() {
312+
// When allow_unsecured_connection is true, protocol must be HTTPS
313+
if !data.Protocol.IsNull() && !data.Protocol.IsUnknown() {
314+
if data.Protocol.ValueString() != "HTTPS" {
315+
resp.Diagnostics.AddAttributeError(
316+
path.Root("protocol"),
317+
"Invalid Protocol Configuration",
318+
fmt.Sprintf("When allow_unsecured_connection is true, protocol must be HTTPS. Got: %s", data.Protocol.ValueString()),
319+
)
320+
}
321+
}
322+
323+
// When allow_unsecured_connection is true, driver_type must be VMware or OpenStack
324+
if !data.DriverType.IsNull() && !data.DriverType.IsUnknown() {
325+
driverType := data.DriverType.ValueString()
326+
if driverType != "VMWARE" && driverType != "OPENSTACK" {
327+
resp.Diagnostics.AddAttributeError(
328+
path.Root("driver_type"),
329+
"Invalid Driver Type Configuration",
330+
fmt.Sprintf("When allow_unsecured_connection is true, driver_type must be either VMware or OpenStack. Got: %s", driverType),
331+
)
332+
}
333+
}
334+
}
285335
}
286336

287337
func (r *VdiscoverytaskResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {

0 commit comments

Comments
 (0)