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 7 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
11 changes: 11 additions & 0 deletions api/resource_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"strconv"

"github.com/lacework/go-sdk/lwtime"
dmurray-lacework marked this conversation as resolved.
Show resolved Hide resolved
"github.com/pkg/errors"
)

Expand All @@ -32,6 +33,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)
}
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)
}
28 changes: 26 additions & 2 deletions api/resource_groups_machine.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 @@ -125,13 +126,36 @@ type MachineResourceGroupProps struct {
Description string `json:"description,omitempty"`
MachineTags []map[string]string `json:"machineTags"`
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
type MachineResourceGroupJsonStringProps struct {
Description string `json:"DESCRIPTION,omitempty"`
MachineTags []map[string]string `json:"MACHINE_TAGS"`
UpdatedBy string `json:"UPDATED_BY,omitempty"`
LastUpdated int `json:"LAST_UPDATED,omitempty"`
LastUpdated *lwtime.Epoch `json:"LAST_UPDATED,omitempty"`
}

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

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