From f2713709a917d665faf98576a446a09ef5938298 Mon Sep 17 00:00:00 2001 From: Siddhu Warrier Date: Tue, 30 Apr 2024 19:45:08 +0100 Subject: [PATCH] fix(lh-79148): fix bug with onboarding using a CDG (#137) * fix(lh-79148): fix bug with onboarding using a CDG * fix tests --------- Co-authored-by: Weilue Luo --- client/device/asa/create.go | 16 ++++++++++------ client/device/asa/create_test.go | 7 +++---- provider/examples/resources/asa/main.tf | 11 ++++++++++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/client/device/asa/create.go b/client/device/asa/create.go index 3ab5d532..44f6cc66 100644 --- a/client/device/asa/create.go +++ b/client/device/asa/create.go @@ -68,12 +68,16 @@ func Create(ctx context.Context, client http.Client, createInp CreateInput) (*Cr createUrl := url.CreateAsa(client.BaseUrl()) - conn, err := connector.ReadByUid(ctx, client, connector.ReadByUidInput{ConnectorUid: createInp.ConnectorUid}) - if err != nil { - return nil, &CreateError{ - Err: err, - CreatedResourceId: nil, + var connectorName string + if createInp.ConnectorType == "SDC" { + conn, err := connector.ReadByUid(ctx, client, connector.ReadByUidInput{ConnectorUid: createInp.ConnectorUid}) + if err != nil { + return nil, &CreateError{ + Err: err, + CreatedResourceId: nil, + } } + connectorName = conn.Name } transaction, err := publicapi.TriggerTransaction( @@ -87,7 +91,7 @@ func Create(ctx context.Context, client http.Client, createInp CreateInput) (*Cr Password: createInp.Password, ConnectorType: createInp.ConnectorType, IgnoreCertificate: createInp.IgnoreCertificate, - ConnectorName: conn.Name, + ConnectorName: connectorName, Labels: createInp.Labels, }, ) diff --git a/client/device/asa/create_test.go b/client/device/asa/create_test.go index 5247411f..1461e1f6 100644 --- a/client/device/asa/create_test.go +++ b/client/device/asa/create_test.go @@ -66,19 +66,18 @@ func TestAsaCreate(t *testing.T) { }, }, { - testName: "fails onboards Duo Admin Panel if cdg read fails", + testName: "fails onboards Duo Admin Panel if trigger transaction fails", input: createInput, setupFunc: func(input asa.CreateInput) { - internalTesting.MockGetError(url.ReadConnectorByUid(testModel.BaseUrl, cdgReadOutput.Uid), "read cdg error") - internalTesting.MockPostAccepted(url.CreateAsa(testModel.BaseUrl), doneTransaction) + internalTesting.MockPostError(url.CreateAsa(testModel.BaseUrl), "post error") internalTesting.MockGetOk(url.ReadDevice(testModel.BaseUrl, readOutput.Uid), readOutput) }, assertFunc: func(actualOutput *asa.CreateOutput, err *asa.CreateError, t *testing.T) { assert.Nil(t, actualOutput) assert.NotNil(t, err) - assert.ErrorContains(t, err, "read cdg error") + assert.ErrorContains(t, err, "post error") }, }, } diff --git a/provider/examples/resources/asa/main.tf b/provider/examples/resources/asa/main.tf index 382eedcf..132ac294 100644 --- a/provider/examples/resources/asa/main.tf +++ b/provider/examples/resources/asa/main.tf @@ -46,4 +46,13 @@ module "asav" { asa_enable_password = random_password.asa_enable_password.result depends_on = [cdo_sdc_onboarding.sdc] -} \ No newline at end of file +} + +resource "cdo_asa_device" "my-asa" { + name = "my-asa" + socket_address = module.asav.mgmt_interface_ip + username = var.asa_username + password = random_password.asa_password.result + connector_type = "CDG" + ignore_certificate = false + } \ No newline at end of file