/// <summary> /// .ctor /// </summary> public SiteMapBuilder(IOptions <RootOptions> rootOptions, IOurGardenRepository context) { _rootOptions = rootOptions.Value; _context = (context as OurGardenRepository).Context; _publicDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); }
public void OptionNames() { var s = new RootOptions(); var names = s.GetOptionNames(); Assert.AreEqual(propertyNames.Count, names.Count); }
public static CollectionRuleOptions CreateCollectionRule(this RootOptions rootOptions, string name) { CollectionRuleOptions options = new(); rootOptions.CollectionRules.Add(name, options); return(options); }
/// <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)); }
public static RootOptions SetDumpTempFolder(this RootOptions options, string directoryPath) { if (null == options.Storage) { options.Storage = new StorageOptions(); } options.Storage.DumpTempFolder = directoryPath; return(options); }
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 }
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); }
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()); }
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); }
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); }
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()); }
/// <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; }
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); }
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); }
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(); } } }
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(); } } }
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); }
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 _)); }
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(); }
public RootConnection(IOptions <RootOptions> options, ILogger <RootConnection> logger) { _logger = logger; _options = options.Value; }
public PagePingerService(ILogger <PagePingerService> logger, IOptions <RootOptions> rootOptions) { _logger = logger; _rootOptions = rootOptions.Value; }
/// <summary> /// .ctor /// </summary> public HomeController(IOptions <SeoServicesOptions> seoServicesOption, IOptions <RootOptions> rootOption) { _seoServicesOption = seoServicesOption.Value; _rootOption = rootOption.Value; }
private void InvokeError(RootOptions error) { HelpView.HelpNotParsed(error).Render(); }