@@ -22,8 +22,9 @@ public static class FunctionMetadataExtensions
22
22
/// <returns>Promise of a FunctionMetadataResponse</returns>
23
23
public static async Task < FunctionMetadataResponse > ToFunctionMetadataResponse ( this FunctionMetadata functionMetadata , ScriptJobHostOptions hostOptions , string routePrefix , string baseUrl )
24
24
{
25
- var functionPath = Path . Combine ( hostOptions . RootScriptPath , functionMetadata . Name ) ;
26
- var functionMetadataFilePath = Path . Combine ( functionPath , ScriptConstants . FunctionMetadataFileName ) ;
25
+ string functionPath = GetFunctionPathOrNull ( hostOptions . RootScriptPath , functionMetadata . Name ) ;
26
+ string functionMetadataFilePath = GetMetadataPathOrNull ( functionPath ) ;
27
+
27
28
if ( string . IsNullOrEmpty ( baseUrl ) )
28
29
{
29
30
baseUrl = "https://localhost/" ;
@@ -32,10 +33,8 @@ public static async Task<FunctionMetadataResponse> ToFunctionMetadataResponse(th
32
33
var response = new FunctionMetadataResponse
33
34
{
34
35
Name = functionMetadata . Name ,
35
- ConfigHref = VirtualFileSystem . FilePathToVfsUri ( functionMetadataFilePath , baseUrl , hostOptions ) ,
36
- ScriptRootPathHref = VirtualFileSystem . FilePathToVfsUri ( functionPath , baseUrl , hostOptions , isDirectory : true ) ,
37
36
Href = GetFunctionHref ( functionMetadata . Name , baseUrl ) ,
38
- Config = await GetFunctionConfig ( functionMetadataFilePath ) ,
37
+ Config = await GetFunctionConfig ( functionMetadata , functionMetadataFilePath ) ,
39
38
40
39
// Properties below this comment are not present in the kudu version.
41
40
IsDirect = functionMetadata . IsDirect ( ) ,
@@ -45,6 +44,16 @@ public static async Task<FunctionMetadataResponse> ToFunctionMetadataResponse(th
45
44
InvokeUrlTemplate = GetFunctionInvokeUrlTemplate ( baseUrl , functionMetadata , routePrefix )
46
45
} ;
47
46
47
+ if ( ! string . IsNullOrEmpty ( functionPath ) )
48
+ {
49
+ response . ScriptRootPathHref = VirtualFileSystem . FilePathToVfsUri ( functionPath , baseUrl , hostOptions , isDirectory : true ) ;
50
+ }
51
+
52
+ if ( ! string . IsNullOrEmpty ( functionMetadataFilePath ) )
53
+ {
54
+ response . ConfigHref = VirtualFileSystem . FilePathToVfsUri ( functionMetadataFilePath , baseUrl , hostOptions ) ;
55
+ }
56
+
48
57
if ( ! string . IsNullOrEmpty ( hostOptions . TestDataPath ) )
49
58
{
50
59
var testDataFilePath = functionMetadata . GetTestDataFilePath ( hostOptions ) ;
@@ -69,29 +78,12 @@ public static async Task<FunctionMetadataResponse> ToFunctionMetadataResponse(th
69
78
/// <param name="config">ScriptHostConfiguration to read RootScriptPath from.</param>
70
79
/// <returns>JObject that represent the trigger for scale controller to consume</returns>
71
80
public static async Task < JObject > ToFunctionTrigger ( this FunctionMetadata functionMetadata , ScriptJobHostOptions config )
72
- {
73
- // Codeless functions do not have a physical file and need to be converted differently.
74
- if ( functionMetadata . IsCodeless ( ) )
75
- {
76
- return await GetCodelessFunctionTrigger ( functionMetadata ) ;
77
- }
78
-
79
- return await GetRegularFunctionTrigger ( functionMetadata , config ) ;
80
- }
81
-
82
- public static string GetTestDataFilePath ( this FunctionMetadata functionMetadata , ScriptJobHostOptions hostOptions ) =>
83
- GetTestDataFilePath ( functionMetadata . Name , hostOptions ) ;
84
-
85
- public static string GetTestDataFilePath ( string functionName , ScriptJobHostOptions hostOptions ) =>
86
- Path . Combine ( hostOptions . TestDataPath , $ "{ functionName } .dat") ;
87
-
88
- private static async Task < JObject > GetRegularFunctionTrigger ( FunctionMetadata functionMetadata , ScriptJobHostOptions config )
89
81
{
90
82
var functionPath = Path . Combine ( config . RootScriptPath , functionMetadata . Name ) ;
91
83
var functionMetadataFilePath = Path . Combine ( functionPath , ScriptConstants . FunctionMetadataFileName ) ;
92
84
93
85
// Read function.json as a JObject
94
- var functionConfig = await GetFunctionConfig ( functionMetadataFilePath ) ;
86
+ var functionConfig = await GetFunctionConfig ( functionMetadata , functionMetadataFilePath ) ;
95
87
96
88
if ( functionConfig . TryGetValue ( "bindings" , out JToken value ) &&
97
89
value is JArray )
@@ -112,35 +104,50 @@ private static async Task<JObject> GetRegularFunctionTrigger(FunctionMetadata fu
112
104
return null ;
113
105
}
114
106
115
- private static Task < JObject > GetCodelessFunctionTrigger ( FunctionMetadata functionMetadata )
107
+ public static string GetTestDataFilePath ( this FunctionMetadata functionMetadata , ScriptJobHostOptions hostOptions ) =>
108
+ GetTestDataFilePath ( functionMetadata . Name , hostOptions ) ;
109
+
110
+ public static string GetTestDataFilePath ( string functionName , ScriptJobHostOptions hostOptions ) =>
111
+ Path . Combine ( hostOptions . TestDataPath , $ "{ functionName } .dat") ;
112
+
113
+ private static string GetFunctionPathOrNull ( string scriptRoot , string functionName )
116
114
{
117
- if ( functionMetadata . Bindings == null )
115
+ var functionPath = Path . Combine ( scriptRoot , functionName ) ;
116
+
117
+ if ( FileUtility . DirectoryExists ( functionPath ) )
118
118
{
119
- return null ;
119
+ return functionPath ;
120
120
}
121
121
122
- foreach ( BindingMetadata binding in functionMetadata . Bindings )
122
+ return null ;
123
+ }
124
+
125
+ private static string GetMetadataPathOrNull ( string functionPath )
126
+ {
127
+ if ( ! string . IsNullOrEmpty ( functionPath ) )
123
128
{
124
- JObject rawBinding = binding . Raw ;
125
- var type = ( string ) rawBinding [ "type" ] ;
126
- if ( type != null && type . EndsWith ( "Trigger" , StringComparison . OrdinalIgnoreCase ) )
129
+ var metadataPath = Path . Combine ( functionPath , ScriptConstants . FunctionMetadataFileName ) ;
130
+
131
+ if ( FileUtility . FileExists ( metadataPath ) )
127
132
{
128
- JObject newBinding = ( JObject ) rawBinding . DeepClone ( ) ;
129
- newBinding . Add ( "functionName" , functionMetadata . Name ) ;
130
- return Task . FromResult ( newBinding ) ;
133
+ return metadataPath ;
131
134
}
132
135
}
133
136
134
137
return null ;
135
138
}
136
139
137
- private static async Task < JObject > GetFunctionConfig ( string path )
140
+ private static async Task < JObject > GetFunctionConfig ( FunctionMetadata metadata , string path )
138
141
{
139
142
try
140
143
{
141
- if ( FileUtility . FileExists ( path ) )
144
+ if ( ! string . IsNullOrEmpty ( path ) && FileUtility . FileExists ( path ) )
145
+ {
146
+ return await GetFunctionConfigFromFile ( path ) ;
147
+ }
148
+ else
142
149
{
143
- return JObject . Parse ( await FileUtility . ReadAsync ( path ) ) ;
150
+ return GetFunctionConfigFromMetadata ( metadata ) ;
144
151
}
145
152
}
146
153
catch
@@ -154,6 +161,26 @@ private static async Task<JObject> GetFunctionConfig(string path)
154
161
return new JObject ( ) ;
155
162
}
156
163
164
+ private static async Task < JObject > GetFunctionConfigFromFile ( string path )
165
+ {
166
+ return JObject . Parse ( await FileUtility . ReadAsync ( path ) ) ;
167
+ }
168
+
169
+ private static JObject GetFunctionConfigFromMetadata ( FunctionMetadata metadata )
170
+ {
171
+ var config = new
172
+ {
173
+ name = metadata . Name ,
174
+ entryPoint = metadata . EntryPoint ,
175
+ scriptFile = metadata . ScriptFile ,
176
+ language = metadata . Language ,
177
+ functionDirectory = metadata . FunctionDirectory ,
178
+ bindings = metadata . Bindings . Select ( m => m . Raw ) . ToList ( )
179
+ } ;
180
+
181
+ return JObject . FromObject ( config ) ;
182
+ }
183
+
157
184
private static async Task < string > GetTestData ( string testDataPath , ScriptJobHostOptions config )
158
185
{
159
186
if ( ! File . Exists ( testDataPath ) )
0 commit comments