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

fix: ResourceGroups lastUpdated time format #599

Merged
merged 8 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions api/alert_channels_splunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
package api_test

import (
"encoding/json"
"fmt"
"log"
"net/http"
"testing"
"time"

"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -139,6 +142,21 @@ func TestAlertChannelSplunkUpdate(t *testing.T) {
}
}

func TestMarshallAlertChannelLastUpdatedTime(t *testing.T) {
var res api.SplunkHecAlertChannelResponseV2
err := json.Unmarshal([]byte(generateAlertChannelResponse(singleSplunkAlertChannel("test"))), &res)
if err != nil {
log.Fatal("Unable to unmarshall splunk string")
}
jsonString, err := json.Marshal(res)
if err != nil {
log.Fatal("Unable to marshall splunk string")
}

assert.Equal(t, res.Data.State.LastUpdatedTime.ToTime().UnixNano()/int64(time.Millisecond), int64(1627895573122))
assert.Contains(t, string(jsonString), "1627895573122")
}

func singleSplunkAlertChannel(id string) string {
return `
{
Expand Down
12 changes: 12 additions & 0 deletions api/resource_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"strconv"

"github.com/pkg/errors"

"github.com/lacework/go-sdk/lwtime"
)

// ResourceGroupsService is the service that interacts with
Expand All @@ -32,6 +34,16 @@ type ResourceGroupsService struct {
client *Client
}

type ResourceGroupProps interface {
GetBaseProps() ResourceGroupPropsBase
}

type ResourceGroupPropsBase struct {
Description string `json:"description"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated *lwtime.Epoch `json:"lastUpdated,omitempty"`
}

