Skip to content
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
7 changes: 6 additions & 1 deletion sysdig/data_source_agent_access_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sysdig

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

Expand Down Expand Up @@ -68,8 +69,12 @@ func dataSourceSysdigAgentAccessKeyRead(ctx context.Context, d *schema.ResourceD
}

agentKeyID := d.Get("id").(int)
agentAccessKey, err := client.GetAgentAccessKeyByID(ctx, strconv.Itoa(agentKeyID))
agentAccessKey, statusCode, err := client.GetAgentAccessKeyByID(ctx, strconv.Itoa(agentKeyID))
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
}
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(agentAccessKey.ID))
Expand Down
7 changes: 6 additions & 1 deletion sysdig/data_source_sysdig_monitor_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sysdig

import (
"context"
"net/http"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -120,8 +121,12 @@ func dataSourceSysdigMonitorTeamRead(ctx context.Context, d *schema.ResourceData
return diag.FromErr(err)
}

team, err := client.GetTeamByID(ctx, id)
team, statusCode, err := client.GetTeamByID(ctx, id)
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
}
return diag.FromErr(err)
}

Expand Down
7 changes: 6 additions & 1 deletion sysdig/data_source_sysdig_secure_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sysdig

import (
"context"
"net/http"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -99,8 +100,12 @@ func dataSourceSysdigSecureTeamRead(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(err)
}

team, err := client.GetTeamByID(ctx, id)
team, statusCode, err := client.GetTeamByID(ctx, id)
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
}
return diag.FromErr(err)
}

Expand Down
10 changes: 8 additions & 2 deletions sysdig/data_source_sysdig_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sysdig

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

Expand Down Expand Up @@ -50,9 +51,14 @@ func dataSourceSysdigUserRead(ctx context.Context, d *schema.ResourceData, meta
return diag.FromErr(err)
}

u, err := client.GetUserByEmail(ctx, d.Get("email").(string))
u, statusCode, err := client.GetUserByEmail(ctx, d.Get("email").(string))
if err != nil {
return diag.FromErr(err)
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
}

