Skip to content

Commit c03d1b3

Browse files
committed
feat(Sdk): Added the arguments property to the ScriptProcessDefinition
1 parent ee82811 commit c03d1b3

File tree

7 files changed

+91
-9
lines changed

7 files changed

+91
-9
lines changed

src/ServerlessWorkflow.Sdk.Builders/Interfaces/IScriptProcessDefinitionBuilder.cs

+30
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,34 @@ public interface IScriptProcessDefinitionBuilder
5050
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
5151
IScriptProcessDefinitionBuilder WithSource(Action<IExternalResourceDefinitionBuilder> setup);
5252

53+
/// <summary>
54+
/// Adds a new argument to execute the script with
55+
/// </summary>
56+
/// <param name="name">The name of the argument to use</param>
57+
/// <param name="value">The value of the argument to use</param>
58+
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
59+
IScriptProcessDefinitionBuilder WithArgument(string name, object value);
60+
61+
/// <summary>
62+
/// Sets the arguments of the script to execute
63+
/// </summary>
64+
/// <param name="arguments">A name/value mapping of the arguments to use</param>
65+
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
66+
IScriptProcessDefinitionBuilder WithArguments(IDictionary<string, object> arguments);
67+
68+
/// <summary>
69+
/// Adds the specified environment variable to the process
70+
/// </summary>
71+
/// <param name="name">The environment variable's name</param>
72+
/// <param name="value">The environment variable's value</param>
73+
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
74+
IScriptProcessDefinitionBuilder WithEnvironment(string name, string value);
75+
76+
/// <summary>
77+
/// Sets the process's environment variables
78+
/// </summary>
79+
/// <param name="environment">A name/value mapping of the environment variables to use</param>
80+
/// <returns>The configured <see cref="IScriptProcessDefinitionBuilder"/></returns>
81+
IScriptProcessDefinitionBuilder WithEnvironment(IDictionary<string, string> environment);
82+
5383
}

src/ServerlessWorkflow.Sdk.Builders/Interfaces/IShellProcessDefinitionBuilder.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,29 @@ public interface IShellProcessDefinitionBuilder
3333
/// Adds a new argument to execute the shell command with
3434
/// </summary>
3535
/// <param name="argument">The argument to use</param>
36-
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
36+
/// <returns>The configured <see cref="IShellProcessDefinitionBuilder"/></returns>
3737
IShellProcessDefinitionBuilder WithArgument(string argument);
3838

3939
/// <summary>
4040
/// Sets the arguments of the shell command to execute
4141
/// </summary>
4242
/// <param name="arguments">A list of the arguments to use</param>
43-
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
43+
/// <returns>The configured <see cref="IShellProcessDefinitionBuilder"/></returns>
4444
IShellProcessDefinitionBuilder WithArguments(IEnumerable<string> arguments);
4545

4646
/// <summary>
4747
/// Adds the specified environment variable to the process
4848
/// </summary>
4949
/// <param name="name">The environment variable's name</param>
5050
/// <param name="value">The environment variable's value</param>
51-
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
51+
/// <returns>The configured <see cref="IShellProcessDefinitionBuilder"/></returns>
5252
IShellProcessDefinitionBuilder WithEnvironment(string name, string value);
5353

5454
/// <summary>
5555
/// Sets the process's environment variables
5656
/// </summary>
5757
/// <param name="environment">A name/value mapping of the environment variables to use</param>
58-
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
58+
/// <returns>The configured <see cref="IShellProcessDefinitionBuilder"/></returns>
5959
IShellProcessDefinitionBuilder WithEnvironment(IDictionary<string, string> environment);
6060

6161
}

src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs

+47
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14+
using Neuroglia;
1415
using ServerlessWorkflow.Sdk.Models.Processes;
1516

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

