Skip to content

Commit

Permalink
v1.0.3, retarget to .NET Core and .NET framework, update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Christner committed Apr 20, 2019
1 parent dd075df commit 6363575
Show file tree
Hide file tree
Showing 38 changed files with 3,576 additions and 169 deletions.
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,34 @@ RESTful HTTP/HTTPS server for Microsoft SQL Server, MySQL, and PostgreSQL databa
## Description
RestDb spawns a RESTful HTTP/HTTPS server that exposes a series of APIs allowing you to perform SELECT, INSERT, UPDATE, DELETE, and TRUNCATE against tables in Microsoft SQL Server, MySQL, and PostgreSQL.

## New in v1.0.2
- PostgreSQL support
## New in v1.0.3
- Retarget to .NET Core and .NET Framework

## Important Notes
- If you specify a listener other than ```localhost``` or ```127.0.0.1```, you may have to run with elevated privileges.
- The HTTP HOST header MUST match the listener hostname, otherwise you'll get ```Bad Request``` errors back.
- By default, access to RestDb is UNAUTHENTICATED. Configure ```System.json``` with API keys to enable authentication, and set the ```RequireAuthentication``` value to ```true```.

## Execution
In Windows, using .NET Framework
```
> cd RestDb\bin\debug\net462
> RestDb.exe
```

In Windows, using .NET Core
```
> cd RestDb\bin\debug\netcoreapp2.2
> dotnet RestDb.dll
```

In Linux/Mac, using .NET Core
```
$ cd RestDb/bin/debug/netcoreapp2.2
$ dotnet RestDb.dll
```

