Skip to content

Commit

Permalink
[LH-75098] Fix: Support label groups (#134)
Browse files Browse the repository at this point in the history
* WIP

* ci: temporarily enable acceptance tests for branch push

* fix: address broken tests

* docs: generate docs

* refactor: remove debugging logs

* refactor: make use of test fixtures rather than repeated literals

* ci: restore github ci definition after debugging
  • Loading branch information
Christopher Dickson authored Feb 29, 2024
1 parent a43f4d4 commit c764c62
Show file tree
Hide file tree
Showing 62 changed files with 849 additions and 221 deletions.
27 changes: 14 additions & 13 deletions client/device/asa/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package asa

import (
"context"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/connector"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/publicapi"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/publicapilabels"
)

type CreateInput struct {
Name string
ConnectorUid string
ConnectorType string
SocketAddress string
Tags tags.Type
Labels publicapilabels.Type

Username string
Password string
Expand All @@ -34,21 +35,21 @@ type CreateError struct {
}

type createBody struct {
Name string `json:"name"`
DeviceAddress string `json:"deviceAddress"`
Username string `json:"username"`
Password string `json:"password"`
ConnectorType string `json:"connectorType"`
IgnoreCertificate bool `json:"ignoreCertificate"`
ConnectorName string `json:"connectorName"`
Labels []string `json:"labels"`
Name string `json:"name"`
DeviceAddress string `json:"deviceAddress"`
Username string `json:"username"`
Password string `json:"password"`
ConnectorType string `json:"connectorType"`
IgnoreCertificate bool `json:"ignoreCertificate"`
ConnectorName string `json:"connectorName"`
Labels publicapilabels.Type `json:"labels"`
}

func (r *CreateError) Error() string {
return r.Err.Error()
}

func NewCreateRequestInput(name, connectorUid, connectorType, socketAddress, username, password string, ignoreCertificate bool, tags tags.Type) *CreateInput {
func NewCreateRequestInput(name, connectorUid, connectorType, socketAddress, username, password string, ignoreCertificate bool, labels publicapilabels.Type) *CreateInput {
return &CreateInput{
Name: name,
ConnectorUid: connectorUid,
Expand All @@ -57,7 +58,7 @@ func NewCreateRequestInput(name, connectorUid, connectorType, socketAddress, use
Username: username,
Password: password,
IgnoreCertificate: ignoreCertificate,
Tags: tags,
Labels: labels,
}
}

Expand Down Expand Up @@ -87,7 +88,7 @@ func Create(ctx context.Context, client http.Client, createInp CreateInput) (*Cr
ConnectorType: createInp.ConnectorType,
IgnoreCertificate: createInp.IgnoreCertificate,
ConnectorName: conn.Name,
Labels: createInp.Tags.Labels,
Labels: createInp.Labels,
},
)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions client/device/asa/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package asa_test

import (
"context"
"testing"
"time"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/publicapi/transaction/transactiontype"
internalTesting "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/testing"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/asa"
"github.com/jarcoal/httpmock"
Expand Down
1 change: 1 addition & 0 deletions client/device/asa/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package asa

import (
"context"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/devicetype"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/statemachine"
Expand Down
58 changes: 44 additions & 14 deletions client/device/cloudftd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ package cloudftd
import (
"context"
"fmt"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc/fmcplatform"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/cdo"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/publicapi"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/cloudfmc/accesspolicies"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/publicapilabels"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/devicetype"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/license"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/tier"
Expand All @@ -25,37 +26,57 @@ type CreateInput struct {
PerformanceTier *tier.Type // ignored if it is physical device
Virtual bool
Licenses *[]license.Type
Tags tags.Type
Labels publicapilabels.Type
}

type CreateOutput struct {
Uid string `json:"uid"`
Name string `json:"name"`
Metadata Metadata `json:"metadata,omitempty"`
State string `json:"state"`
Labels publicapilabels.Type `json:"labels"`
}

type CreateOutput = ReadOutput
func FromDeviceReadOutput(readOutput *ReadOutput) *CreateOutput {
if readOutput == nil {
return nil
}

return &CreateOutput{
Uid: readOutput.Uid,
Name: readOutput.Name,
Metadata: readOutput.Metadata,
State: readOutput.State,
Labels: publicapilabels.New(readOutput.Tags.UngroupedTags(), readOutput.Tags.GroupedTags()),
}
}

func NewCreateInput(
name string,
accessPolicyName string,
performanceTier *tier.Type,
virtual bool,
licenses *[]license.Type,
tags tags.Type,
labels publicapilabels.Type,
) CreateInput {
return CreateInput{
Name: name,
AccessPolicyName: accessPolicyName,
PerformanceTier: performanceTier,
Virtual: virtual,
Licenses: licenses,
Tags: tags,
Labels: labels,
}
}

type createRequestBody struct {
Name string `json:"name"`
DeviceType devicetype.Type `json:"deviceType"`
FmcAccessPolicyUid string `json:"fmcAccessPolicyUid"`
PerformanceTier *tier.Type `json:"performanceTier"`
Virtual bool `json:"virtual"`
Licenses *[]license.Type `json:"licenses"`
Labels []string `json:"labels"`
Name string `json:"name"`
DeviceType devicetype.Type `json:"deviceType"`
FmcAccessPolicyUid string `json:"fmcAccessPolicyUid"`
PerformanceTier *tier.Type `json:"performanceTier"`
Virtual bool `json:"virtual"`
Licenses *[]license.Type `json:"licenses"`
Labels publicapilabels.Type `json:"labels"`
}

func Create(ctx context.Context, client http.Client, createInp CreateInput) (*CreateOutput, error) {
Expand All @@ -79,7 +100,7 @@ func Create(ctx context.Context, client http.Client, createInp CreateInput) (*Cr
FmcAccessPolicyUid: selectedPolicy.Id,
PerformanceTier: createInp.PerformanceTier,
Virtual: createInp.Virtual,
Labels: createInp.Tags.Labels,
Labels: createInp.Labels,
Licenses: createInp.Licenses,
},
)
Expand All @@ -99,7 +120,12 @@ func Create(ctx context.Context, client http.Client, createInp CreateInput) (*Cr
return nil, err
}

return ReadByUid(ctx, client, NewReadByUidInput(transaction.EntityUid))
cloudFtdReadOutput, err := ReadByUid(ctx, client, NewReadByUidInput(transaction.EntityUid))
if err != nil {
return nil, err
}

return FromDeviceReadOutput(cloudFtdReadOutput), nil
}

func readPolicyUidFromPolicyName(ctx context.Context, client http.Client, accessPolicyName string) (accesspolicies.Item, error) {
Expand All @@ -123,6 +149,10 @@ func readPolicyUidFromPolicyName(ctx context.Context, client http.Client, access
client,
cloudfmc.NewReadAccessPoliciesInput(fmcRes.Host, readFmcDomainRes.Items[0].Uuid, 1000), // 1000 is what CDO UI uses
)
if err != nil {
return accesspolicies.Item{}, err
}

selectedPolicy, ok := accessPoliciesRes.Find(accessPolicyName)
if !ok {
return accesspolicies.Item{}, fmt.Errorf(
Expand Down
8 changes: 5 additions & 3 deletions client/device/cloudftd/create_outputbuilder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cloudftd

import "github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
import (
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/publicapilabels"
)

type CreateOutputBuilder struct {
createOutput *CreateOutput
Expand All @@ -27,8 +29,8 @@ func (b *CreateOutputBuilder) Metadata(metadata Metadata) *CreateOutputBuilder {
return b
}

func (b *CreateOutputBuilder) Tags(tags tags.Type) *CreateOutputBuilder {
b.createOutput.Tags = tags
func (b *CreateOutputBuilder) Labels(labels publicapilabels.Type) *CreateOutputBuilder {
b.createOutput.Labels = labels
return b
}

Expand Down
9 changes: 5 additions & 4 deletions client/device/cloudftd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package cloudftd_test

import (
"context"
"net/http"
"testing"
"time"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudftd"
internalHttp "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
Expand All @@ -10,9 +14,6 @@ import (
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"time"
)

func TestCreateCloudFtd(t *testing.T) {
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestCreateCloudFtd(t *testing.T) {
assertFunc: func(output *cloudftd.CreateOutput, err error, t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, output)
assert.Equal(t, *output, ftdReadOutput)
assert.Equal(t, output, cloudftd.FromDeviceReadOutput(&ftdReadOutput))
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions client/device/cloudftd/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc/fmcappliance"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudftd"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/statemachine"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/testing"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/cloudfmc/accesspolicies"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/cloudfmc/fmcconfig"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/cloudfmc/fmcdomain"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/license"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/tier"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/statemachine/state"
Expand Down Expand Up @@ -66,7 +66,7 @@ const (
var (
ftdLicenseCaps = &[]license.Type{license.Base, license.Carrier}
ftdPerformanceTier = tier.FTDv5
ftdTags = tags.New("tags1", "tags2", "tags3")
ftdTags = testing.NewTestingTags()
)

var (
Expand Down
1 change: 1 addition & 0 deletions client/device/cloudftd/read_by_uid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cloudftd

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/device/tags"
Expand Down
3 changes: 2 additions & 1 deletion client/device/cloudftd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cloudftd

import (
"context"
"time"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc/fmcappliance"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc/fmcplatform"
Expand All @@ -10,7 +12,6 @@ import (
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/license"
"time"
)

type UpdateInput struct {
Expand Down
11 changes: 6 additions & 5 deletions client/device/cloudftd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package cloudftd_test

import (
"context"
"net/http"
"testing"
"time"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudfmc/fmcplatform"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/cloudftd"
internalHttp "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
internalTesting "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/testing"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/cloudfmc/devicelicense"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/tags"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/ftd/license"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/statemachine/state"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"time"
)

func TestUpdateCloudFtd(t *testing.T) {
Expand All @@ -29,7 +30,7 @@ func TestUpdateCloudFtd(t *testing.T) {
Uid("test-uid").
Licenses([]license.Type{license.Essentials}).
Name("test-name").
Tags(tags.Type{Labels: []string{"test-tag"}}).
Tags(internalTesting.NewTestingTags()).
Build()

testMetadata := cloudftd.NewMetadataBuilder().
Expand Down
12 changes: 7 additions & 5 deletions client/device/duoadminpanel/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package duoadminpanel

import (
"context"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/publicapi"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/model/device/publicapilabels"
)

type CreateInput struct {
Name string `json:"name"`
Host string `json:"host"`
IntegrationKey string `json:"integrationKey"`
SecretKey string `json:"secretKey"`
Labels []string `json:"labels"`
Name string `json:"name"`
Host string `json:"host"`
IntegrationKey string `json:"integrationKey"`
SecretKey string `json:"secretKey"`
Labels publicapilabels.Type `json:"labels"`
}

type CreateOutput = ReadOutput
Expand Down
5 changes: 3 additions & 2 deletions client/device/duoadminpanel/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package duoadminpanel_test

import (
"context"
"testing"
"time"

"github.com/CiscoDevnet/terraform-provider-cdo/go-client/device/duoadminpanel"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/publicapi/transaction/transactiontype"
internalTesting "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/testing"
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url"
"github.com/stretchr/testify/assert"
"testing"
"time"

internalHttp "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http"
"github.com/jarcoal/httpmock"
Expand Down
1 change: 1 addition & 0 deletions client/device/duoadminpanel/read_by_uid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package duoadminpanel

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/device/tags"
Expand Down
Loading

0 comments on commit c764c62

Please sign in to comment.