Skip to content

Commit

Permalink
fix: using context.Context in every resource
Browse files Browse the repository at this point in the history
  • Loading branch information
theobori committed Jul 4, 2023
1 parent 028e25c commit c07a801
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Provider metadata and versionning
PROVIDER = neuvector
VERSION = 0.4.3
VERSION = 0.4.4
RELEASE_VERSION ?= v$(VERSION)

# Terraform metadata for installation
Expand Down
6 changes: 4 additions & 2 deletions internal/resources/neuvector/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, meta any)
return nil
}

func resourceGroupRead(_ context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
APIClient := meta.(*goneuvector.Client)

groupData, err := APIClient.GetGroup(d.Id())
groupData, err := APIClient.
WithContext(ctx).
GetGroup(d.Id())

if err != nil {
return diag.FromErr(err)
Expand Down
16 changes: 9 additions & 7 deletions internal/resources/neuvector/resource_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta any) d
return nil
}

func resourcePolicyDelete(_ context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
func resourcePolicyDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
APIClient := meta.(*goneuvector.Client)

params := GetScopeChanges(d.Get("rules_scope").(string))
Expand All @@ -358,12 +358,14 @@ func resourcePolicyDelete(_ context.Context, d *schema.ResourceData, meta any) d
return diag.FromErr(err)
}

APIClient.PatchPolicy(
goneuvector.PatchPolicyBody{
Delete: delete,
},
params.IsFed,
)
APIClient.
WithContext(ctx).
PatchPolicy(
goneuvector.PatchPolicyBody{
Delete: delete,
},
params.IsFed,
)

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/resources/neuvector/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func resolveGroupName(d *schema.ResourceData) string {
return name
}

func resourceServiceCreate(_ context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
APIClient := meta.(*goneuvector.Client)

body := helper.FromSchemas[goneuvector.CreateServiceBody](
Expand All @@ -85,7 +85,7 @@ func resourceServiceCreate(_ context.Context, d *schema.ResourceData, meta any)
return nil
}

func resourceServiceUpdate(_ context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
func resourceServiceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
if !d.HasChanges(
"policy_mode",
"baseline_profile",
Expand All @@ -103,7 +103,7 @@ func resourceServiceUpdate(_ context.Context, d *schema.ResourceData, meta any)

body.Services = []string{d.Id()}

if err := APIClient.PatchServiceConfig(body); err != nil {
if err := APIClient.WithContext(ctx).PatchServiceConfig(body); err != nil {
return diag.FromErr(err)
}

Expand Down

0 comments on commit c07a801

Please sign in to comment.