Skip to content

Commit

Permalink
Rename input params data and meta consistently (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught authored Aug 1, 2023
1 parent 7f376ed commit 8645834
Show file tree
Hide file tree
Showing 44 changed files with 766 additions and 766 deletions.
10 changes: 5 additions & 5 deletions internal/auth0/action/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ func expandTriggerBindings(config cty.Value) []*management.ActionBinding {
return triggerBindings
}

func preventErasingUnmanagedSecrets(ctx context.Context, d *schema.ResourceData, api *management.Management) diag.Diagnostics {
if !d.HasChange("secrets") {
func preventErasingUnmanagedSecrets(ctx context.Context, data *schema.ResourceData, api *management.Management) diag.Diagnostics {
if !data.HasChange("secrets") {
return nil
}

preUpdateAction, err := api.Action.Read(ctx, d.Id())
preUpdateAction, err := api.Action.Read(ctx, data.Id())
if err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
return diag.FromErr(internalError.HandleAPIError(data, err))
}

// We need to also include the secrets that we're about to remove
// against the checks, not just the ones with which we are left.
oldSecrets, newSecrets := d.GetChange("secrets")
oldSecrets, newSecrets := data.GetChange("secrets")
allSecrets := append(oldSecrets.([]interface{}), newSecrets.([]interface{})...)

return checkForUnmanagedActionSecrets(allSecrets, preUpdateAction.GetSecrets())
Expand Down
62 changes: 31 additions & 31 deletions internal/auth0/action/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,76 +130,76 @@ func NewResource() *schema.Resource {
}
}

func createAction(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func createAction(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

action := expandAction(d.GetRawConfig())
action := expandAction(data.GetRawConfig())

if err := api.Action.Create(ctx, action); err != nil {
return diag.FromErr(err)
}

d.SetId(action.GetID())
data.SetId(action.GetID())

if err := deployAction(ctx, d, m); err != nil {
if err := deployAction(ctx, data, meta); err != nil {
return diag.FromErr(err)
}

return readAction(ctx, d, m)
return readAction(ctx, data, meta)
}

func readAction(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func readAction(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

action, err := api.Action.Read(ctx, d.Id())
action, err := api.Action.Read(ctx, data.Id())
if err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
return diag.FromErr(internalError.HandleAPIError(data, err))
}

return diag.FromErr(flattenAction(d, action))
return diag.FromErr(flattenAction(data, action))
}

func updateAction(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func updateAction(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

diagnostics := preventErasingUnmanagedSecrets(ctx, d, api)
diagnostics := preventErasingUnmanagedSecrets(ctx, data, api)
if diagnostics.HasError() {
return diagnostics
}

action := expandAction(d.GetRawConfig())
action := expandAction(data.GetRawConfig())

if err := api.Action.Update(ctx, d.Id(), action); err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
if err := api.Action.Update(ctx, data.Id(), action); err != nil {
return diag.FromErr(internalError.HandleAPIError(data, err))
}

if err := deployAction(ctx, d, m); err != nil {
if err := deployAction(ctx, data, meta); err != nil {
return diag.FromErr(err)
}

return readAction(ctx, d, m)
return readAction(ctx, data, meta)
}

func deleteAction(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func deleteAction(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

if err := api.Action.Delete(ctx, d.Id()); err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
if err := api.Action.Delete(ctx, data.Id()); err != nil {
return diag.FromErr(internalError.HandleAPIError(data, err))
}

return nil
}

func deployAction(ctx context.Context, d *schema.ResourceData, m interface{}) error {
deployExists := d.Get("deploy").(bool)
func deployAction(ctx context.Context, data *schema.ResourceData, meta interface{}) error {
deployExists := data.Get("deploy").(bool)
if !deployExists {
return nil
}

api := m.(*config.Config).GetAPI()
api := meta.(*config.Config).GetAPI()

err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError {
action, err := api.Action.Read(ctx, d.Id())
err := retry.RetryContext(ctx, data.Timeout(schema.TimeoutCreate), func() *retry.RetryError {
action, err := api.Action.Read(ctx, data.Id())
if err != nil {
return retry.NonRetryableError(err)
}
Expand All @@ -219,13 +219,13 @@ func deployAction(ctx context.Context, d *schema.ResourceData, m interface{}) er
return nil
})
if err != nil {
return fmt.Errorf("action %q never reached built state: %w", d.Get("name").(string), err)
return fmt.Errorf("action %q never reached built state: %w", data.Get("name").(string), err)
}

actionVersion, err := api.Action.Deploy(ctx, d.Id())
actionVersion, err := api.Action.Deploy(ctx, data.Id())
if err != nil {
return err
}

return d.Set("version_id", actionVersion.GetID())
return data.Set("version_id", actionVersion.GetID())
}
62 changes: 31 additions & 31 deletions internal/auth0/action/resource_trigger_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func NewTriggerActionResource() *schema.Resource {
}
}

func createTriggerAction(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func createTriggerAction(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

trigger := d.Get("trigger").(string)
actionID := d.Get("action_id").(string)
displayName := d.Get("display_name").(string)
trigger := data.Get("trigger").(string)
actionID := data.Get("action_id").(string)
displayName := data.Get("display_name").(string)

currentBindings, err := api.Action.Bindings(ctx, trigger)
if err != nil {
Expand All @@ -76,8 +76,8 @@ func createTriggerAction(ctx context.Context, d *schema.ResourceData, m interfac
var updatedBindings []*management.ActionBinding
for _, binding := range currentBindings.Bindings {
if binding.Action.GetID() == actionID {
internalSchema.SetResourceGroupID(d, trigger, actionID)
return readTriggerAction(ctx, d, m)
internalSchema.SetResourceGroupID(data, trigger, actionID)
return readTriggerAction(ctx, data, meta)
}

updatedBindings = append(updatedBindings, &management.ActionBinding{
Expand Down Expand Up @@ -110,21 +110,21 @@ func createTriggerAction(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err)
}

internalSchema.SetResourceGroupID(d, trigger, actionID)
internalSchema.SetResourceGroupID(data, trigger, actionID)

return readTriggerAction(ctx, d, m)
return readTriggerAction(ctx, data, meta)
}

func updateTriggerAction(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func updateTriggerAction(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

trigger := d.Get("trigger").(string)
actionID := d.Get("action_id").(string)
displayName := d.Get("display_name").(string)
trigger := data.Get("trigger").(string)
actionID := data.Get("action_id").(string)
displayName := data.Get("display_name").(string)

currentBindings, err := api.Action.Bindings(ctx, trigger)
if err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
return diag.FromErr(internalError.HandleAPIError(data, err))
}

found := false
Expand All @@ -151,47 +151,47 @@ func updateTriggerAction(ctx context.Context, d *schema.ResourceData, m interfac
}

if !found {
d.SetId("")
data.SetId("")
return nil
}

if err := api.Action.UpdateBindings(ctx, trigger, updatedBindings); err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
return diag.FromErr(internalError.HandleAPIError(data, err))
}

return readTriggerAction(ctx, d, m)
return readTriggerAction(ctx, data, meta)
}

func readTriggerAction(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func readTriggerAction(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

trigger := d.Get("trigger").(string)
actionID := d.Get("action_id").(string)
trigger := data.Get("trigger").(string)
actionID := data.Get("action_id").(string)

triggerBindings, err := api.Action.Bindings(ctx, trigger)
if err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
return diag.FromErr(internalError.HandleAPIError(data, err))
}

for _, binding := range triggerBindings.Bindings {
if binding.Action.GetID() == actionID {
return diag.FromErr(d.Set("display_name", binding.GetDisplayName()))
return diag.FromErr(data.Set("display_name", binding.GetDisplayName()))
}
}

d.SetId("")
data.SetId("")
return nil
}

func deleteTriggerAction(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func deleteTriggerAction(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

trigger := d.Get("trigger").(string)
actionID := d.Get("action_id").(string)
trigger := data.Get("trigger").(string)
actionID := data.Get("action_id").(string)

triggerBindings, err := api.Action.Bindings(ctx, trigger)
if err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
return diag.FromErr(internalError.HandleAPIError(data, err))
}

updatedBindings := make([]*management.ActionBinding, 0)
Expand All @@ -210,7 +210,7 @@ func deleteTriggerAction(ctx context.Context, d *schema.ResourceData, m interfac
}

if err = api.Action.UpdateBindings(ctx, trigger, updatedBindings); err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
return diag.FromErr(internalError.HandleAPIError(data, err))
}

return nil
Expand Down
42 changes: 21 additions & 21 deletions internal/auth0/action/resource_trigger_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,49 +72,49 @@ func NewTriggerActionsResource() *schema.Resource {
}
}

func createTriggerBinding(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func createTriggerBinding(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

id := d.Get("trigger").(string)
triggerBindings := expandTriggerBindings(d.GetRawConfig().GetAttr("actions"))
id := data.Get("trigger").(string)
triggerBindings := expandTriggerBindings(data.GetRawConfig().GetAttr("actions"))

if err := api.Action.UpdateBindings(ctx, id, triggerBindings); err != nil {
return diag.FromErr(err)
}

d.SetId(id)
data.SetId(id)

return readTriggerBinding(ctx, d, m)
return readTriggerBinding(ctx, data, meta)
}

func readTriggerBinding(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func readTriggerBinding(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

triggerBindings, err := api.Action.Bindings(ctx, d.Id())
triggerBindings, err := api.Action.Bindings(ctx, data.Id())
if err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
return diag.FromErr(internalError.HandleAPIError(data, err))
}

return diag.FromErr(flattenTriggerBinding(d, triggerBindings.Bindings))
return diag.FromErr(flattenTriggerBinding(data, triggerBindings.Bindings))
}

func updateTriggerBinding(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func updateTriggerBinding(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

triggerBindings := expandTriggerBindings(d.GetRawConfig().GetAttr("actions"))
triggerBindings := expandTriggerBindings(data.GetRawConfig().GetAttr("actions"))

if err := api.Action.UpdateBindings(ctx, d.Id(), triggerBindings); err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
if err := api.Action.UpdateBindings(ctx, data.Id(), triggerBindings); err != nil {
return diag.FromErr(internalError.HandleAPIError(data, err))
}

return readTriggerBinding(ctx, d, m)
return readTriggerBinding(ctx, data, meta)
}

func deleteTriggerBinding(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
api := m.(*config.Config).GetAPI()
func deleteTriggerBinding(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

if err := api.Action.UpdateBindings(ctx, d.Id(), []*management.ActionBinding{}); err != nil {
return diag.FromErr(internalError.HandleAPIError(d, err))
if err := api.Action.UpdateBindings(ctx, data.Id(), []*management.ActionBinding{}); err != nil {
return diag.FromErr(internalError.HandleAPIError(data, err))
}

return nil
Expand Down
12 changes: 6 additions & 6 deletions internal/auth0/attackprotection/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ func expandSuspiciousIPThrottling(data *schema.ResourceData) *management.Suspici
return ipt
}

func expandBruteForceProtection(d *schema.ResourceData) *management.BruteForceProtection {
if !d.HasChange("brute_force_protection") {
func expandBruteForceProtection(data *schema.ResourceData) *management.BruteForceProtection {
if !data.HasChange("brute_force_protection") {
return nil
}

var bfp *management.BruteForceProtection

d.GetRawConfig().GetAttr("brute_force_protection").ForEachElement(func(_ cty.Value, cfg cty.Value) (stop bool) {
data.GetRawConfig().GetAttr("brute_force_protection").ForEachElement(func(_ cty.Value, cfg cty.Value) (stop bool) {
bfp = &management.BruteForceProtection{
Enabled: value.Bool(cfg.GetAttr("enabled")),
Mode: value.String(cfg.GetAttr("mode")),
Expand All @@ -81,14 +81,14 @@ func expandBruteForceProtection(d *schema.ResourceData) *management.BruteForcePr
return bfp
}

func expandBreachedPasswordDetection(d *schema.ResourceData) *management.BreachedPasswordDetection {
if !d.HasChange("breached_password_detection") {
func expandBreachedPasswordDetection(data *schema.ResourceData) *management.BreachedPasswordDetection {
if !data.HasChange("breached_password_detection") {
return nil
}

var bpd *management.BreachedPasswordDetection

d.GetRawConfig().GetAttr("breached_password_detection").ForEachElement(
data.GetRawConfig().GetAttr("breached_password_detection").ForEachElement(
func(_ cty.Value, breach cty.Value) (stop bool) {
bpd = &management.BreachedPasswordDetection{
Enabled: value.Bool(breach.GetAttr("enabled")),
Expand Down
Loading

0 comments on commit 8645834

Please sign in to comment.