@@ -35,8 +35,8 @@ public class FunctionCallExecutor(IServiceProvider serviceProvider, ILogger<Func
35
35
{
36
36
37
37
const string CustomFunctionDefinitionFile = "function.yaml" ;
38
- const string GithubHost = "github.com" ;
39
- const string GitlabHost = "gitlab" ;
38
+ const string GitHubHost = "github.com" ;
39
+ const string GitLabHost = "gitlab" ;
40
40
41
41
/// <summary>
42
42
/// Gets the service used to serialize/deserialize objects to/from YAML
@@ -65,6 +65,15 @@ public override async Task InitializeAsync(CancellationToken cancellationToken =
65
65
if ( components . Length != 2 ) throw new NotSupportedException ( $ "Unknown/unsupported function '{ this . Task . Definition . Call } '") ;
66
66
this . Function = await this . GetCustomFunctionAsync ( components [ 0 ] , components [ 1 ] , cancellationToken ) . ConfigureAwait ( false ) ;
67
67
}
68
+ else if ( this . Task . Definition . Call . Contains ( ':' ) )
69
+ {
70
+ var components = this . Task . Definition . Call . Split ( ':' , StringSplitOptions . RemoveEmptyEntries ) ;
71
+ if ( components . Length != 2 ) throw new Exception ( $ "The specified value '{ this . Task . Definition . Call } ' is not a valid custom function qualified name ({{name}}:{{version}})") ;
72
+ var functionName = components [ 0 ] ;
73
+ var functionVersion = components [ 1 ] ;
74
+ uri = new Uri ( $ "https://github.com/serverlessworkflow/catalog/tree/main/functions/{ functionName } /{ functionVersion } /{ CustomFunctionDefinitionFile } ") ;
75
+ this . Function = await this . GetCustomFunctionAsync ( new ( ) { Uri = uri } , cancellationToken ) . ConfigureAwait ( false ) ;
76
+ }
68
77
else throw new NotSupportedException ( $ "Unknown/unsupported function '{ this . Task . Definition . Call } '") ;
69
78
}
70
79
@@ -79,8 +88,8 @@ protected virtual async Task<TaskDefinition> GetCustomFunctionAsync(EndpointDefi
79
88
ArgumentNullException . ThrowIfNull ( endpoint ) ;
80
89
var uri = endpoint . Uri ;
81
90
if ( ! uri . OriginalString . EndsWith ( CustomFunctionDefinitionFile ) ) uri = new Uri ( uri , CustomFunctionDefinitionFile ) ;
82
- if ( uri . Host . Equals ( GithubHost , StringComparison . OrdinalIgnoreCase ) ) uri = this . TransformGithubUriToRawUri ( uri ) ;
83
- else if ( uri . Host . Contains ( GitlabHost ) ) uri = this . TransformGitlabUriToRawUri ( uri ) ;
91
+ if ( uri . Host . Equals ( GitHubHost , StringComparison . OrdinalIgnoreCase ) ) uri = this . TransformGithubUriToRawUri ( uri ) ;
92
+ else if ( uri . Host . Contains ( GitLabHost ) ) uri = this . TransformGitlabUriToRawUri ( uri ) ;
84
93
var authentication = endpoint . Authentication == null ? null : await this . Task . Workflow . Expressions . EvaluateAsync < AuthenticationPolicyDefinition > ( endpoint . Authentication , this . Task . Input , this . Task . Arguments , cancellationToken ) . ConfigureAwait ( false ) ;
85
94
using var httpClient = this . ServiceProvider . GetRequiredService < IHttpClientFactory > ( ) . CreateClient ( ) ;
86
95
await httpClient . ConfigureAuthenticationAsync ( authentication , this . ServiceProvider , this . Task . Workflow . Definition , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -138,8 +147,8 @@ protected virtual async Task<TaskDefinition> GetCustomFunctionAsync(string funct
138
147
protected virtual Uri TransformGithubUriToRawUri ( Uri uri )
139
148
{
140
149
ArgumentNullException . ThrowIfNull ( uri ) ;
141
- if ( uri . Host . Equals ( GithubHost , StringComparison . OrdinalIgnoreCase ) ) return uri ;
142
- var rawUri = uri . AbsoluteUri . Replace ( GithubHost , "raw.githubusercontent.com" , StringComparison . OrdinalIgnoreCase ) ;
150
+ if ( ! uri . Host . Equals ( GitHubHost , StringComparison . OrdinalIgnoreCase ) ) return uri ;
151
+ var rawUri = uri . AbsoluteUri . Replace ( GitHubHost , "raw.githubusercontent.com" , StringComparison . OrdinalIgnoreCase ) ;
143
152
rawUri = rawUri . Replace ( "/tree/" , "/refs/heads/" , StringComparison . OrdinalIgnoreCase ) ;
144
153
return new ( rawUri , UriKind . Absolute ) ;
145
154
}
@@ -152,7 +161,7 @@ protected virtual Uri TransformGithubUriToRawUri(Uri uri)
152
161
protected virtual Uri TransformGitlabUriToRawUri ( Uri uri )
153
162
{
154
163
ArgumentNullException . ThrowIfNull ( uri ) ;
155
- if ( ! uri . AbsoluteUri . Contains ( GitlabHost , StringComparison . OrdinalIgnoreCase ) ) return uri ;
164
+ if ( ! uri . Host . Equals ( GitLabHost , StringComparison . OrdinalIgnoreCase ) ) return uri ;
156
165
var rawUri = uri . AbsoluteUri . Replace ( "/-/blob/" , "/-/raw/" , StringComparison . OrdinalIgnoreCase ) ;
157
166
return new ( rawUri , UriKind . Absolute ) ;
158
167
}
0 commit comments