Skip to content

Commit

Permalink
fix(lh-79148): fix bug with onboarding using a CDG (#137)
Browse files Browse the repository at this point in the history
* fix(lh-79148): fix bug with onboarding using a CDG

* fix tests

---------

Co-authored-by: Weilue Luo <[email protected]>
  • Loading branch information
siddhuwarrier and weilueluo authored Apr 30, 2024
1 parent 513abfe commit f271370
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
16 changes: 10 additions & 6 deletions client/device/asa/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
},
)
Expand Down
7 changes: 3 additions & 4 deletions client/device/asa/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
},
}
Expand Down
11 changes: 10 additions & 1 deletion provider/examples/resources/asa/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ module "asav" {
asa_enable_password = random_password.asa_enable_password.result

depends_on = [cdo_sdc_onboarding.sdc]
}
}

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
}

0 comments on commit f271370

Please sign in to comment.