Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FTD Resource (onboard via cdFMC) #11

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f8ca719
provider skeleton
weilueluo Aug 14, 2023
4c4f07e
Merge branch 'main' into LH-67704/ftd-onboard-cdfmc-resource
weilueluo Aug 22, 2023
52d7dda
impl
weilueluo Aug 22, 2023
2e00787
cleanup
weilueluo Aug 22, 2023
fad693c
fix unit test
weilueluo Aug 22, 2023
f10f330
save
weilueluo Aug 22, 2023
b15cba6
read impl
weilueluo Aug 22, 2023
eb3d54c
add test
weilueluo Aug 23, 2023
9695b6b
add tests
weilueluo Aug 23, 2023
fe26c05
fix test
weilueluo Aug 23, 2023
a5dd668
rename filenames
weilueluo Aug 23, 2023
93d0e14
Merge branch 'main' into LH-67704/ftd-onboard-cdfmc-resource
weilueluo Aug 23, 2023
2588332
Merge branch 'LH-67704/go-client-smart-license' into LH-67704/ftd-onb…
weilueluo Aug 23, 2023
65800e9
Merge branch 'LH-67704/go-client-read-cdfmc' into LH-67704/ftd-onboar…
weilueluo Aug 23, 2023
d79492c
progress++
weilueluo Aug 24, 2023
6a01b05
Merge branch 'main' into LH-67704/ftd-onboard-cdfmc-resource
weilueluo Aug 24, 2023
66204dd
fix merge conflict
weilueluo Aug 24, 2023
b214ba0
init impl done
weilueluo Aug 24, 2023
ecaab96
finally create working
weilueluo Aug 25, 2023
c5f499d
finally fix acceptance tests
weilueluo Aug 25, 2023
623ef46
remove temp files
weilueluo Aug 25, 2023
d74ca8e
clean up
weilueluo Aug 26, 2023
5e50e8c
fix unit test
weilueluo Aug 26, 2023
4a89f3c
fmcappliance tests
weilueluo Aug 26, 2023
fd291ce
acceptance update tests && use cloudfmc & cloudftd as name
weilueluo Aug 26, 2023
78878f8
read fmc domain uid
weilueluo Aug 26, 2023
abbb35f
fix unit tests
weilueluo Aug 26, 2023
1c72d3a
read fmc domain info test
weilueluo Aug 26, 2023
9e2331e
cloudfmc test
weilueluo Aug 27, 2023
abfa12c
ftd unit test wip
weilueluo Aug 27, 2023
fc0b52f
some test utils
weilueluo Aug 28, 2023
2749046
ftd unit test wip
weilueluo Aug 29, 2023
a7fc37e
create unit test done
weilueluo Aug 29, 2023
77a226d
create unit tests failure cases
weilueluo Aug 29, 2023
bdb871d
ftd delete tests
weilueluo Aug 29, 2023
44e332c
minor cleanup
weilueluo Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/connector"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/asa/asaconfig"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudftd"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/genericssh"
"net/http"

