Skip to content

Commit

Permalink
fix: comment the enpoint code
Browse files Browse the repository at this point in the history
  • Loading branch information
lriberon committed Jan 2, 2025
1 parent b00bb56 commit 49628ea
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 195 deletions.
153 changes: 77 additions & 76 deletions datadome/resource_custom_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package datadome
import (
"context"
"fmt"
"strconv"
"strings"
"time"

dd "github.com/datadome/terraform-provider/datadome-client-go"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -122,114 +124,113 @@ func resourceCustomRule() *schema.Resource {
// resourceCustomRuleCreate is used to create new custom rule
func resourceCustomRuleCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
config := m.(*ProviderConfig)
_ = config.ClientCustomRule
c := config.ClientCustomRule

// Warning or errors can be collected in a slice type
var diags diag.Diagnostics

// newCustomRule := dd.CustomRule{
// Name: d.Get("name").(string),
// Response: d.Get("response").(string),
// Query: d.Get("query").(string),
// EndpointType: d.Get("endpoint_type").(string),
// Priority: d.Get("priority").(string),
// Enabled: d.Get("enabled").(bool),
// }
newCustomRule := dd.CustomRule{
Name: d.Get("name").(string),
Response: d.Get("response").(string),
Query: d.Get("query").(string),
EndpointType: d.Get("endpoint_type").(string),
Priority: d.Get("priority").(string),
Enabled: d.Get("enabled").(bool),
}

// id, err := c.Create(ctx, newCustomRule)
// if err != nil {
// return diag.FromErr(err)
// }
id, err := c.Create(ctx, newCustomRule)
if err != nil {
return diag.FromErr(err)
}

// d.SetId(strconv.Itoa(*id))
d.SetId(strconv.Itoa(*id))

return diags
}

// resourceCustomRuleRead is used to fetch the custom rule by its ID
func resourceCustomRuleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
config := m.(*ProviderConfig)
_ = config.ClientCustomRule
c := config.ClientCustomRule

var diags diag.Diagnostics

// id, err := strconv.Atoi(d.Id())
// if err != nil {
// return diag.FromErr(err)
// }

// customRule, err := c.Read(ctx, id)
// if err != nil {
// return diag.FromErr(err)
// }

// if err = d.Set("name", customRule.Name); err != nil {
// return diag.FromErr(err)
// }
// if err = d.Set("response", customRule.Response); err != nil {
// return diag.FromErr(err)
// }
// if err = d.Set("query", customRule.Query); err != nil {
// return diag.FromErr(err)
// }
// if err = d.Set("endpoint_type", customRule.EndpointType); err != nil {
// return diag.FromErr(err)
// }
// if err = d.Set("priority", customRule.Priority); err != nil {
// return diag.FromErr(err)
// }
// if err = d.Set("enabled", customRule.Enabled); err != nil {
// return diag.FromErr(err)
// }
id, err := strconv.Atoi(d.Id())
if err != nil {
return diag.FromErr(err)
}

customRule, err := c.Read(ctx, id)
if err != nil {
return diag.FromErr(err)
}

if err = d.Set("name", customRule.Name); err != nil {
return diag.FromErr(err)
}
if err = d.Set("response", customRule.Response); err != nil {
return diag.FromErr(err)
}
if err = d.Set("query", customRule.Query); err != nil {
return diag.FromErr(err)
}
if err = d.Set("endpoint_type", customRule.EndpointType); err != nil {
return diag.FromErr(err)
}
if err = d.Set("priority", customRule.Priority); err != nil {
return diag.FromErr(err)
}
if err = d.Set("enabled", customRule.Enabled); err != nil {
return diag.FromErr(err)
}

return diags
}

// resourceCustomRuleUpdate is used to update a custom rule by its ID
func resourceCustomRuleUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
config := m.(*ProviderConfig)
_ = config.ClientCustomRule

// id, err := strconv.Atoi(d.Id())
// if err != nil {
// return diag.FromErr(err)
// }

// newCustomRule := dd.CustomRule{
// ID: id,
// Name: d.Get("name").(string),
// Response: d.Get("response").(string),
// Query: d.Get("query").(string),
// EndpointType: d.Get("endpoint_type").(string),
// Priority: d.Get("priority").(string),
// Enabled: d.Get("enabled").(bool),
// }

// o, err := c.Update(ctx, newCustomRule)
// if err != nil {
// return diag.FromErr(err)
// }
// d.SetId(strconv.Itoa(o.ID))
// return resourceCustomRuleRead(ctx, d, m)
return nil
c := config.ClientCustomRule

id, err := strconv.Atoi(d.Id())
if err != nil {
return diag.FromErr(err)
}

newCustomRule := dd.CustomRule{
ID: id,
Name: d.Get("name").(string),
Response: d.Get("response").(string),
Query: d.Get("query").(string),
EndpointType: d.Get("endpoint_type").(string),
Priority: d.Get("priority").(string),
Enabled: d.Get("enabled").(bool),
}

o, err := c.Update(ctx, newCustomRule)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(o.ID))
return resourceCustomRuleRead(ctx, d, m)
}

// resourceCustomRuleDelete is used to delete a custom rule by its ID
func resourceCustomRuleDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
config := m.(*ProviderConfig)
_ = config.ClientCustomRule
c := config.ClientCustomRule

var diags diag.Diagnostics

// id, err := strconv.Atoi(d.Id())
// if err != nil {
// return diag.FromErr(err)
// }
id, err := strconv.Atoi(d.Id())
if err != nil {
return diag.FromErr(err)
}

// err = c.Delete(ctx, id)
// if err != nil {
// return diag.FromErr(err)
// }
err = c.Delete(ctx, id)
if err != nil {
return diag.FromErr(err)
}

return diags
}
Loading

0 comments on commit 49628ea

Please sign in to comment.