-
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.
- Loading branch information
1 parent
cc2333e
commit 0e4bdbd
Showing
21 changed files
with
938 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,19 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text=auto | ||
|
||
############################################################################### | ||
# Set default behavior for command prompt diff. | ||
# | ||
# This is need for earlier builds of msysgit that does not have it on by | ||
# default for csharp files. | ||
# Note: This is only used by command line | ||
############################################################################### | ||
#*.cs diff=csharp | ||
# Force bash scripts to always use lf line endings so that if a repo is accessed | ||
# in Unix via a file share from Windows, the scripts will work. | ||
*.in text eol=lf | ||
*.sh text eol=lf | ||
|
||
############################################################################### | ||
# Set the merge driver for project and solution files | ||
# | ||
# Merging from the command prompt will add diff markers to the files if there | ||
# are conflicts (Merging from VS is not affected by the settings below, in VS | ||
# the diff markers are never inserted). Diff markers may cause the following | ||
# file extensions to fail to load in VS. An alternative would be to treat | ||
# these files as binary and thus will always conflict and require user | ||
# intervention with every merge. To do so, just uncomment the entries below | ||
############################################################################### | ||
#*.sln merge=binary | ||
#*.csproj merge=binary | ||
#*.vbproj merge=binary | ||
#*.vcxproj merge=binary | ||
#*.vcproj merge=binary | ||
#*.dbproj merge=binary | ||
#*.fsproj merge=binary | ||
#*.lsproj merge=binary | ||
#*.wixproj merge=binary | ||
#*.modelproj merge=binary | ||
#*.sqlproj merge=binary | ||
#*.wwaproj merge=binary | ||
# Likewise, force cmd and batch scripts to always use crlf | ||
*.cmd text eol=crlf | ||
*.bat text eol=crlf | ||
|
||
############################################################################### | ||
# behavior for image files | ||
# | ||
# image files are treated as binary by default. | ||
############################################################################### | ||
#*.jpg binary | ||
#*.png binary | ||
#*.gif binary | ||
*.cs text=auto diff=csharp | ||
*.csproj text=auto | ||
*.sln text=auto | ||
*.resx text=auto | ||
*.xml text=auto | ||
*.txt text=auto | ||
|
||
############################################################################### | ||
# diff behavior for common document formats | ||
# | ||
# Convert binary document formats to text before diffing them. This feature | ||
# is only available from the command line. Turn it on by uncommenting the | ||
# entries below. | ||
############################################################################### | ||
#*.doc diff=astextplain | ||
#*.DOC diff=astextplain | ||
#*.docx diff=astextplain | ||
#*.DOCX diff=astextplain | ||
#*.dot diff=astextplain | ||
#*.DOT diff=astextplain | ||
#*.pdf diff=astextplain | ||
#*.PDF diff=astextplain | ||
#*.rtf diff=astextplain | ||
#*.RTF diff=astextplain | ||
packages/ binary |
This file was deleted.
Oops, something went wrong.
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
12 changes: 12 additions & 0 deletions
12
src/GeoTools.GeoServer.Abstractions/Models/Workspace/GetWorkspaceResponse.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,12 @@ | ||
namespace GeoTools.GeoServer.Models | ||
{ | ||
public class GetWorkspaceResponse | ||
{ | ||
public WorkspaceSummary Workspace { get; } | ||
|
||
public GetWorkspaceResponse(WorkspaceSummary workspace) | ||
{ | ||
Workspace = workspace; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/GeoTools.GeoServer.Abstractions/Models/Workspace/WorkspaceInfo.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,30 @@ | ||
namespace GeoTools.GeoServer.Models | ||
{ | ||
/// <summary> | ||
/// Workspace. | ||
/// </summary> | ||
public class WorkspaceInfo | ||
{ | ||
/// <summary> | ||
/// Name of the workspace. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Is the workspace content isolated so it is not included as part of | ||
/// global web services. | ||
/// </summary> | ||
/// <remarks> | ||
/// Isolated workspaces content is only visible and queryable in the | ||
/// context of a virtual service bound to the isolated workspace. | ||
/// </remarks> | ||
/// <value>False by default.</value> | ||
public bool Isolated { get; } | ||
|
||
public WorkspaceInfo(string name, bool isolated = false) | ||
{ | ||
Name = name; | ||
Isolated = isolated; | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/GeoTools.GeoServer.Abstractions/Models/Workspace/WorkspaceSummary.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,48 @@ | ||
namespace GeoTools.GeoServer.Models | ||
{ | ||
/// <summary> | ||
/// Workspace Response. | ||
/// </summary> | ||
public class WorkspaceSummary | ||
{ | ||
/// <summary> | ||
/// Name of workspace. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Is the workspace content isolated so it is not included as part of | ||
/// global web services. | ||
/// </summary> | ||
/// <remarks> | ||
/// Isolated workspaces content is only visible and queryable in the | ||
/// context of a virtual service bound to the isolated workspace. | ||
/// </remarks> | ||
/// <value>False by default.</value> | ||
public bool Isolated { get; } | ||
|
||
/// <summary> | ||
/// URL to Datas tores in this workspace. | ||
/// </summary> | ||
public string DataStores { get; } | ||
|
||
/// <summary> | ||
/// URL to Coverage stores in this workspace. | ||
/// </summary> | ||
public string CoverageStores { get; } | ||
|
||
/// <summary> | ||
/// URL to WMS stores in this workspace. | ||
/// </summary> | ||
public string WmsStores { get; } | ||
|
||
public WorkspaceSummary(string name, string dataStores, string coverageStores, string wmsStores, bool isolated = false) | ||
{ | ||
Name = name; | ||
Isolated = isolated; | ||
DataStores = dataStores; | ||
CoverageStores = coverageStores; | ||
WmsStores = wmsStores; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/GeoTools.GeoServer.Abstractions/Models/Workspace/WorkspaceWrapper.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,15 @@ | ||
namespace GeoTools.GeoServer.Models | ||
{ | ||
/// <summary> | ||
/// Wrapper object around Workspace, in order to conform to how XStream serializes to JSON in GeoServer. | ||
/// </summary> | ||
public class WorkspaceWrapper | ||
{ | ||
public WorkspaceInfo Workspace { get; } | ||
|
||
public WorkspaceWrapper(WorkspaceInfo workspace) | ||
{ | ||
Workspace = workspace; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/GeoTools.GeoServer.Abstractions/Services/IWorkspaceService.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,17 @@ | ||
using GeoTools.GeoServer.Models; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace GeoTools.GeoServer.Services | ||
{ | ||
public interface IWorkspaceService | ||
{ | ||
/// <summary> | ||
/// Retrieve a Workspace. | ||
/// </summary> | ||
/// <param name="name">The name of the workspace to fetch.</param> | ||
/// <param name="token"></param> | ||
/// <returns>Retrieves a single workspace definition.</returns> | ||
Task<WorkspaceSummary> GetWorkspaceAsync(string name, CancellationToken token); | ||
} | ||
} |
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,68 @@ | ||
using GeoTools.GeoServer.Helpers.Options; | ||
using GeoTools.GeoServer.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
|
||
namespace GeoTools.GeoServer.Extensions | ||
{ | ||
public static class GeoServerExtensions | ||
{ | ||
public static IServiceCollection AddGeoServer(this IServiceCollection services) | ||
{ | ||
return services.AddGeoServer(options => { }); | ||
} | ||
|
||
public static IServiceCollection AddGeoServer(this IServiceCollection services, Action<GeoServerOptions> configureOptions) | ||
{ | ||
return AddGeoServer(services, (options, _) => configureOptions(options)); | ||
} | ||
|
||
public static IServiceCollection AddGeoServer(this IServiceCollection services, Action<GeoServerOptions, IServiceProvider> configureOptions) | ||
{ | ||
services | ||
.AddSingleton<IValidateOptions<GeoServerOptions>, ValidateGeoServerOptions>() | ||
.AddOptions<GeoServerOptions>() | ||
.Configure(configureOptions); | ||
|
||
services | ||
.AddHttpClient(GeoServerOptions.HttpClientName, ConfigureHttpClient); | ||
|
||
return services | ||
.AddTransient<IWorkspaceService, WorkspaceService>(); | ||
} | ||
|
||
private static void ConfigureHttpClient(IServiceProvider provider, HttpClient client) | ||
{ | ||
var optionsWrapper = provider.GetService<IOptions<GeoServerOptions>>(); | ||
|
||
if (optionsWrapper != null) | ||
{ | ||
var options = optionsWrapper.Value; | ||
|
||
if (options.ConfigureHttpClient != null) | ||
{ | ||
options.ConfigureHttpClient(provider, client); | ||
} | ||
else | ||
{ | ||
client.BaseAddress = options.BaseAddress; | ||
|
||
if (options.AuthorizationHeaderValue != null) | ||
{ | ||
var authTokens = options.AuthorizationHeaderValue.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); | ||
var authSchema = authTokens[0]; | ||
var authParameter = string.Join(" ", authTokens.Skip(1)); | ||
|
||
client.DefaultRequestHeaders.Authorization = string.IsNullOrEmpty(authParameter) | ||
? new AuthenticationHeaderValue(authSchema) | ||
: new AuthenticationHeaderValue(authSchema, authParameter); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="7.0.0" /> | ||
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" /> | ||
<PackageReference Include="System.Text.Json" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\GeoTools.GeoServer.Abstractions\GeoTools.GeoServer.Abstractions.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="Resources\ExceptionMessages.Designer.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>ExceptionMessages.resx</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Update="Resources\ExceptionMessages.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>ExceptionMessages.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
</Project> |
37 changes: 37 additions & 0 deletions
37
src/GeoTools.GeoServer/Helpers/Options/ValidateGeoServerOptions.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,37 @@ | ||
using GeoTools.GeoServer.Resources; | ||
using Microsoft.Extensions.Options; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace GeoTools.GeoServer.Helpers.Options | ||
{ | ||
internal class ValidateGeoServerOptions : IValidateOptions<GeoServerOptions> | ||
{ | ||
public ValidateOptionsResult Validate(string name, GeoServerOptions options) | ||
{ | ||
var failures = new List<string>(); | ||
|
||
if (options is null) | ||
return ValidateOptionsResult.Fail(ExceptionMessages.Options_Null); | ||
|
||
if (options.ConfigureHttpClient != null) | ||
return ValidateOptionsResult.Success; | ||
|
||
if (options.BaseAddress == null) | ||
failures.Add(ExceptionMessages.Options_BaseAddressNull); | ||
else if (options.BaseAddress.IsFile) | ||
failures.Add(ExceptionMessages.Options_BaseAddressFile); | ||
|
||
if (options.AuthorizationHeaderValue != null && | ||
options.AuthorizationHeaderValue.Split( | ||
new char[] { ' ' }, | ||
StringSplitOptions.RemoveEmptyEntries).Length < 1) | ||
failures.Add(ExceptionMessages.Options_AuthorizationHeaderValueWrongFormat); | ||
|
||
if (failures.Count > 0) | ||
return ValidateOptionsResult.Fail(failures); | ||
else | ||
return ValidateOptionsResult.Success; | ||
} | ||
} | ||
} |
Oops, something went wrong.