type ResourceGroup interface {
ID() string
ResourceGroupType() ResourceGroupType
Expand Down
40 changes: 32 additions & 8 deletions api/resource_groups_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"strconv"

"github.com/lacework/go-sdk/lwtime"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -120,16 +121,39 @@ type AwsResourceGroupData struct {
}

type AwsResourceGroupProps struct {
Description string `json:"description,omitempty"`
AccountIDs []string `json:"accountIds"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated int `json:"lastUpdated,omitempty"`
Description string `json:"description,omitempty"`
AccountIDs []string `json:"accountIds"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated *lwtime.Epoch `json:"lastUpdated,omitempty"`
}

// Workaround for props being returned as a json string
type AwsResourceJsonStringGroupProps struct {
Description string `json:"DESCRIPTION,omitempty"`
AccountIDs []string `json:"ACCOUNT_IDS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated int `json:"LAST_UPDATED,omitempty"`
Description string `json:"DESCRIPTION,omitempty"`
AccountIDs []string `json:"ACCOUNT_IDS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated *lwtime.Epoch `json:"LAST_UPDATED,omitempty"`
}

func (props AwsResourceGroupProps) GetBaseProps() ResourceGroupPropsBase {
return ResourceGroupPropsBase{
Description: props.Description,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated,
}
}

func (props AwsResourceGroupProps) MarshalJSON() ([]byte, error) {
res := struct {
Description string `json:"description,omitempty"`
AccountIDs []string `json:"accountIds"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated string `json:"lastUpdated,omitempty"`
}{
dmurray-lacework marked this conversation as resolved.
Show resolved Hide resolved
Description: props.Description,
AccountIDs: props.AccountIDs,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated.String(),
}
return json.Marshal(&res)
}
18 changes: 18 additions & 0 deletions api/resource_groups_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
package api_test

import (
"encoding/json"
"fmt"
"log"
"net/http"
"testing"
"time"

"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -110,6 +113,21 @@ func TestResourceGroupsAwsUpdate(t *testing.T) {
assert.Equal(t, resourceGUID, response.Data.ResourceGuid)
}

func TestMarshallResourceGroupLastUpdatedTime(t *testing.T) {
var res api.AwsResourceGroupResponse
err := json.Unmarshal([]byte(generateResourceGroupResponse(singleAwsResourceGroupUpdateResponse("test"))), &res)
if err != nil {
log.Fatal("Unable to unmarshall aws resource group string")
}
jsonString, err := json.Marshal(res)
if err != nil {
log.Fatal("Unable to marshall aws resource group string")
}

assert.Equal(t, res.Data.Props.LastUpdated.ToTime().UnixNano()/int64(time.Millisecond), int64(1586453993470))
assert.Contains(t, string(jsonString), "2020-04-09T17:39:53Z")
}

func singleAwsResourceGroup(id string) string {
return `
{
Expand Down
46 changes: 36 additions & 10 deletions api/resource_groups_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"strconv"

"github.com/lacework/go-sdk/lwtime"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -124,18 +125,43 @@ type AzureResourceGroupData struct {
}

type AzureResourceGroupProps struct {
Description string `json:"description,omitempty"`
Tenant string `json:"tenant"`
Subscriptions []string `json:"subscriptions"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated int `json:"lastUpdated,omitempty"`
Description string `json:"description,omitempty"`
Tenant string `json:"tenant"`
Subscriptions []string `json:"subscriptions"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated *lwtime.Epoch `json:"lastUpdated,omitempty"`
}

// Workaround for props being returned as a json string
type AzureResourceJsonStringGroupProps struct {
Description string `json:"DESCRIPTION,omitempty"`
Tenant string `json:"TENANT"`
Subscriptions []string `json:"SUBSCRIPTIONS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated int `json:"LAST_UPDATED,omitempty"`
Description string `json:"DESCRIPTION,omitempty"`
Tenant string `json:"TENANT"`
Subscriptions []string `json:"SUBSCRIPTIONS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated *lwtime.Epoch `json:"LAST_UPDATED,omitempty"`
}

func (props AzureResourceGroupProps) GetBaseProps() ResourceGroupPropsBase {
return ResourceGroupPropsBase{
Description: props.Description,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated,
}
}

func (props AzureResourceGroupProps) MarshalJSON() ([]byte, error) {
res := struct {
Description string `json:"description,omitempty"`
Tenant string `json:"tenant"`
Subscriptions []string `json:"subscriptions"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated string `json:"lastUpdated,omitempty"`
}{
Description: props.Description,
Tenant: props.Tenant,
Subscriptions: props.Subscriptions,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated.String(),
}
return json.Marshal(&res)
}
30 changes: 28 additions & 2 deletions api/resource_groups_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"strconv"

"github.com/lacework/go-sdk/lwtime"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -128,7 +129,7 @@ type ContainerResourceGroupProps struct {
ContainerLabels []map[string]string `json:"containerLabels"`
ContainerTags []string `json:"containerTags"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated int `json:"lastUpdated,omitempty"`
LastUpdated *lwtime.Epoch `json:"lastUpdated,omitempty"`
}

// Workaround for props being returned as a json string
Expand All @@ -137,5 +138,30 @@ type ContainerResourceJsonStringGroupProps struct {
ContainerLabels []map[string]string `json:"CONTAINER_LABELS"`
ContainerTags []string `json:"CONTAINER_TAGS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated int `json:"LAST_UPDATED,omitempty"`
LastUpdated *lwtime.Epoch `json:"LAST_UPDATED,omitempty"`
}

func (props ContainerResourceGroupProps) GetBaseProps() ResourceGroupPropsBase {
return ResourceGroupPropsBase{
Description: props.Description,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated,
}
}

func (props ContainerResourceGroupProps) MarshalJSON() ([]byte, error) {
res := struct {
Description string `json:"description,omitempty"`
ContainerLabels []map[string]string `json:"containerLabels"`
ContainerTags []string `json:"containerTags"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated string `json:"lastUpdated,omitempty"`
}{
Description: props.Description,
ContainerLabels: props.ContainerLabels,
ContainerTags: props.ContainerTags,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated.String(),
}
return json.Marshal(&res)
}
46 changes: 36 additions & 10 deletions api/resource_groups_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"strconv"

"github.com/lacework/go-sdk/lwtime"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -122,18 +123,43 @@ type GcpResourceGroupData struct {
}

type GcpResourceGroupProps struct {
Description string `json:"description,omitempty"`
Organization string `json:"organization"`
Projects []string `json:"projects"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated int `json:"lastUpdated,omitempty"`
Description string `json:"description,omitempty"`
Organization string `json:"organization"`
Projects []string `json:"projects"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated *lwtime.Epoch `json:"lastUpdated,omitempty"`
}

// Workaround for props being returned as a json string
type GcpResourceGroupJsonStringProps struct {
Description string `json:"DESCRIPTION,omitempty"`
Organization string `json:"ORGANIZATION"`
Projects []string `json:"PROJECTS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated int `json:"LAST_UPDATED,omitempty"`
Description string `json:"DESCRIPTION,omitempty"`
Organization string `json:"ORGANIZATION"`
Projects []string `json:"PROJECTS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated *lwtime.Epoch `json:"LAST_UPDATED,omitempty"`
}

func (props GcpResourceGroupProps) GetBaseProps() ResourceGroupPropsBase {
return ResourceGroupPropsBase{
Description: props.Description,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated,
}
}

func (props GcpResourceGroupProps) MarshalJSON() ([]byte, error) {
res := struct {
Description string `json:"description,omitempty"`
Organization string `json:"organization"`
Projects []string `json:"projects"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated string `json:"lastUpdated,omitempty"`
}{
Description: props.Description,
Organization: props.Organization,
Projects: props.Projects,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated.String(),
}
return json.Marshal(&res)
}
40 changes: 32 additions & 8 deletions api/resource_groups_lw_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"strconv"

"github.com/lacework/go-sdk/lwtime"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -122,16 +123,39 @@ type LwAccountResourceGroupData struct {
}

type LwAccountResourceGroupProps struct {
Description string `json:"description,omitempty"`
LwAccounts []string `json:"lwAccounts"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated int `json:"lastUpdated,omitempty"`
Description string `json:"description,omitempty"`
LwAccounts []string `json:"lwAccounts"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated *lwtime.Epoch `json:"lastUpdated,omitempty"`
}

// Workaround for props being returned as a json string
type LwAccountResourceGroupJsonStringProps struct {
Description string `json:"DESCRIPTION,omitempty"`
LwAccounts []string `json:"LW_ACCOUNTS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated int `json:"LAST_UPDATED,omitempty"`
Description string `json:"DESCRIPTION,omitempty"`
LwAccounts []string `json:"LW_ACCOUNTS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated *lwtime.Epoch `json:"LAST_UPDATED,omitempty"`
}

func (props LwAccountResourceGroupProps) GetBaseProps() ResourceGroupPropsBase {
return ResourceGroupPropsBase{
Description: props.Description,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated,
}
}

func (props LwAccountResourceGroupProps) MarshalJSON() ([]byte, error) {
res := struct {
Description string `json:"description,omitempty"`
LwAccounts []string `json:"lwAccounts"`
UpdatedBy string `json:"updatedBy,omitempty"`
LastUpdated string `json:"lastUpdated,omitempty"`
}{
Description: props.Description,
LwAccounts: props.LwAccounts,
UpdatedBy: props.UpdatedBy,
LastUpdated: props.LastUpdated.String(),
}
return json.Marshal(&res)
}
Loading