## Running in Mono
Before starting in Linux or Mac environments, you should run the Mono AOT.
In Mono with .NET Framework environments, you should run the Mono AOT.
```
mono --aot=nrgctx-trampolines=8096,nimt-trampolines=8096,ntrampolines=4048 --server RestDb.exe
mono --server RestDb.exe
Expand All @@ -18,10 +41,8 @@ mono --server RestDb.exe
## Setup
Simply compile from source, run ```RestDb.exe```, and a system configuration file will be created for you. Setup scripts for both MSSQL and MySQL are included in the Docs directory of the project, which create the test database and person table used in the examples below.

1) Start RestDb.exe
1) Start RestDb.exe (.NET Framework) or RestDb.dll (.NET Core) as described above.
```
Windows : C:\RestDb\RestDb.exe
Linux/Mac : $ mono --server RestDb.exe
RestDb :: Starting Watson Webserver at http://localhost:8000
```

Expand Down Expand Up @@ -248,6 +269,7 @@ To enable authentication, set ```Server.RequireAuthentication``` to ```true``` a
Notes from previous versions (starting with v1.0.0) will be moved here.

v1.0.x
- PostgreSQL support
- Authentication via API key
- Initial release

13 changes: 8 additions & 5 deletions RestDb.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestDb", "RestDb\RestDb.csproj", "{9D53A716-9A4C-482D-9C25-C91257A60B00}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestDb", "RestDb\RestDb.csproj", "{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9D53A716-9A4C-482D-9C25-C91257A60B00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D53A716-9A4C-482D-9C25-C91257A60B00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D53A716-9A4C-482D-9C25-C91257A60B00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D53A716-9A4C-482D-9C25-C91257A60B00}.Release|Any CPU.Build.0 = Release|Any CPU
{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EF516CBA-7C5E-4DDD-8CD8-3C1F25FCB5D8}
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion RestDb/APIs/Get/GetTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
Expand Down Expand Up @@ -82,7 +83,7 @@ static WatsonWebserver.HttpResponse GetTable(WatsonWebserver.HttpRequest req)

if (req.QuerystringEntries.ContainsKey("_index_start")) indexStart = Convert.ToInt32(req.QuerystringEntries["_index_start"]);
if (req.QuerystringEntries.ContainsKey("_max_results")) maxResults = Convert.ToInt32(req.QuerystringEntries["_max_results"]);
if (req.QuerystringEntries.ContainsKey("_order_by")) orderBy = HttpUtility.UrlDecode(req.QuerystringEntries["_order_by"]);
if (req.QuerystringEntries.ContainsKey("_order_by")) orderBy = WebUtility.UrlDecode(req.QuerystringEntries["_order_by"]);
if (req.QuerystringEntries.ContainsKey("_return_fields")) returnFields = Common.CsvToStringList(req.QuerystringEntries["_return_fields"]);

result = db.Select(tableName, indexStart, maxResults, returnFields, filter, orderBy);
Expand Down
12 changes: 6 additions & 6 deletions RestDb/Classes/AuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ public bool Authenticate(HttpRequest req)
if (String.IsNullOrEmpty(curr.Key)) continue;
if (curr.Key.ToLower().Equals(apiKey.ToLower()))
{
switch (req.Method.ToLower())
switch (req.Method)
{
case "get":
case "head":
case HttpMethod.GET:
case HttpMethod.HEAD:
return curr.AllowGet;

case "put":
case HttpMethod.PUT:
return curr.AllowPut;

case "post":
case HttpMethod.POST:
return curr.AllowPost;

case "delete":
case HttpMethod.DELETE:
return curr.AllowDelete;

default:
Expand Down
34 changes: 2 additions & 32 deletions RestDb/Classes/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using Newtonsoft.Json;
using Mono.Posix;
using Mono.Unix;
using Mono.Unix.Native;
using Newtonsoft.Json;

namespace RestDb
{
Expand Down Expand Up @@ -789,34 +786,7 @@ public static bool IsLaterThanNow(DateTime dt)
#endregion

#region Environment

public static bool IsAdmin()
{
int platform = (int)Environment.OSVersion.Platform;
if ((platform == 4) || (platform == 6) || (platform == 128))
{
#region Linux

// see http://stackoverflow.com/questions/2615997/winforms-console-application-on-mono-how-to-know-it-runs-as-root
if (Mono.Unix.Native.Syscall.getuid() == 0) return true;

#endregion
}
else
{
#region Windows

// see http://stackoverflow.com/questions/11660184/c-sharp-check-if-run-as-administrator
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
if (principal.IsInRole(WindowsBuiltInRole.Administrator)) return true;

#endregion
}

return false;
}


public static void ExitApplication(string method, string text, int returnCode)
{
Console.WriteLine("---");
Expand Down
5 changes: 4 additions & 1 deletion RestDb/Classes/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ private void RunSetup()
Console.WriteLine("------------");
Console.WriteLine("We'll collect some values and put together your initial configuration.");
Console.WriteLine("");
Console.WriteLine("On which hostname should this node listen? The hostname supplied here must");
Console.WriteLine("On which hostname should this node listen? The hostname supplied here MUST");
Console.WriteLine("match the host header received on incoming RESTful HTTP requests. It is");
Console.WriteLine("recommended that you use the DNS hostname of the machine.");
Console.WriteLine("");
Console.WriteLine("NOTE: using anything other than 127.0.0.1 or localhost may require that you");
Console.WriteLine("run RestDb with elevated/admin privileges.");
Console.WriteLine("");

ret.Server = new ServerSettings();
ret.Server.ListenerHostname = Common.InputString("Hostname?", "localhost", false);
Expand Down
132 changes: 27 additions & 105 deletions RestDb/RestDb.csproj
Original file line number Diff line number Diff line change
@@ -1,115 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9D53A716-9A4C-482D-9C25-C91257A60B00}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>RestDb</RootNamespace>
<AssemblyName>RestDb</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworks>netcoreapp2.2;net462</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.3</Version>
<Authors>Joel Christner</Authors>
<Description>C:\Code\Misc\RestDb\RestDbOriginal\APIs\</Description>
<Copyright>(c)2019 Joel Christner</Copyright>
<PackageProjectUrl>https://github.com/jchristn/restdb</PackageProjectUrl>
<RepositoryUrl>https://github.com/jchristn/restdb</RepositoryUrl>
<RepositoryType>Github</RepositoryType>
<PackageTags>rest,database,api,db</PackageTags>
<PackageReleaseNotes>Retarget to .NET Core and .NET Framework</PackageReleaseNotes>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="DatabaseWrapper, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DatabaseWrapper.1.2.1\lib\DatabaseWrapper.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Posix.4.0.0.0\lib\net40\Mono.Posix.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Npgsql, Version=3.2.2.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
<HintPath>..\packages\Npgsql.3.2.2\lib\net451\Npgsql.dll</HintPath>
</Reference>
<Reference Include="RegexMatcher, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RegexMatcher.1.0.0\lib\RegexMatcher.dll</HintPath>
</Reference>
<Reference Include="SyslogLogging, Version=1.0.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SyslogLogging.1.0.8\lib\SyslogLogging.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Watson, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Watson.1.2.1\lib\Watson.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Compile Include="APIs\Delete\DeleteTable.cs" />
<Compile Include="APIs\Get\GetDatabase.cs" />
<Compile Include="APIs\Get\GetDatabaseClients.cs" />
<Compile Include="APIs\Get\GetTable.cs" />
<Compile Include="APIs\Get\GetHelloWorld.cs" />
<Compile Include="APIs\Get\GetDatabases.cs" />
<Compile Include="APIs\Post\PostTable.cs" />
<Compile Include="APIs\Put\PutTable.cs" />
<Compile Include="APIs\Support\DeserializeExpression.cs" />
<Compile Include="Classes\AuthManager.cs" />
<Compile Include="Classes\ApiKey.cs" />
<Compile Include="ControlQueryKeys.cs" />
<Compile Include="Classes\ErrorResponse.cs" />
<Compile Include="Classes\Column.cs" />
<Compile Include="Classes\Common.cs" />
<Compile Include="Classes\Table.cs" />
<Compile Include="Classes\Settings.cs" />
<Compile Include="Classes\Setup.cs" />
<Compile Include="Classes\DatabaseManager.cs" />
<Compile Include="Classes\Template.cs" />
<Compile Include="Classes\Database.cs" />
<Compile Include="Server.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="DatabaseWrapper.dll.config" />
<None Include="packages.config" />
<None Remove="Docs\MsSqlSample.txt" />
<None Remove="Docs\MySqlSample.txt" />
<None Remove="Docs\PgSqlSample.txt" />
</ItemGroup>

<ItemGroup>
<Content Include="Docs\MsSqlSample.txt" />
<Content Include="Docs\MySqlSample.txt" />
<Content Include="Docs\PgSqlSample.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

<ItemGroup>
<PackageReference Include="DatabaseWrapper" Version="1.2.7" />
<PackageReference Include="SyslogLogging" Version="1.0.10" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
<PackageReference Include="Watson" Version="1.6.0" />
</ItemGroup>

</Project>
Loading

0 comments on commit 6363575

Please sign in to comment.