예제 #1
0
 /// <summary>
 /// .ctor
 /// </summary>
 public SiteMapBuilder(IOptions <RootOptions> rootOptions,
                       IOurGardenRepository context)
 {
     _rootOptions     = rootOptions.Value;
     _context         = (context as OurGardenRepository).Context;
     _publicDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
 }
예제 #2
0
        public void OptionNames()
        {
            var s     = new RootOptions();
            var names = s.GetOptionNames();

            Assert.AreEqual(propertyNames.Count, names.Count);
        }
예제 #3
0
        public static CollectionRuleOptions CreateCollectionRule(this RootOptions rootOptions, string name)
        {
            CollectionRuleOptions options = new();

            rootOptions.CollectionRules.Add(name, options);
            return(options);
        }
예제 #4
0
        /// <summary>
        /// Sets API Key authentication. Use this overload for most operations, unless specifically testing Authentication or Authorization.
        /// </summary>
        public static RootOptions UseApiKey(this RootOptions options, string algorithmName, Guid subject, out string token)
        {
            string     subjectStr = subject.ToString("D");
            Claim      audClaim   = new Claim(AuthConstants.ClaimAudienceStr, AuthConstants.ApiKeyJwtAudience);
            Claim      issClaim   = new Claim(AuthConstants.ClaimIssuerStr, AuthConstants.ApiKeyJwtInternalIssuer);
            Claim      subClaim   = new Claim(AuthConstants.ClaimSubjectStr, subjectStr);
            JwtPayload newPayload = new JwtPayload(new Claim[] { audClaim, issClaim, subClaim });

            return(options.UseApiKey(algorithmName, subjectStr, newPayload, out token));
        }
예제 #5
0
        public static RootOptions SetDumpTempFolder(this RootOptions options, string directoryPath)
        {
            if (null == options.Storage)
            {
                options.Storage = new StorageOptions();
            }

            options.Storage.DumpTempFolder = directoryPath;

            return(options);
        }
예제 #6
0
        private static void RunOptionsAndReturnExitCode(RootOptions opts)
        {
            // print all verbs...

            var typeswithgroups = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(t => t.GetCustomAttribute <VerbGroupAttribute>() != null)
                                  .GroupBy(t => t.GetCustomAttribute <VerbGroupAttribute>().Group)

                                  .ToArray();

            // blah
        }
예제 #7
0
        public void ZIndexCustom()
        {
            var propertyIndex = 2;
            var expectedValue = r.Next(-10, 10, 0);

            var src = new RootOptions {
                ZIndex = expectedValue
            };
            var so = PopulateOptions(src);

            AssertPopulatedProperty(so, propertyIndex, expectedValue);
        }
예제 #8
0
        public void WidthCustom()
        {
            var propertyIndex = 1;
            var expectedValue = new CSSLengthUnit(r.Next(1, 99), CSSUnit.Percent);

            var src = new RootOptions {
                Width = expectedValue
            };
            var so = PopulateOptions(src);

            AssertPopulatedProperty(so, propertyIndex, expectedValue.ToString());
        }
예제 #9
0
        public void EmptyContructor()
        {
            var src = new RootOptions
            {
            };

            var so = PopulateOptions(src);

            Assert.AreEqual(0, so.Count);

            so = PopulateOptions(src, true);
            Assert.AreEqual(3, so.Count);
        }
예제 #10
0
        public void ZIndexDefault()
        {
            var propertyIndex = 2;
            var expectedValue = RootOptions.Defaults.ZIndex;
            var src           = new RootOptions {
            };

            var so = PopulateOptions(src);

            AssertEmptyProperty(so, propertyIndex);

            so = PopulateOptions(src, true);
            AssertPopulatedProperty(so, propertyIndex, expectedValue);
        }
예제 #11
0
        public void WidthDefault()
        {
            var propertyIndex = 1;
            var expectedValue = RootOptions.Defaults.Width;
            var src           = new RootOptions {
            };

            var so = PopulateOptions(src);

            AssertEmptyProperty(so, propertyIndex);

            so = PopulateOptions(src, true);
            AssertPopulatedProperty(so, propertyIndex, expectedValue.ToString());
        }
예제 #12
0
 /// <summary>
 /// .ctor
 /// </summary>
 public EmailService(ILogger <EmailService> logger,
                     IOurGardenRepository repository,
                     IMjmlServices mjmlServices,
                     IOptions <EmailServiceConfigurationOptions> emailOption,
                     IOptions <RootOptions> rootOptions,
                     IEmailSender emailSender)
 {
     _logger              = logger;
     _repository          = repository;
     _mjmlServices        = mjmlServices;
     _emailServiceOptions = emailOption.Value;
     _rootOptions         = rootOptions.Value;
     _emailSender         = emailSender;
 }