46+
/// <summary>
47+
/// Gets the arguments, if any, of the command to execute
48+
/// </summary>
49+
protected virtual EquatableDictionary<string, object>? Arguments { get; set; }
50+
51+
/// <summary>
52+
/// Gets/sets the environment variables, if any, of the shell command to execute
53+
/// </summary>
54+
protected virtual EquatableDictionary<string, string>? Environment { get; set; }
55+
4556
/// <inheritdoc/>
4657
public virtual IScriptProcessDefinitionBuilder WithLanguage(string language)
4758
{
@@ -76,6 +87,40 @@ public virtual IScriptProcessDefinitionBuilder WithSource(Action<IExternalResour
7687
return this;
7788
}
7889

90+
/// <inheritdoc/>
91+
public virtual IScriptProcessDefinitionBuilder WithArgument(string name, object value)
92+
{
93+
ArgumentException.ThrowIfNullOrWhiteSpace(name);
94+
this.Arguments ??= [];
95+
this.Arguments[name] = value;
96+
return this;
97+
}
98+
99+
/// <inheritdoc/>
100+
public virtual IScriptProcessDefinitionBuilder WithArguments(IDictionary<string, object> arguments)
101+
{
102+
ArgumentNullException.ThrowIfNull(arguments);
103+
this.Arguments = new(arguments);
104+
return this;
105+
}
106+
107+
/// <inheritdoc/>
108+
public virtual IScriptProcessDefinitionBuilder WithEnvironment(string name, string value)
109+
{
110+
ArgumentException.ThrowIfNullOrWhiteSpace(name);
111+
this.Environment ??= [];
112+
this.Environment[name] = value;
113+
return this;
114+
}
115+
116+
/// <inheritdoc/>
117+
public virtual IScriptProcessDefinitionBuilder WithEnvironment(IDictionary<string, string> environment)
118+
{
119+
ArgumentNullException.ThrowIfNull(environment);
120+
this.Environment = new(environment);
121+
return this;
122+
}
123+
79124
/// <inheritdoc/>
80125
public override ScriptProcessDefinition Build()
81126
{
@@ -85,6 +130,8 @@ public override ScriptProcessDefinition Build()
85130
{
86131
Language = this.Language,
87132
Code = this.Code,
133+
Arguments = this.Arguments,
134+
Environment = this.Environment
88135
};
89136
if(this.Source != null) process.Source = this.Source;
90137
else if(this.SourceUri != null) process.Source = new() { Uri = this.SourceUri };

src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<VersionPrefix>1.0.0</VersionPrefix>
8-
<VersionSuffix>alpha2.6</VersionSuffix>
8+
<VersionSuffix>alpha2.7</VersionSuffix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<VersionPrefix>1.0.0</VersionPrefix>
8-
<VersionSuffix>alpha2.6</VersionSuffix>
8+
<VersionSuffix>alpha2.7</VersionSuffix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/ServerlessWorkflow.Sdk/Models/Processes/ScriptProcessDefinition.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ public record ScriptProcessDefinition
3939
[DataMember(Name = "source", Order = 3), JsonPropertyName("source"), JsonPropertyOrder(3), YamlMember(Alias = "source", Order = 3)]
4040
public virtual ExternalResourceDefinition? Source { get; set; }
4141

42+
/// <summary>
43+
/// Gets/sets a key/value mapping of the arguments, if any, to pass to the script to run
44+
/// </summary>
45+
[DataMember(Name = "arguments", Order = 4), JsonPropertyName("arguments"), JsonPropertyOrder(4), YamlMember(Alias = "arguments", Order = 4)]
46+
public virtual EquatableDictionary<string, object>? Arguments { get; set; }
47+
4248
/// <summary>
4349
/// Gets/sets a key/value mapping of the environment variables, if any, to use when running the configured process
4450
/// </summary>
45-
[DataMember(Name = "environment", Order = 4), JsonPropertyName("environment"), JsonPropertyOrder(4), YamlMember(Alias = "environment", Order = 4)]
51+
[DataMember(Name = "environment", Order = 5), JsonPropertyName("environment"), JsonPropertyOrder(5), YamlMember(Alias = "environment", Order = 5)]
4652
public virtual EquatableDictionary<string, string>? Environment { get; set; }
4753

48-
4954
}

src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<VersionPrefix>1.0.0</VersionPrefix>
8-
<VersionSuffix>alpha2.6</VersionSuffix>
8+
<VersionSuffix>alpha2.7</VersionSuffix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

0 commit comments

Comments
 (0)