Skip to content

Commit b03aa05

Browse files
Ticket #3 : Add API in order to import YML file
1 parent 737fd51 commit b03aa05

34 files changed

+824
-12
lines changed

FaasNet.sln

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FaasNet.Runtime.Transform",
2121
EndProject
2222
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FaasNet.Gateway.Core", "src\FaasNet.Gateway.Core\FaasNet.Gateway.Core.csproj", "{65DA8EDF-48A2-4AB5-B93A-6301718F1C1B}"
2323
EndProject
24-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FaasNet.Gateway.Startup", "src\FaasNet.Gateway.Startup\FaasNet.Gateway.Startup.csproj", "{24686604-17C3-4BBB-9B05-7668073546E2}"
24+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FaasNet.Gateway.Startup", "src\FaasNet.Gateway.Startup\FaasNet.Gateway.Startup.csproj", "{24686604-17C3-4BBB-9B05-7668073546E2}"
25+
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FaasNet.CLI", "src\FaasNet.CLI\FaasNet.CLI.csproj", "{EDDFD04B-B4F0-47A6-8FD3-628F3F542402}"
27+
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FaasNet.Common", "src\FaasNet.Common\FaasNet.Common.csproj", "{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}"
2529
EndProject
2630
Global
2731
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -57,6 +61,14 @@ Global
5761
{24686604-17C3-4BBB-9B05-7668073546E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
5862
{24686604-17C3-4BBB-9B05-7668073546E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
5963
{24686604-17C3-4BBB-9B05-7668073546E2}.Release|Any CPU.Build.0 = Release|Any CPU
64+
{EDDFD04B-B4F0-47A6-8FD3-628F3F542402}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
65+
{EDDFD04B-B4F0-47A6-8FD3-628F3F542402}.Debug|Any CPU.Build.0 = Debug|Any CPU
66+
{EDDFD04B-B4F0-47A6-8FD3-628F3F542402}.Release|Any CPU.ActiveCfg = Release|Any CPU
67+
{EDDFD04B-B4F0-47A6-8FD3-628F3F542402}.Release|Any CPU.Build.0 = Release|Any CPU
68+
{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69+
{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
70+
{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
71+
{8B02C02D-EF1A-4F48-A69D-DC8592D966B9}.Release|Any CPU.Build.0 = Release|Any CPU
6072
EndGlobalSection
6173
GlobalSection(SolutionProperties) = preSolution
6274
HideSolutionNode = FALSE
@@ -69,6 +81,8 @@ Global
6981
{E1FBEF1B-892D-4F3B-ADB2-A150152F4E51} = {E407AB8F-BDC8-4084-BE20-B4442CFE5EE9}
7082
{65DA8EDF-48A2-4AB5-B93A-6301718F1C1B} = {1064A767-7322-4A14-BFD4-97FDD40E76B4}
7183
{24686604-17C3-4BBB-9B05-7668073546E2} = {B0C38F6D-3F83-458A-A493-428AB3DD9F85}
84+
{EDDFD04B-B4F0-47A6-8FD3-628F3F542402} = {B0C38F6D-3F83-458A-A493-428AB3DD9F85}
85+
{8B02C02D-EF1A-4F48-A69D-DC8592D966B9} = {1064A767-7322-4A14-BFD4-97FDD40E76B4}
7286
EndGlobalSection
7387
GlobalSection(ExtensibilityGlobals) = postSolution
7488
SolutionGuid = {46764455-0D10-4266-9C37-35D7BD67517C}

faasnet.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
provider:
2+
name: faasnet
3+
gateway: http://localhost:30001
4+
apis:
5+
persons:
6+
path: persons
7+
operations:
8+
- name: getPersons
9+
functions:
10+
- name: getsql
11+
configuration: >-
12+
{
13+
14+
"ConnectionString": "Data Source=mssql-entry.faas.svc.cluster.local;Initial Catalog=OpenID;User ID=sa;Password=D54DE7hHpkG9",
15+
16+
"SqlQuery": "SELECT * FROM [dbo].[Acrs]"
17+
18+
}
19+
flows:
20+
- next: transform
21+
- name: transform
22+
configuration: '{ "mappings": [ { "input": "content[*].Name", "output": "name" } ] }'
23+
flows: []
24+
functions:
25+
- name: getsql
26+
image: localhost:5000/getsql
27+
- name: transform
28+
image: localhost:5000/transform
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using FaasNet.CLI.Helpers;
2+
using FaasNet.Common.Configuration;
3+
using Newtonsoft.Json.Linq;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Net.Http;
9+
using System.Text;
10+
using YamlDotNet.Serialization;
11+
using YamlDotNet.Serialization.NamingConventions;
12+
13+
namespace FaasNet.CLI.Commands
14+
{
15+
public class ApplyCommand : IMenuItemCommand
16+
{
17+
private List<IMenuItemCommand> _commands = new List<IMenuItemCommand>
18+
{
19+
new ApplyFileCommand()
20+
};
21+
22+
public string Command => "apply";
23+
public string Description => "Apply configuration";
24+
25+
public void Execute(IEnumerable<string> args)
26+
{
27+
if (!args.Any())
28+
{
29+
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "faasnet.yml");
30+
Apply(filePath);
31+
}
32+
33+
MenuHelper.Execute(args, _commands);
34+
}
35+
36+
internal static void Apply(string filePath)
37+
{
38+
if (!File.Exists(filePath))
39+
{
40+
Console.WriteLine($"The file '{filePath}' doesn't exist");
41+
return;
42+
}
43+
44+
var yml = File.ReadAllText(filePath);
45+
var deserializer = new DeserializerBuilder()
46+
.WithNamingConvention(UnderscoredNamingConvention.Instance)
47+
.Build();
48+
var faasConfiguration = deserializer.Deserialize<FaasConfiguration>(yml);
49+
using (var httpClient = new HttpClient())
50+
{
51+
var jObj = new JObject
52+
{
53+
{ "SerializedConfigurationFile", Convert.ToBase64String(Encoding.UTF8.GetBytes(yml)) }
54+
};
55+
var request = new HttpRequestMessage
56+
{
57+
Method = HttpMethod.Post,
58+
Content = new StringContent(jObj.ToString(), Encoding.UTF8, "application/json"),
59+
RequestUri = new Uri($"{faasConfiguration.Provider.Gateway}/configuration")
60+
};
61+
var httpResult = httpClient.SendAsync(request).Result;
62+
httpResult.EnsureSuccessStatusCode();
63+
Console.WriteLine("Configuration is applied");
64+
}
65+
}
66+
}
67+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using FaasNet.Common.Configuration;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Net.Http;
8+
using System.Text;
9+
using YamlDotNet.Serialization;
10+
using YamlDotNet.Serialization.NamingConventions;
11+
12+
namespace FaasNet.CLI.Commands
13+
{
14+
public class ApplyFileCommand : IMenuItemCommand
15+
{
16+
public string Command => "-f";
17+
18+
public string Description => "Apply file configuration";
19+
20+
public void Execute(IEnumerable<string> args)
21+
{
22+
if (!args.Any())
23+
{
24+
Console.Write("A file must be specified");
25+
return;
26+
}
27+
28+
ApplyCommand.Apply(args.First());
29+
}
30+
}
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Collections.Generic;
2+
3+
namespace FaasNet.CLI.Commands
4+
{
5+
public interface IMenuItemCommand
6+
{
7+
public string Command { get; }
8+
public string Description { get; }
9+
10+
void Execute(IEnumerable<string> args);
11+
}
12+
}

src/FaasNet.CLI/FaasNet.CLI.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\FaasNet.Common\FaasNet.Common.csproj" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="YamlDotNet" Version="11.2.1" />
14+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
15+
</ItemGroup>
16+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using FaasNet.CLI.Commands;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace FaasNet.CLI.Helpers
7+
{
8+
public static class MenuHelper
9+
{
10+
public static void Execute(IEnumerable<string> args, List<IMenuItemCommand> commands)
11+
{
12+
if (!args.Any())
13+
{
14+
DisplayHelper(commands);
15+
return;
16+
}
17+
18+
var cmd = commands.FirstOrDefault(c => c.Command == args.First());
19+
if (cmd == null)
20+
{
21+
DisplayHelper(commands);
22+
return;
23+
}
24+
25+
cmd.Execute(args.Skip(1));
26+
}
27+
28+
private static void DisplayHelper(List<IMenuItemCommand> commands)
29+
{
30+
foreach (var cmd in commands)
31+
{
32+
Console.WriteLine($"{cmd.Command} \t\t {cmd.Description}");
33+
}
34+
}
35+
}
36+
}

src/FaasNet.CLI/Program.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using FaasNet.CLI.Commands;
2+
using FaasNet.CLI.Helpers;
3+
using System.Collections.Generic;
4+
5+
namespace FaasNet.CLI
6+
{
7+
class Program
8+
{
9+
private static List<IMenuItemCommand> Commands = new List<IMenuItemCommand>
10+
{
11+
new ApplyCommand()
12+
};
13+
14+
static void Main(string[] args)
15+
{
16+
MenuHelper.Execute(args, Commands);
17+
}
18+
}
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"profiles": {
3+
"FaasNet.CLI": {
4+
"commandName": "Project"
5+
}
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace FaasNet.Common.Configuration
4+
{
5+
public class FaasApiConfiguration
6+
{
7+
public string Path { get; set; }
8+
public ICollection<FaasApiOperationConfiguration> Operations { get; set; }
9+
}
10+
}

0 commit comments

Comments
 (0)