예제 #13
0
        static int RunRootAuthority(RootOptions ro)
        {
            using (CertificateRootAuthority rootAuthority = new CertificateRootAuthority())
            {
                X509Certificate2 cert     = rootAuthority.GenerateRootCertificate(ro.SubjectName);
                byte[]           pfxBytes = cert.Export(X509ContentType.Pfx, ro.PfxPassword);
                File.WriteAllBytes(ro.PfxFile + ".pfx", pfxBytes);

                if (false == ro.NoPem)
                {
                    File.WriteAllText(ro.PfxFile + ".pem", cert.ToPem());
                }
            }

            return(0);
        }
예제 #14
0
        public static RootOptions AddFileSystemEgress(this RootOptions options, string name, string outputPath)
        {
            var egressProvider = new FileSystemEgressProviderOptions()
            {
                DirectoryPath = outputPath
            };

            options.Egress = new EgressOptions
            {
                FileSystem = new Dictionary <string, FileSystemEgressProviderOptions>()
                {
                    { name, egressProvider }
                }
            };

            return(options);
        }
예제 #15
0
 private void Run(string[] args)
 {
     if (Debugger.IsAttached)
     {
         try {
             Console.BufferWidth = Console.WindowWidth = 80;
         }
         catch { }
     }
     try {
         Console.OutputEncoding = Encoding.UTF8;
         var options = new RootOptions();
         var parser  = new Parser(s => s.HelpWriter = null);
         if (!parser.ParseArguments(args, options, (s, v) => { }))
         {
             InvokeError(options);
         }
         else if (options.List != null)
         {
             InvokeList(options.List);
         }
         else if (options.Start != null)
         {
             InvokeStart(options.Start);
         }
         else
         {
             InvokeHelp(options.Help);
         }
     }
     catch (Exception ex) {
         HelpView.Message(ErrorInfo.Exception(ex)).Render();
     }
     finally {
         if (Debugger.IsAttached)
         {
             View.PressEnter().Render();
             Console.ReadLine();
         }
     }
 }
예제 #16
0
        private void Run(string[] args)
        {
            try {
                if (args.Length == 0)
                {
                    InvokeHelp(new HelpOptions());
                    return;
                }

                var options = new RootOptions();
                if (!Parser.Default.ParseArguments(args, options, (s, o) => { }))
                {
                    Environment.Exit(Parser.DefaultExitCodeFail);
                }

                if (options.List != null)
                {
                    InvokeList(options.List);
                }
                else if (options.Start != null)
                {
                    InvokeStart(options.Start);
                }
                else
                {
                    InvokeHelp(options.Help);
                }
            }
            catch (Exception ex) {
                ConsoleRenderer.RenderDocument(View.Error(ex.Message, ex.ToString()));
            }
            finally {
                if (Debugger.IsAttached)
                {
                    ConsoleRenderer.RenderDocument(View.Info("Press any key..."));
                    Console.ReadLine();
                }
            }
        }
