-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add command line tool for generating countries.json and dockerise it
- Loading branch information
1 parent
7112c34
commit 2cadf44
Showing
17 changed files
with
160 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/.idea | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/azds.yaml | ||
**/bin | ||
**/charts | ||
**/docker-compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
LICENSE | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build | ||
COPY . . | ||
ARG Version | ||
RUN dotnet publish "./DragonFruit.OnionFruit.Status.Generator/DragonFruit.OnionFruit.Status.Generator.csproj" -c Release -o /app/publish /p:AssemblyVersion=$Version | ||
|
||
FROM mcr.microsoft.com/dotnet/net:5.0 AS final | ||
WORKDIR /app | ||
COPY --from=build /app/publish . | ||
ENV OUTPUT_FILE=/output/countries.json | ||
ENTRYPOINT ["dotnet", "DragonFruit.OnionFruit.Status.Generator.dll"] |
13 changes: 13 additions & 0 deletions
13
DragonFruit.OnionFruit.Status.Generator/DragonFruit.OnionFruit.Status.Generator.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DragonFruit.OnionFruit.Status\DragonFruit.OnionFruit.Status.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
27 changes: 27 additions & 0 deletions
27
DragonFruit.OnionFruit.Status.Generator/OnionFruitCountriesList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// OnionFruit.Status Copyright 2021 DragonFruit Network <inbox@dragonfruit.network> | ||
// Licensed under MIT. Please refer to the LICENSE file for more info | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
|
||
namespace DragonFruit.OnionFruit.Status.Generator | ||
{ | ||
public class OnionFruitCountriesList | ||
{ | ||
[JsonProperty("in")] | ||
public string[] In { get; set; } | ||
|
||
[JsonProperty("out")] | ||
public string[] Out { get; set; } | ||
|
||
private static IEnumerable<string> GetCountriesWithFlag(IEnumerable<IGrouping<string, TorRelay>> info, RelayFlags flag) => | ||
info.Where(x => x.Any(y => y.Flags.HasFlag(flag))).Select(x => x.Key); | ||
|
||
public static explicit operator OnionFruitCountriesList(IGrouping<string, TorRelay>[] info) => new() | ||
{ | ||
In = GetCountriesWithFlag(info, RelayFlags.Guard).ToArray(), | ||
Out = GetCountriesWithFlag(info, RelayFlags.Exit).ToArray() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// OnionFruit.Status Copyright 2021 DragonFruit Network <inbox@dragonfruit.network> | ||
// Licensed under MIT. Please refer to the LICENSE file for more info | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Bia.Countries.Iso3166; | ||
using DragonFruit.Common.Data; | ||
using DragonFruit.Common.Data.Services; | ||
|
||
namespace DragonFruit.OnionFruit.Status.Generator | ||
{ | ||
internal static class Program | ||
{ | ||
private static readonly ApiClient Client = new(); | ||
|
||
private static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Fetching data..."); | ||
var nodes = Client.GetServerInfo().Relays; | ||
var countries = nodes.GroupBy(x => x.CountryCode.ToUpper()).Where(x => Countries.GetCountryByAlpha2(x.Key) is not null).ToArray(); | ||
|
||
Console.ForegroundColor = ConsoleColor.Magenta; | ||
Console.WriteLine($"Downloaded {nodes.Length} relay metadata packets over {countries.Length} countries"); | ||
var response = (OnionFruitCountriesList)countries; | ||
|
||
Console.WriteLine($"Response contains {response.In.Length} entry countries and {response.Out.Length} exit countries"); | ||
|
||
var saveLocation = Environment.GetEnvironmentVariable("OUTPUT_FILE") ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "countries.json"); | ||
Console.Write($"Writing to {saveLocation}..."); | ||
|
||
FileServices.WriteFile(saveLocation, response); | ||
|
||
Console.ForegroundColor = ConsoleColor.Green; | ||
Console.WriteLine("Complete"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
{"solution":"DragonFruit.OnionFruit.Status.sln","displayLevel":3,"errorLevel":3} | ||
{ | ||
"solution": "DragonFruit.OnionFruit.Status.sln", | ||
"displayLevel": 3, | ||
"errorLevel": 3 | ||
} |
File renamed without changes.