diff options
author | WouterTinus <wouter.tinus@gmail.com> | 2019-09-07 01:36:12 +0200 |
---|---|---|
committer | WouterTinus <wouter.tinus@gmail.com> | 2019-09-07 01:36:12 +0200 |
commit | 7673fa357a81444cf6c216267dfab4e76684ba5c (patch) | |
tree | 73c0bd36e5b6261cd89a168c2a099f6556c59f4d /src/main.lib/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs | |
parent | 42aa0faa4de6ea4184cfe1a5830508777418b11a (diff) | |
download | letsencrypt-win-simple-7673fa357a81444cf6c216267dfab4e76684ba5c.zip letsencrypt-win-simple-7673fa357a81444cf6c216267dfab4e76684ba5c.tar.gz letsencrypt-win-simple-7673fa357a81444cf6c216267dfab4e76684ba5c.tar.bz2 |
move plugins & re-implement WebDav
Diffstat (limited to 'src/main.lib/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs')
-rw-r--r-- | src/main.lib/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/main.lib/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs b/src/main.lib/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs new file mode 100644 index 0000000..4b8979d --- /dev/null +++ b/src/main.lib/Plugins/ValidationPlugins/Http/HttpValidationOptionsFactory.cs @@ -0,0 +1,93 @@ +using PKISharp.WACS.DomainObjects; +using PKISharp.WACS.Plugins.Base.Factories; +using PKISharp.WACS.Plugins.Interfaces; +using PKISharp.WACS.Services; +using System; +using System.Collections.Generic; + +namespace PKISharp.WACS.Plugins.ValidationPlugins +{ + internal abstract class HttpValidationOptionsFactory<TPlugin, TOptions> : + ValidationPluginOptionsFactory<TPlugin, TOptions> + where TPlugin : IValidationPlugin + where TOptions : HttpValidationOptions<TPlugin>, new() + { + protected readonly IArgumentsService _arguments; + + public HttpValidationOptionsFactory(IArgumentsService arguments) + { + _arguments = arguments; + } + + /// <summary> + /// Get webroot path manually + /// </summary> + public HttpValidationOptions<TPlugin> BaseAquire(Target target, IInputService input, RunLevel runLevel) + { + var allowEmtpy = AllowEmtpy(target); + string path = _arguments.TryGetArgument(null, input, WebrootHint(allowEmtpy)); + while ( + (!string.IsNullOrEmpty(path) && !PathIsValid(path)) || + (string.IsNullOrEmpty(path) && !allowEmtpy)) + { + path = _arguments.TryGetArgument(null, input, WebrootHint(allowEmtpy)); + } + return new TOptions { + Path = path, + CopyWebConfig = target.IIS || input.PromptYesNo("Copy default web.config before validation?", false) + }; + } + + /// <summary> + /// By default we don't allow emtpy paths, but FileSystem + /// makes an exception because it can read from IIS + /// </summary> + /// <param name="target"></param> + /// <returns></returns> + public virtual bool AllowEmtpy(Target target) => false; + + /// <summary> + /// Check if the webroot makes sense + /// </summary> + /// <returns></returns> + public virtual bool PathIsValid(string path) => false; + + /// <summary> + /// Get webroot automatically + /// </summary> + public HttpValidationOptions<TPlugin> BaseDefault(Target target) + { + string path = null; + var allowEmpty = AllowEmtpy(target); + var args = _arguments.GetArguments<HttpValidationArguments>(); + if (string.IsNullOrEmpty(path) && !allowEmpty) + { + path = _arguments.TryGetRequiredArgument(nameof(args.WebRoot), args.WebRoot); + } + if (!string.IsNullOrEmpty(path) && !PathIsValid(path)) + { + throw new ArgumentException($"Invalid webroot {path}: {WebrootHint(false)[0]}"); + } + return new TOptions + { + Path = path, + CopyWebConfig = target.IIS || args.ManualTargetIsIIS + }; + } + + /// <summary> + /// Hint to show to the user what the webroot should look like + /// </summary> + /// <returns></returns> + public virtual string[] WebrootHint(bool allowEmpty) + { + var ret = new List<string> { "Path to the root of the site that will handle authentication" }; + if (allowEmpty) + { + ret.Add("Leave empty to automatically read the path from IIS"); + } + return ret.ToArray(); + } + } + +}
\ No newline at end of file |