예제 #17
0
        public static RootOptions UseApiKey(this RootOptions options, string algorithmName, string subject, JwtPayload customPayload, out string token, out SecurityKey privateKey)
        {
            if (null == options.Authentication)
            {
                options.Authentication = new AuthenticationOptions();
            }

            if (null == options.Authentication.MonitorApiKey)
            {
                options.Authentication.MonitorApiKey = new MonitorApiKeyOptions();
            }

            SigningCredentials signingCreds;
            JsonWebKey         exportableJwk;

            switch (algorithmName)
            {
            case SecurityAlgorithms.EcdsaSha256:
            case SecurityAlgorithms.EcdsaSha256Signature:
            case SecurityAlgorithms.EcdsaSha384:
            case SecurityAlgorithms.EcdsaSha384Signature:
            case SecurityAlgorithms.EcdsaSha512:
            case SecurityAlgorithms.EcdsaSha512Signature:
                ECDsa            ecDsa    = ECDsa.Create(GetEcCurveFromName(algorithmName));
                ECDsaSecurityKey ecSecKey = new ECDsaSecurityKey(ecDsa);
                signingCreds = new SigningCredentials(ecSecKey, algorithmName);
                ECDsa            pubEcDsa    = ECDsa.Create(ecDsa.ExportParameters(false));
                ECDsaSecurityKey pubEcSecKey = new ECDsaSecurityKey(pubEcDsa);
                exportableJwk = JsonWebKeyConverter.ConvertFromECDsaSecurityKey(pubEcSecKey);
                privateKey    = ecSecKey;
                break;

            case SecurityAlgorithms.RsaSha256:
            case SecurityAlgorithms.RsaSha256Signature:
            case SecurityAlgorithms.RsaSha384:
            case SecurityAlgorithms.RsaSha384Signature:
            case SecurityAlgorithms.RsaSha512:
            case SecurityAlgorithms.RsaSha512Signature:
                RSA            rsa       = RSA.Create(GetRsaKeyLengthFromName(algorithmName));
                RsaSecurityKey rsaSecKey = new RsaSecurityKey(rsa);
                signingCreds = new SigningCredentials(rsaSecKey, algorithmName);
                RSA            pubRsa       = RSA.Create(rsa.ExportParameters(false));
                RsaSecurityKey pubRsaSecKey = new RsaSecurityKey(pubRsa);
                exportableJwk = JsonWebKeyConverter.ConvertFromRSASecurityKey(pubRsaSecKey);
                privateKey    = rsaSecKey;
                break;

            case SecurityAlgorithms.HmacSha256:
            case SecurityAlgorithms.HmacSha384:
            case SecurityAlgorithms.HmacSha512:
                HMAC hmac = HMAC.Create(GetHmacAlgorithmFromName(algorithmName));
                SymmetricSecurityKey hmacSecKey = new SymmetricSecurityKey(hmac.Key);
                signingCreds  = new SigningCredentials(hmacSecKey, algorithmName);
                exportableJwk = JsonWebKeyConverter.ConvertFromSymmetricSecurityKey(hmacSecKey);
                privateKey    = hmacSecKey;
                break;

            default:
                throw new ArgumentException($"Algorithm name '{algorithmName}' not supported", nameof(algorithmName));
            }

            JwtHeader               newHeader    = new JwtHeader(signingCreds, null, JwtConstants.HeaderType);
            JwtSecurityToken        newToken     = new JwtSecurityToken(newHeader, customPayload);
            JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();
            string resultToken = tokenHandler.WriteToken(newToken);

            JsonSerializerOptions serializerOptions = JsonSerializerOptionsFactory.Create(JsonSerializerOptionsFactory.JsonIgnoreCondition.WhenWritingNull);
            string publicKeyJson = JsonSerializer.Serialize(exportableJwk, serializerOptions);

            string publicKeyEncoded = Base64UrlEncoder.Encode(publicKeyJson);

            options.Authentication.MonitorApiKey.Subject   = subject;
            options.Authentication.MonitorApiKey.PublicKey = publicKeyEncoded;

            token = resultToken;

            return(options);
        }
예제 #18
0
 public static RootOptions UseApiKey(this RootOptions options, string algorithmName, string subject, JwtPayload customPayload, out string token)
 {
     return(options.UseApiKey(algorithmName, subject, customPayload, out token, out SecurityKey _));
 }
예제 #19
0
 private OptionsTreeNode[] TraverseRoot(RootOptions root)
 {
     List<OptionsTreeNode> children = new List<OptionsTreeNode>();
     foreach (PropertyInfo pi in typeof(RootOptions).GetProperties()) {
         object[] soAttribs = pi.GetCustomAttributes(typeof(SubOptionsAttribute), false);
         if (soAttribs.Length > 0) {
             SubOptionsAttribute soAttrib = soAttribs[0] as SubOptionsAttribute;
             OptionsTreeNode otn = this.TraverseChild(pi.GetValue(root, null), soAttrib.Name, soAttrib.Description);
             otn.ExpandAll();
             children.Add(otn);
         }
     }
     return children.ToArray();
 }
예제 #20
0
 public RootConnection(IOptions <RootOptions> options, ILogger <RootConnection> logger)
 {
     _logger  = logger;
     _options = options.Value;
 }
예제 #21
0
 public PagePingerService(ILogger <PagePingerService> logger,
                          IOptions <RootOptions> rootOptions)
 {
     _logger      = logger;
     _rootOptions = rootOptions.Value;
 }
예제 #22
0
 /// <summary>
 /// .ctor
 /// </summary>
 public HomeController(IOptions <SeoServicesOptions> seoServicesOption,
                       IOptions <RootOptions> rootOption)
 {
     _seoServicesOption = seoServicesOption.Value;
     _rootOption        = rootOption.Value;
 }
예제 #23
0
 private void InvokeError(RootOptions error)
 {
     HelpView.HelpNotParsed(error).Render();
 }