Skip to content

Commit

Permalink
Refactoring Triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmclaws committed Apr 30, 2024
1 parent 9f385dd commit c64534b
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 75 deletions.
37 changes: 34 additions & 3 deletions src/Auth0.ManagementApi/Models/Actions/ActionSecret.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,57 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Auth0.ManagementApi.Models.Actions
{

/// <summary>
///
/// </summary>
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class ActionSecret
{

#region Public Properties

/// <summary>
/// The name of the particular secret, e.g. API_KEY.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// The time when the secret was last updated.
/// </summary>
[JsonProperty("updated_at")]
public DateTime UpdatedAt { get; private set; }

/// <summary>
/// The value of the particular secret, e.g. secret123. A secret's value can only be set upon creation. A secret's value will never be returned by the API.
/// </summary>
[JsonProperty("value")]
public string Value { get; set; }

#endregion

#region Constructors

/// <summary>
///
/// </summary>
public ActionSecret()
{
}

/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
public ActionSecret(string name, string value)
{
Name = name;
Value = value;
}

#endregion

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models.Actions
{

/// <summary>
///
/// </summary>
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class UpdateTriggerBindingEntry
{

/// <summary>
/// The name of the binding.
/// </summary>
public string DisplayName { get; set; }

/// <summary>
/// A reference to an action. An action can be referred to by <see cref="TriggerReferenceType.ActionId" />,
/// <see cref="TriggerReferenceType.ActionName" />, or <see cref="TriggerReferenceType.BindingId" />.
/// </summary>
[JsonProperty("ref")]
public TriggerBindingReference Reference { get; set; }

/// <summary>
///
/// </summary>
public IList<ActionSecret> Secrets { get; set; }

#region Constructors

/// <summary>
///
/// </summary>
public UpdateTriggerBindingEntry()
{
Reference = new TriggerBindingReference()
{
Type = TriggerReferenceType.ActionId
};
Secrets = [];
}

/// <summary>
///
/// </summary>
/// <param name="displayName"></param>
/// <param name="referenceType"></param>
/// <param name="referenceValue"></param>
public UpdateTriggerBindingEntry(string displayName, TriggerReferenceType referenceType, string referenceValue) : this()
{
DisplayName = displayName;
Reference.Type = referenceType;
Reference.Value = referenceValue;
}

#endregion

}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;

namespace Auth0.ManagementApi.Models.Actions
{

/// <summary>
/// Request configuration to update the actions that are bound (i.e. attached) to a trigger.
/// </summary>
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]

public class UpdateTriggerBindingsRequest
{

#region Public Properties

/// <summary>
/// The actions that will be bound to this trigger. The order in which they are included will be the order in which they are executed.
/// </summary>
[JsonProperty("bindings")]
public IList<UpdateTriggerBindingEntry> Bindings { get; set; }

#endregion

#region Constructors

/// <summary>
///
/// </summary>
public UpdateTriggerBindingsRequest()
{
Bindings = [];
}

#endregion

}

}
4 changes: 2 additions & 2 deletions src/Auth0.ManagementApi/Models/Actions/Triggers/Trigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Trigger : TriggerBase
/// <summary>
/// Runtimes supported by this trigger.
/// </summary>
public List<ActionRuntimeType> Runtimes { get; set; }
public System.Collections.Generic.List<ActionRuntimeType> Runtimes { get; set; }

/// <summary>
/// Runtime that will be used when none is specified when creating an action.
Expand All @@ -24,7 +24,7 @@ public class Trigger : TriggerBase
/// <summary>
///
/// </summary>
public List<TriggerBase> CompatibleTriggers { get; set; }
public System.Collections.Generic.List<TriggerBase> CompatibleTriggers { get; set; }
}

}
38 changes: 38 additions & 0 deletions src/Auth0.ManagementApi/Models/Actions/Triggers/TriggerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Auth0.ManagementApi.Models.Actions
public class TriggerBase
{

#region Properties

/// <summary>
/// The actions extensibility point
/// </summary>
Expand All @@ -19,13 +21,49 @@ public class TriggerBase
/// <summary>
/// The version of a trigger. v1, v2, etc.
/// </summary>
/// <remarks>When submitting data, leave this blank to use the most current version.</remarks>
public string Version { get; set; }

/// <summary>
/// The trigger's status.
/// </summary>
public TriggerStatusType Status { get; set; }

#endregion

#region Constructors

/// <summary>
///
/// </summary>
public TriggerBase()
{
}

/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="status"></param>
public TriggerBase(TriggerType id, TriggerStatusType status = TriggerStatusType.Current) : this()
{
Id = id;
Status = status;
}

/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="version"></param>
/// <param name="status"></param>
public TriggerBase(TriggerType id, string version, TriggerStatusType status = TriggerStatusType.Current) : this(id, status)
{
Version = version;
}

#endregion

}

}
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Auth0.ManagementApi.Models.Actions
{

/// <summary>
/// Represents a Trigger Binding in Auth0
/// </summary>
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class TriggerBinding
{

/// <summary>
/// The unique ID of this binding.
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }
public Guid Id { get; set; }

/// <summary>
/// The actions extensibility point.
/// </summary>
[JsonProperty("trigger_id")]
public string TriggerId { get; set; }
public TriggerType TriggerId { get; set; }

/// <summary>
/// The connected action.
/// </summary>
[JsonProperty("action")]
public CodeAction Action { get; set; }

/// <summary>
/// The time when the binding was created.
/// </summary>
[JsonProperty("created_at")]
public DateTime CreatedAt { get; set; }

/// <summary>
/// The time when the binding was updated.
/// </summary>
[JsonProperty("updated_at")]
public DateTime UpdatedAt { get; set; }

/// <summary>
/// The name of the binding.
/// </summary>
[JsonProperty("display_name")]
public string DisplayName { get; set; }

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Auth0.ManagementApi.Models.Actions
{

/// <summary>
///
/// </summary>
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class TriggerBindingReference
{

/// <summary>
/// How the action is being referred to.
/// </summary>
public TriggerReferenceType Type { get; set; }

/// <summary>
/// The value to ude to look up the binding, based on the <see cref="Type" />.
/// </summary>
public string Value { get; set; }

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;

namespace Auth0.ManagementApi.Models.Actions
{

/// <summary>
///
/// </summary>
[JsonConverter(typeof(StringEnumConverter), typeof(SnakeCaseNamingStrategy))]
public enum TriggerReferenceType
{

/// <summary>
///
/// </summary>
ActionId,

/// <summary>
///
/// </summary>
ActionName,

/// <summary>
///
/// </summary>
BindingId

}

}
Loading

0 comments on commit c64534b

Please sign in to comment.