Skip to content

Commit

Permalink
Added GetWorkspace(name).
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmikecreations committed Nov 24, 2022
1 parent cc2333e commit 0e4bdbd
Show file tree
Hide file tree
Showing 21 changed files with 938 additions and 68 deletions.
72 changes: 14 additions & 58 deletions .gitattributes
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
9 changes: 0 additions & 9 deletions GeoTools.GeoServer/Class1.cs

This file was deleted.

14 changes: 13 additions & 1 deletion GeoTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33020.496
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeoTools.GeoServer", "GeoTools.GeoServer\GeoTools.GeoServer.csproj", "{46D1A21A-2C2F-46CF-899C-90D3D8E3B747}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeoTools.GeoServer", "src\GeoTools.GeoServer\GeoTools.GeoServer.csproj", "{46D1A21A-2C2F-46CF-899C-90D3D8E3B747}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeoTools.GeoServer.Abstractions", "src\GeoTools.GeoServer.Abstractions\GeoTools.GeoServer.Abstractions.csproj", "{CD6C97F4-922E-4C71-AADF-926008764840}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeoTools.GeoServer.Tests", "tests\GeoTools.GeoServer.Tests\GeoTools.GeoServer.Tests.csproj", "{AA3ECC68-7ACF-4625-896F-96948198ECFE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +19,14 @@ Global
{46D1A21A-2C2F-46CF-899C-90D3D8E3B747}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46D1A21A-2C2F-46CF-899C-90D3D8E3B747}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46D1A21A-2C2F-46CF-899C-90D3D8E3B747}.Release|Any CPU.Build.0 = Release|Any CPU
{CD6C97F4-922E-4C71-AADF-926008764840}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD6C97F4-922E-4C71-AADF-926008764840}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD6C97F4-922E-4C71-AADF-926008764840}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD6C97F4-922E-4C71-AADF-926008764840}.Release|Any CPU.Build.0 = Release|Any CPU
{AA3ECC68-7ACF-4625-896F-96948198ECFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA3ECC68-7ACF-4625-896F-96948198ECFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA3ECC68-7ACF-4625-896F-96948198ECFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA3ECC68-7ACF-4625-896F-96948198ECFE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>

</Project>
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;
}
}
}
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;
}
}
}
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;
}
}
}
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 src/GeoTools.GeoServer.Abstractions/Services/IWorkspaceService.cs
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);
}
}
68 changes: 68 additions & 0 deletions src/GeoTools.GeoServer/Extensions/GeoServerExtensions.cs
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);
}
}
}
}
}
}
36 changes: 36 additions & 0 deletions src/GeoTools.GeoServer/GeoTools.GeoServer.csproj
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 src/GeoTools.GeoServer/Helpers/Options/ValidateGeoServerOptions.cs
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;
}
}
}
Loading

0 comments on commit 0e4bdbd

Please sign in to comment.