Expand Down Expand Up @@ -120,3 +121,23 @@ func (c *Client) UpdateGenericSSH(ctx context.Context, inp genericssh.UpdateInpu
func (c *Client) DeleteGenericSSH(ctx context.Context, inp genericssh.DeleteInput) (*genericssh.DeleteOutput, error) {
return genericssh.Delete(ctx, c.client, inp)
}

func (c *Client) ReadCloudFtdByUid(ctx context.Context, inp cloudftd.ReadByUidInput) (*cloudftd.ReadOutput, error) {
return cloudftd.ReadByUid(ctx, c.client, inp)
}

func (c *Client) ReadCloudFtdByName(ctx context.Context, inp cloudftd.ReadByNameInput) (*cloudftd.ReadOutput, error) {
return cloudftd.ReadByName(ctx, c.client, inp)
}

func (c *Client) CreateCloudFtd(ctx context.Context, inp cloudftd.CreateInput) (*cloudftd.CreateOutput, error) {
return cloudftd.Create(ctx, c.client, inp)
}

func (c *Client) UpdateCloudFtd(ctx context.Context, inp cloudftd.UpdateInput) (*cloudftd.UpdateOutput, error) {
return cloudftd.Update(ctx, c.client, inp)
}

func (c *Client) DeleteCloudFtd(ctx context.Context, inp cloudftd.DeleteInput) (*cloudftd.DeleteOutput, error) {
return cloudftd.Delete(ctx, c.client, inp)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package cdfmc_test
package cloudfmc_test

import "time"

const (
smartLicenseEvalExpiresInDays = 123456
Expand All @@ -14,9 +16,21 @@ const (
smartLicenseLimit = 123456
smartLicensePages = 123456

baseUrl = "https://unit-test.net"
domainUid = "unit-test-domain-uid"
limit = 123456
baseUrl = "https://unit-test.net"

fmcHostname = "https://fmc-hostname.unit-test.net"
fmcUid = "unit-test-fmc-uid"
domainUid = "unit-test-domain-uid"
limit = 123456
status = "unit-test-status"

deviceName = "unit-test-device-name"
deviceUid = "unit-test-uid"
deviceHost = "https://unit-test.com"
devicePort = 1234
deviceCloudConnectorUId = "unit-test-uid"

specificDeviceUid = "unit-test-specific-device-uid"

accessPolicySelfLink = "https://unit-test.cdo.cisco.com/api/fmc_config/v1/domain/unit-test-domain-uid/policy/accesspolicies/unit-test-uid"
accessPolicyName = "Unit Test Access Control Policy"
Expand All @@ -27,3 +41,8 @@ const (
accessPolicyLimit = 123456
accessPolicyPages = 123456
)

var (
deviceCreatedDate = time.Date(1999, 1, 1, 0, 0, 0, 0, time.Local)
deviceLastUpdatedDate = time.Date(1999, 1, 1, 0, 0, 0, 0, time.Local)
)
16 changes: 16 additions & 0 deletions client/device/cloudfmc/fmcappliance/fixture_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fmcappliance_test

const (
baseUrl = "https://unit-test.net"
FmcSpecificUid = "unit-test-cloudfmc-specific-uid"
queueTriggerState = "unit-test-queue-trigger-state"
uid = "unit-test-uid"
state = "unit-test-state"
domainUid = "unit-test-domainUid"
)

var (
stateMachineContext = map[string]string{
"unit-test-sm-context-key": "unit-test-sm-context-value",
}
)
47 changes: 47 additions & 0 deletions client/device/cloudfmc/fmcappliance/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fmcappliance

import (
"context"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
)

type UpdateInput struct {
FmcSpecificUid string
QueueTriggerState string
StateMachineContext map[string]string
}

func NewUpdateInput(FmcSpecificUid, queueTriggerState string, stateMachineContext map[string]string) UpdateInput {
return UpdateInput{
FmcSpecificUid: FmcSpecificUid,
QueueTriggerState: queueTriggerState,
StateMachineContext: stateMachineContext,
}
}

type UpdateOutput struct {
Uid string `json:"uid"`
State string `json:"state"`
DomainUid string `json:"domainUid"`
}

type updateRequestBody struct {
QueueTriggerState string `json:"queueTriggerState"`
StateMachineContext map[string]string `json:"stateMachineContext"`
}

func Update(ctx context.Context, client http.Client, updateInp UpdateInput) (*UpdateOutput, error) {
updateUrl := url.UpdateFmcAppliance(client.BaseUrl(), updateInp.FmcSpecificUid)
updateBody := newUpdateRequestBodyBuilder().
QueueTriggerState(updateInp.QueueTriggerState).
StateMachineContext(updateInp.StateMachineContext).
Build()
req := client.NewPut(ctx, updateUrl, updateBody)
var updateOup UpdateOutput
if err := req.Send(&updateOup); err != nil {
return nil, err
}

return &updateOup, nil
}
30 changes: 30 additions & 0 deletions client/device/cloudfmc/fmcappliance/update_inputbuilder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fmcappliance

type UpdateInputBuilder struct {
updateInput *UpdateInput
}

func NewUpdateInputBuilder() *UpdateInputBuilder {
updateInput := &UpdateInput{}
b := &UpdateInputBuilder{updateInput: updateInput}
return b
}

func (b *UpdateInputBuilder) FmcSpecificUid(fmcSpecificUid string) *UpdateInputBuilder {
b.updateInput.FmcSpecificUid = fmcSpecificUid
return b
}

func (b *UpdateInputBuilder) QueueTriggerState(queueTriggerState string) *UpdateInputBuilder {
b.updateInput.QueueTriggerState = queueTriggerState
return b
}

func (b *UpdateInputBuilder) StateMachineContext(stateMachineContext map[string]string) *UpdateInputBuilder {
b.updateInput.StateMachineContext = stateMachineContext
return b
}

func (b *UpdateInputBuilder) Build() UpdateInput {
return *b.updateInput
}
54 changes: 54 additions & 0 deletions client/device/cloudfmc/fmcappliance/update_outputbuilder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package fmcappliance

type UpdateOutputBuilder struct {
updateOutput *UpdateOutput
}

func NewUpdateOutputBuilder() *UpdateOutputBuilder {
updateOutput := &UpdateOutput{}
b := &UpdateOutputBuilder{updateOutput: updateOutput}
return b
}

func (b *UpdateOutputBuilder) Uid(uid string) *UpdateOutputBuilder {
b.updateOutput.Uid = uid
return b
}

func (b *UpdateOutputBuilder) State(state string) *UpdateOutputBuilder {
b.updateOutput.State = state
return b
}

func (b *UpdateOutputBuilder) DomainUid(domainUid string) *UpdateOutputBuilder {
b.updateOutput.DomainUid = domainUid
return b
}

func (b *UpdateOutputBuilder) Build() UpdateOutput {
return *b.updateOutput
}

type updateRequestBodyBuilder struct {
updateRequestBody *updateRequestBody
}

func newUpdateRequestBodyBuilder() *updateRequestBodyBuilder {
updateRequestBody := &updateRequestBody{}
b := &updateRequestBodyBuilder{updateRequestBody: updateRequestBody}
return b
}

func (b *updateRequestBodyBuilder) QueueTriggerState(queueTriggerState string) *updateRequestBodyBuilder {
b.updateRequestBody.QueueTriggerState = queueTriggerState
return b
}

func (b *updateRequestBodyBuilder) StateMachineContext(stateMachineContext map[string]string) *updateRequestBodyBuilder {
b.updateRequestBody.StateMachineContext = stateMachineContext
return b
}

func (b *updateRequestBodyBuilder) Build() updateRequestBody {
return *b.updateRequestBody
}
85 changes: 85 additions & 0 deletions client/device/cloudfmc/fmcappliance/update_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package fmcappliance_test

import (
"context"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc/fmcappliance"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"time"

internalHttp "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/jarcoal/httpmock"
)

func TestUpdate(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()

validUpdateOutput := fmcappliance.NewUpdateOutputBuilder().
Uid(uid).
State(state).
DomainUid(domainUid).
Build()

testCases := []struct {
testName string
input fmcappliance.UpdateInput
setupFunc func()
assertFunc func(input fmcappliance.UpdateInput, output *fmcappliance.UpdateOutput, err error, t *testing.T)
}{
{
testName: "successfully updates FMC Appliance name",
input: fmcappliance.NewUpdateInput(FmcSpecificUid, queueTriggerState, stateMachineContext),

setupFunc: func() {
httpmock.RegisterResponder(
http.MethodPut,
url.UpdateFmcAppliance(baseUrl, FmcSpecificUid),
httpmock.NewJsonResponderOrPanic(http.StatusOK, validUpdateOutput),
)
},

assertFunc: func(input fmcappliance.UpdateInput, output *fmcappliance.UpdateOutput, err error, t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, output)
assert.Equal(t, validUpdateOutput, *output)
},
},

{
testName: "error when update FMC Appliance name error",
input: fmcappliance.NewUpdateInput(FmcSpecificUid, queueTriggerState, stateMachineContext),

setupFunc: func() {
httpmock.RegisterResponder(
http.MethodPut,
url.UpdateFmcAppliance(baseUrl, FmcSpecificUid),
httpmock.NewJsonResponderOrPanic(http.StatusInternalServerError, "internal server error"),
)
},

assertFunc: func(input fmcappliance.UpdateInput, output *fmcappliance.UpdateOutput, err error, t *testing.T) {
assert.NotNil(t, err)
assert.Nil(t, output)
},
},
}

for _, testCase := range testCases {
t.Run(testCase.testName, func(t *testing.T) {
httpmock.Reset()

testCase.setupFunc()

output, err := fmcappliance.Update(
context.Background(),
*internalHttp.MustNewWithConfig(baseUrl, "a_valid_token", 0, 0, time.Minute),
testCase.input,
)

testCase.assertFunc(testCase.input, output, err, t)
})
}
}
20 changes: 20 additions & 0 deletions client/device/cloudfmc/fmcplatform/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fmcplatform

type ReadDomainInfoInputBuilder struct {
readDomainInfoInput *ReadDomainInfoInput
}

func NewReadDomainInfoInputBuilder() *ReadDomainInfoInputBuilder {
readDomainInfoInput := &ReadDomainInfoInput{}
b := &ReadDomainInfoInputBuilder{readDomainInfoInput: readDomainInfoInput}
return b
}

func (b *ReadDomainInfoInputBuilder) FmcHost(fmcHost string) *ReadDomainInfoInputBuilder {
b.readDomainInfoInput.FmcHost = fmcHost
return b
}

func (b *ReadDomainInfoInputBuilder) Build() ReadDomainInfoInput {
return *b.readDomainInfoInput
}
16 changes: 16 additions & 0 deletions client/device/cloudfmc/fmcplatform/fixture_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fmcplatform_test

const (
links = "unit-test-links"
count = 123
offset = 234
limit = 345
pages = 456
uuid = "unit-test-uuid"
name = "unit-test-name"
type_ = "unit-test-type"

fmcHostname = "unit-test-fmc.com"

baseUrl = "https://unit-test.cdo.cisco.com"
)
36 changes: 36 additions & 0 deletions client/device/cloudfmc/fmcplatform/readdomaininfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fmcplatform

import (
"context"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/cloudfmc/fmcdomain"
)

type ReadDomainInfoInput struct {
FmcHost string
}

func NewReadDomainInfo(fmcHost string) ReadDomainInfoInput {
return ReadDomainInfoInput{
FmcHost: fmcHost,
}
}

type ReadDomainInfoOutput = fmcdomain.Info

func ReadFmcDomainInfo(ctx context.Context, client http.Client, readInp ReadDomainInfoInput) (*ReadDomainInfoOutput, error) {

client.Logger.Println("reading FMC domain info")

readUrl := url.ReadFmcDomainInfo(readInp.FmcHost)

req := client.NewGet(ctx, readUrl)

var outp ReadDomainInfoOutput
if err := req.Send(&outp); err != nil {
return nil, err
}

return &outp, nil
}
Loading
Loading