Skip to content

Commit

Permalink
feat(Sdk): Added the arguments property to the ScriptProcessDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
cdavernas committed Aug 8, 2024
1 parent ee82811 commit c03d1b3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,34 @@ public interface IScriptProcessDefinitionBuilder
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
IScriptProcessDefinitionBuilder WithSource(Action<IExternalResourceDefinitionBuilder> setup);

/// <summary>
/// Adds a new argument to execute the script with
/// </summary>
/// <param name="name">The name of the argument to use</param>
/// <param name="value">The value of the argument to use</param>
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
IScriptProcessDefinitionBuilder WithArgument(string name, object value);

/// <summary>
/// Sets the arguments of the script to execute
/// </summary>
/// <param name="arguments">A name/value mapping of the arguments to use</param>
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
IScriptProcessDefinitionBuilder WithArguments(IDictionary<string, object> arguments);

/// <summary>
/// Adds the specified environment variable to the process
/// </summary>
/// <param name="name">The environment variable's name</param>
/// <param name="value">The environment variable's value</param>
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
IScriptProcessDefinitionBuilder WithEnvironment(string name, string value);

/// <summary>
/// Sets the process's environment variables
/// </summary>
/// <param name="environment">A name/value mapping of the environment variables to use</param>
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
IScriptProcessDefinitionBuilder WithEnvironment(IDictionary<string, string> environment);

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ public interface IShellProcessDefinitionBuilder
/// Adds a new argument to execute the shell command with
/// </summary>
/// <param name="argument">The argument to use</param>
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
/// <returns>The configured <see cref="IShellProcessDefinitionBuilder"/></returns>
IShellProcessDefinitionBuilder WithArgument(string argument);

/// <summary>
/// Sets the arguments of the shell command to execute
/// </summary>
/// <param name="arguments">A list of the arguments to use</param>
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
/// <returns>The configured <see cref="IShellProcessDefinitionBuilder"/></returns>
IShellProcessDefinitionBuilder WithArguments(IEnumerable<string> arguments);

/// <summary>
/// Adds the specified environment variable to the process
/// </summary>
/// <param name="name">The environment variable's name</param>
/// <param name="value">The environment variable's value</param>
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
/// <returns>The configured <see cref="IShellProcessDefinitionBuilder"/></returns>
IShellProcessDefinitionBuilder WithEnvironment(string name, string value);

/// <summary>
/// Sets the process's environment variables
/// </summary>
/// <param name="environment">A name/value mapping of the environment variables to use</param>
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
/// <returns>The configured <see cref="IShellProcessDefinitionBuilder"/></returns>
IShellProcessDefinitionBuilder WithEnvironment(IDictionary<string, string> environment);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Neuroglia;
using ServerlessWorkflow.Sdk.Models.Processes;

namespace ServerlessWorkflow.Sdk.Builders;
Expand Down Expand Up @@ -42,6 +43,16 @@ public class ScriptProcessDefinitionBuilder
/// </summary>
public Uri? SourceUri { get; set; }

/// <summary>
/// Gets the arguments, if any, of the command to execute
/// </summary>
protected virtual EquatableDictionary<string, object>? Arguments { get; set; }

/// <summary>
/// Gets/sets the environment variables, if any, of the shell command to execute
/// </summary>
protected virtual EquatableDictionary<string, string>? Environment { get; set; }

/// <inheritdoc/>
public virtual IScriptProcessDefinitionBuilder WithLanguage(string language)
{
Expand Down Expand Up @@ -76,6 +87,40 @@ public virtual IScriptProcessDefinitionBuilder WithSource(Action<IExternalResour
return this;
}

/// <inheritdoc/>
public virtual IScriptProcessDefinitionBuilder WithArgument(string name, object value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name);
this.Arguments ??= [];
this.Arguments[name] = value;
return this;
}

/// <inheritdoc/>
public virtual IScriptProcessDefinitionBuilder WithArguments(IDictionary<string, object> arguments)
{
ArgumentNullException.ThrowIfNull(arguments);
this.Arguments = new(arguments);
return this;
}

/// <inheritdoc/>
public virtual IScriptProcessDefinitionBuilder WithEnvironment(string name, string value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name);
this.Environment ??= [];
this.Environment[name] = value;
return this;
}

/// <inheritdoc/>
public virtual IScriptProcessDefinitionBuilder WithEnvironment(IDictionary<string, string> environment)
{
ArgumentNullException.ThrowIfNull(environment);
this.Environment = new(environment);
return this;
}

/// <inheritdoc/>
public override ScriptProcessDefinition Build()
{
Expand All @@ -85,6 +130,8 @@ public override ScriptProcessDefinition Build()
{
Language = this.Language,
Code = this.Code,
Arguments = this.Arguments,
Environment = this.Environment
};
if(this.Source != null) process.Source = this.Source;
else if(this.SourceUri != null) process.Source = new() { Uri = this.SourceUri };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha2.6</VersionSuffix>
<VersionSuffix>alpha2.7</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha2.6</VersionSuffix>
<VersionSuffix>alpha2.7</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ public record ScriptProcessDefinition
[DataMember(Name = "source", Order = 3), JsonPropertyName("source"), JsonPropertyOrder(3), YamlMember(Alias = "source", Order = 3)]
public virtual ExternalResourceDefinition? Source { get; set; }

/// <summary>
/// Gets/sets a key/value mapping of the arguments, if any, to pass to the script to run
/// </summary>
[DataMember(Name = "arguments", Order = 4), JsonPropertyName("arguments"), JsonPropertyOrder(4), YamlMember(Alias = "arguments", Order = 4)]
public virtual EquatableDictionary<string, object>? Arguments { get; set; }

/// <summary>
/// Gets/sets a key/value mapping of the environment variables, if any, to use when running the configured process
/// </summary>
[DataMember(Name = "environment", Order = 4), JsonPropertyName("environment"), JsonPropertyOrder(4), YamlMember(Alias = "environment", Order = 4)]
[DataMember(Name = "environment", Order = 5), JsonPropertyName("environment"), JsonPropertyOrder(5), YamlMember(Alias = "environment", Order = 5)]
public virtual EquatableDictionary<string, string>? Environment { get; set; }


}
2 changes: 1 addition & 1 deletion src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha2.6</VersionSuffix>
<VersionSuffix>alpha2.7</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down

0 comments on commit c03d1b3

Please sign in to comment.