Skip to content

Commit 9845496

Browse files
refactor(users): refactor users to use new v2 client (#297)
* chore(deps): bump github.com/docker/docker Bumps [github.com/docker/docker](https://github.com/docker/docker) from 20.10.12+incompatible to 20.10.24+incompatible. - [Release notes](https://github.com/docker/docker/releases) - [Commits](moby/moby@v20.10.12...v20.10.24) --- updated-dependencies: - dependency-name: github.com/docker/docker dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * refactor(teams): refactor users to use new v2 client * feat(users): remove old users client --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent b27f2dc commit 9845496

24 files changed

+335
-231
lines changed

GNUmakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ TERRAFORM_PROVIDER_DEV_VERSION=1.0.0
1313
TERRAFORM_PLATFORM=$(shell terraform version -json | jq -r .platform)
1414
TERRAFORM_SYSDIG_PLUGIN_DIR=$(TERRAFORM_PLUGIN_ROOT_DIR)/$(TERRAFORM_PROVIDER_REFERENCE_NAME)/$(TERRAFORM_PROVIDER_NAME)/$(TERRAFORM_PROVIDER_DEV_VERSION)/$(TERRAFORM_PLATFORM)
1515

16+
install-tools:
17+
go install golang.org/x/tools/cmd/stringer@latest
18+
1619
default: build
1720

1821
build: fmtcheck

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/davecgh/go-spew v1.1.1 // indirect
2323
github.com/docker/cli v20.10.12+incompatible // indirect
2424
github.com/docker/distribution v2.8.1+incompatible // indirect
25-
github.com/docker/docker v20.10.12+incompatible // indirect
25+
github.com/docker/docker v20.10.24+incompatible // indirect
2626
github.com/docker/docker-credential-helpers v0.6.4 // indirect
2727
github.com/falcosecurity/kilt/pkg v0.0.0-20211102134108-7c97c711c0d2 // indirect
2828
github.com/fatih/color v1.13.0 // indirect

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4Kfc
298298
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
299299
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
300300
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
301-
github.com/docker/docker v20.10.12+incompatible h1:CEeNmFM0QZIsJCZKMkZx0ZcahTiewkrgiwfYD+dfl1U=
302301
github.com/docker/docker v20.10.12+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
302+
github.com/docker/docker v20.10.24+incompatible h1:Ugvxm7a8+Gz6vqQYQQ2W7GYq5EUPaAiuPgIfVyI3dYE=
303+
github.com/docker/docker v20.10.24+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
303304
github.com/docker/docker-credential-helpers v0.6.3/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y=
304305
github.com/docker/docker-credential-helpers v0.6.4 h1:axCks+yV+2MR3/kZhAmy07yC56WZ2Pwu/fKWtKuZB0o=
305306
github.com/docker/docker-credential-helpers v0.6.4/go.mod h1:ofX3UI0Gz1TteYBjtgs07O36Pyasyp66D2uKT7H8W1c=

sysdig/clienttype_string.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sysdig/common_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,33 @@ package sysdig_test
44

55
import (
66
"os"
7+
"strings"
78
"testing"
89
)
910

11+
const (
12+
SysdigMonitorApiTokenEnv = "SYSDIG_MONITOR_API_TOKEN"
13+
SysdigSecureApiTokenEnv = "SYSDIG_SECURE_API_TOKEN"
14+
SysdigIBMMonitorAPIKeyEnv = "SYSDIG_IBM_MONITOR_API_KEY"
15+
)
16+
17+
func isAnyEnvSet(envs ...string) bool {
18+
for _, env := range envs {
19+
if value := os.Getenv(env); value != "" {
20+
return true
21+
}
22+
}
23+
return false
24+
}
25+
26+
func preCheckAnyEnv(t *testing.T, envs ...string) func() {
27+
return func() {
28+
if !isAnyEnvSet(envs...) {
29+
t.Fatalf("%s must be set for acceptance tests", strings.Join(envs, " or "))
30+
}
31+
}
32+
}
33+
1034
func sysdigOrIBMMonitorPreCheck(t *testing.T) func() {
1135
return func() {
1236
monitor := os.Getenv("SYSDIG_MONITOR_API_TOKEN")

sysdig/data_source_sysdig_current_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func dataSourceSysdigCurrentUser() *schema.Resource {
4242

4343
// Retrieves the information of a resource form the file and loads it in Terraform
4444
func dataSourceSysdigCurrentUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
45-
client, err := meta.(SysdigClients).sysdigCommonClient()
45+
client, err := meta.(SysdigClients).commonClientV2()
4646
if err != nil {
4747
return diag.FromErr(err)
4848
}

sysdig/data_source_sysdig_current_user_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
//go:build tf_acc_sysdig
1+
//go:build tf_acc_sysdig || tf_acc_ibm
22

33
package sysdig_test
44

55
import (
6-
"os"
76
"testing"
87

98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -14,13 +13,7 @@ import (
1413

1514
func TestAccCurrentUser(t *testing.T) {
1615
resource.ParallelTest(t, resource.TestCase{
17-
PreCheck: func() {
18-
monitor := os.Getenv("SYSDIG_MONITOR_API_TOKEN")
19-
secure := os.Getenv("SYSDIG_SECURE_API_TOKEN")
20-
if monitor == "" && secure == "" {
21-
t.Fatal("either SYSDIG_MONITOR_API_TOKEN or SYSDIG_SECURE_API_TOKEN must be set for acceptance tests")
22-
}
23-
},
16+
PreCheck: preCheckAnyEnv(t, SysdigMonitorApiTokenEnv, SysdigSecureApiTokenEnv, SysdigIBMMonitorAPIKeyEnv),
2417
ProviderFactories: map[string]func() (*schema.Provider, error){
2518
"sysdig": func() (*schema.Provider, error) {
2619
return sysdig.Provider(), nil

sysdig/data_source_sysdig_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func dataSourceSysdigUser() *schema.Resource {
4545
}
4646

4747
func dataSourceSysdigUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
48-
client, err := meta.(SysdigClients).sysdigCommonClient()
48+
client, err := meta.(SysdigClients).sysdigCommonClientV2()
4949
if err != nil {
5050
return diag.FromErr(err)
5151
}

sysdig/data_source_sysdig_user_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package sysdig_test
44

55
import (
6-
"os"
76
"testing"
87

98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -14,13 +13,7 @@ import (
1413

1514
func TestAccDataUser(t *testing.T) {
1615
resource.ParallelTest(t, resource.TestCase{
17-
PreCheck: func() {
18-
monitor := os.Getenv("SYSDIG_MONITOR_API_TOKEN")
19-
secure := os.Getenv("SYSDIG_SECURE_API_TOKEN")
20-
if monitor == "" && secure == "" {
21-
t.Fatal("either SYSDIG_MONITOR_API_TOKEN or SYSDIG_SECURE_API_TOKEN must be set for acceptance tests")
22-
}
23-
},
16+
PreCheck: preCheckAnyEnv(t, SysdigMonitorApiTokenEnv, SysdigSecureApiTokenEnv),
2417
ProviderFactories: map[string]func() (*schema.Provider, error){
2518
"sysdig": func() (*schema.Provider, error) {
2619
return sysdig.Provider(), nil

sysdig/internal/client/common/client.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ import (
1212
)
1313

1414
type SysdigCommonClient interface {
15-
CreateUser(context.Context, *User) (*User, error)
16-
GetUserById(context.Context, int) (*User, error)
17-
GetUserByEmail(context.Context, string) (*User, error)
18-
DeleteUser(context.Context, int) error
19-
UpdateUser(context.Context, *User) (*User, error)
20-
GetCurrentUser(context.Context) (*User, error)
21-
2215
CreateGroupMapping(ctx context.Context, request *GroupMapping) (*GroupMapping, error)
2316
UpdateGroupMapping(ctx context.Context, request *GroupMapping, id int) (*GroupMapping, error)
2417
DeleteGroupMapping(ctx context.Context, id int) error

0 commit comments

Comments
 (0)