d.SetId(strconv.Itoa(u.ID))
Expand Down
11 changes: 6 additions & 5 deletions sysdig/internal/client/v2/agentaccesskey.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ const (

type AgentAccessKeyInterface interface {
Base
GetAgentAccessKeyByID(ctx context.Context, id string) (*AgentAccessKey, error)
GetAgentAccessKeyByID(ctx context.Context, id string) (*AgentAccessKey, int, error)
CreateAgentAccessKey(ctx context.Context, agentAccessKey *AgentAccessKey) (*AgentAccessKey, error)
DeleteAgentAccessKey(ctx context.Context, id string) error
UpdateAgentAccessKey(ctx context.Context, agentAccessKey *AgentAccessKey, id string) (*AgentAccessKey, error)
}

func (c *Client) GetAgentAccessKeyByID(ctx context.Context, id string) (accessKey *AgentAccessKey, err error) {
func (c *Client) GetAgentAccessKeyByID(ctx context.Context, id string) (accessKey *AgentAccessKey, statusCode int, err error) {
response, err := c.requester.Request(ctx, http.MethodGet, c.getAgentAccessKeyByIDUrl(id), nil)
if err != nil {
return nil, err
return nil, 0, err
}
defer func() {
if dErr := response.Body.Close(); dErr != nil {
Expand All @@ -34,10 +34,11 @@ func (c *Client) GetAgentAccessKeyByID(ctx context.Context, id string) (accessKe

if response.StatusCode != http.StatusOK {
err = c.ErrorFromResponse(response)
return nil, err
return nil, response.StatusCode, err
}

return Unmarshal[*AgentAccessKey](response.Body)
result, err := Unmarshal[*AgentAccessKey](response.Body)
return result, response.StatusCode, err
}

func (c *Client) CreateAgentAccessKey(ctx context.Context, agentAccessKey *AgentAccessKey) (createdAccessKey *AgentAccessKey, err error) {
Expand Down
12 changes: 6 additions & 6 deletions sysdig/internal/client/v2/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
type TeamInterface interface {
Base
GetUserIDByEmail(ctx context.Context, userRoles []UserRoles) ([]UserRoles, error)
GetTeamByID(ctx context.Context, id int) (t Team, err error)
GetTeamByID(ctx context.Context, id int) (t Team, statusCode int, err error)
CreateTeam(ctx context.Context, tRequest Team) (t Team, err error)
UpdateTeam(ctx context.Context, tRequest Team) (t Team, err error)
DeleteTeam(ctx context.Context, id int) error
Expand Down Expand Up @@ -66,10 +66,10 @@ func (c *Client) GetUserIDByEmail(ctx context.Context, userRoles []UserRoles) (m
return modifiedUserRoles, nil
}

func (c *Client) GetTeamByID(ctx context.Context, id int) (team Team, err error) {
func (c *Client) GetTeamByID(ctx context.Context, id int) (team Team, statusCode int, err error) {
response, err := c.requester.Request(ctx, http.MethodGet, c.getTeamURL(id), nil)
if err != nil {
return Team{}, err
return Team{}, 0, err
}
defer func() {
if dErr := response.Body.Close(); dErr != nil {
Expand All @@ -78,15 +78,15 @@ func (c *Client) GetTeamByID(ctx context.Context, id int) (team Team, err error)
}()

if response.StatusCode != http.StatusOK {
return Team{}, c.ErrorFromResponse(response)
return Team{}, response.StatusCode, c.ErrorFromResponse(response)
}

wrapper, err := Unmarshal[teamWrapper](response.Body)
if err != nil {
return Team{}, c.ErrorFromResponse(response)
return Team{}, response.StatusCode, c.ErrorFromResponse(response)
}

return wrapper.Team, err
return wrapper.Team, response.StatusCode, err
}

func (c *Client) CreateTeam(ctx context.Context, team Team) (createdTeam Team, err error) {
Expand Down
28 changes: 14 additions & 14 deletions sysdig/internal/client/v2/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ const (

type UserInterface interface {
Base
GetUserByID(ctx context.Context, id int) (*User, error)
GetUserByUsername(ctx context.Context, username string) (*User, error)
GetUserByEmail(ctx context.Context, email string) (*User, error)
GetUserByID(ctx context.Context, id int) (*User, int, error)
GetUserByUsername(ctx context.Context, username string) (*User, int, error)
GetUserByEmail(ctx context.Context, email string) (*User, int, error)
CreateUser(ctx context.Context, user *User) (*User, error)
UpdateUser(ctx context.Context, user *User) (*User, error)
DeleteUser(ctx context.Context, id int) error
GetCurrentUser(ctx context.Context) (u *User, err error)
}

func (c *Client) GetUserByID(ctx context.Context, id int) (user *User, error error) {
func (c *Client) GetUserByID(ctx context.Context, id int) (user *User, statusCode int, error error) {
response, err := c.requester.Request(ctx, http.MethodGet, c.getUserURL(id), nil)
if err != nil {
return nil, err
return nil, 0, err
}
defer func() {
if dErr := response.Body.Close(); dErr != nil {
Expand All @@ -38,21 +38,21 @@ func (c *Client) GetUserByID(ctx context.Context, id int) (user *User, error err
}()

if response.StatusCode != http.StatusOK {
return nil, c.ErrorFromResponse(response)
return nil, response.StatusCode, c.ErrorFromResponse(response)
}

wrapper, err := Unmarshal[userWrapper](response.Body)
if err != nil {
return nil, err
return nil, 0, err
}

return &wrapper.User, nil
return &wrapper.User, response.StatusCode, nil
}

func (c *Client) GetUserByUsername(ctx context.Context, username string) (user *User, err error) {
func (c *Client) GetUserByUsername(ctx context.Context, username string) (user *User, statusCode int, err error) {
response, err := c.requester.Request(ctx, http.MethodGet, c.getUserByUsernameURL(username), nil)
if err != nil {
return nil, err
return nil, 0, err
}
defer func() {
if dErr := response.Body.Close(); dErr != nil {
Expand All @@ -61,18 +61,18 @@ func (c *Client) GetUserByUsername(ctx context.Context, username string) (user *
}()

if response.StatusCode != http.StatusOK {
return nil, c.ErrorFromResponse(response)
return nil, response.StatusCode, c.ErrorFromResponse(response)
}

wrapper, err := Unmarshal[userWrapper](response.Body)
if err != nil {
return nil, err
return nil, 0, err
}

return &wrapper.User, nil
return &wrapper.User, response.StatusCode, nil
}

func (c *Client) GetUserByEmail(ctx context.Context, email string) (*User, error) {
func (c *Client) GetUserByEmail(ctx context.Context, email string) (*User, int, error) {
return c.GetUserByUsername(ctx, email)
}

Expand Down
7 changes: 6 additions & 1 deletion sysdig/resource_sysdig_agent_access_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sysdig
import (
"context"
"fmt"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -157,8 +158,12 @@ func resourceSysdigAgentAccessKeyRead(ctx context.Context, d *schema.ResourceDat

agentKeyID := d.Id()

agentAccessKey, err := client.GetAgentAccessKeyByID(ctx, agentKeyID)
agentAccessKey, statusCode, err := client.GetAgentAccessKeyByID(ctx, agentKeyID)
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
}
return diag.FromErr(err)
}

Expand Down
8 changes: 6 additions & 2 deletions sysdig/resource_sysdig_monitor_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sysdig

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

Expand Down Expand Up @@ -183,9 +184,12 @@ func resourceSysdigMonitorTeamRead(ctx context.Context, d *schema.ResourceData,
}

id, _ := strconv.Atoi(d.Id())
t, err := client.GetTeamByID(ctx, id)
t, statusCode, err := client.GetTeamByID(ctx, id)
if err != nil {
d.SetId("")
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
}
return diag.FromErr(err)
}

Expand Down
1 change: 1 addition & 0 deletions sysdig/resource_sysdig_secure_custom_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func resourceSysdigCustomPolicyRead(ctx context.Context, d *schema.ResourceData,
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand Down
3 changes: 3 additions & 0 deletions sysdig/resource_sysdig_secure_managed_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func resourceSysdigManagedPolicyRead(ctx context.Context, d *schema.ResourceData
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand All @@ -139,6 +140,7 @@ func resourceSysdigManagedPolicyDelete(ctx context.Context, d *schema.ResourceDa
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -176,6 +178,7 @@ func resourceSysdigManagedPolicyUpdate(ctx context.Context, d *schema.ResourceDa
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand Down
1 change: 1 addition & 0 deletions sysdig/resource_sysdig_secure_rule_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func resourceSysdigRuleContainerRead(ctx context.Context, d *schema.ResourceData
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand Down
1 change: 1 addition & 0 deletions sysdig/resource_sysdig_secure_rule_falco.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func resourceSysdigRuleFalcoRead(ctx context.Context, d *schema.ResourceData, me
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand Down
1 change: 1 addition & 0 deletions sysdig/resource_sysdig_secure_rule_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func resourceSysdigRuleFilesystemRead(ctx context.Context, d *schema.ResourceDat
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand Down
1 change: 1 addition & 0 deletions sysdig/resource_sysdig_secure_rule_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func resourceSysdigRuleNetworkRead(ctx context.Context, d *schema.ResourceData,
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand Down
1 change: 1 addition & 0 deletions sysdig/resource_sysdig_secure_rule_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func resourceSysdigRuleProcessRead(ctx context.Context, d *schema.ResourceData,
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand Down
1 change: 1 addition & 0 deletions sysdig/resource_sysdig_secure_rule_syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func resourceSysdigRuleSyscallRead(ctx context.Context, d *schema.ResourceData,
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
} else {
return diag.FromErr(err)
}
Expand Down
8 changes: 6 additions & 2 deletions sysdig/resource_sysdig_secure_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sysdig
import (
"context"
"fmt"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -178,9 +179,12 @@ func resourceSysdigSecureTeamRead(ctx context.Context, d *schema.ResourceData, m
}

id, _ := strconv.Atoi(d.Id())
t, err := client.GetTeamByID(ctx, id)
t, statusCode, err := client.GetTeamByID(ctx, id)
if err != nil {
d.SetId("")
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
}
return diag.FromErr(err)
}

Expand Down
Loading
Loading