Exemplo n.º 1
0
 public HomeController(ILogger <HomeController> logger, ILoggerFactory loggerFactory, IOptionsSnapshot <CredHubOptions> credHubOptions)
 {
     _logger        = logger;
     _loggerFactory = loggerFactory;
     if (_credHub == null && Request?.Path.Value.Contains("Injected") != true)
     {
         // if a username and password were supplied, use that auth method, otherwise expect Diego to provide credentials on PCF
         try
         {
             if (!string.IsNullOrEmpty(credHubOptions.Value.CredHubUser) && !string.IsNullOrEmpty(credHubOptions.Value.CredHubPassword))
             {
                 _logger?.LogTrace("Getting CredHub UAA Client...");
                 _credHub = CredHubClient.CreateUAAClientAsync(credHubOptions.Value, _loggerFactory.CreateLogger <CredHubClient>()).Result;
             }
             else
             {
                 _logger?.LogTrace("Getting CredHub mTLS Client...");
                 _credHub = CredHubClient.CreateMTLSClientAsync(credHubOptions.Value, _loggerFactory.CreateLogger <CredHubClient>()).Result;
             }
         }
         catch (Exception e)
         {
             _logger?.LogCritical(e, "Failed to initialize CredHubClient");
             throw new Exception($"Failed initializing CredHubClient: {e}");
         }
     }
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Injected([FromServices] ICredHubClient credHub)
        {
            var newPassword = await credHub.GenerateAsync <PasswordCredential>(new PasswordGenerationRequest("generated-password", new PasswordGenerationParameters {
                Length = 20
            }, null, OverwiteMode.overwrite));

            ViewBag.Deleted = await credHub.DeleteByNameAsync("generated-password");

            return(View(newPassword));
        }
Exemplo n.º 3
0
 public HomeController(ILogger <HomeController> logger, ILoggerFactory loggerFactory, IOptionsSnapshot <CredHubOptions> credHubOptions)
 {
     _logger        = logger;
     _loggerFactory = loggerFactory;
     if (_credHub == null && Request?.Path.Value.Contains("Injected") != true)
     {
         try
         {
             _logger?.LogTrace("Getting CredHub UAA Client...");
             _credHub = CredHubClient.CreateUAAClientAsync(credHubOptions.Value, _loggerFactory.CreateLogger <CredHubClient>()).Result;
         }
         catch (Exception e)
         {
             _logger?.LogCritical(e, "Failed to initialize CredHubClient");
             throw new Exception($"Failed initializing CredHubClient: {e}");
         }
     }
 }
Exemplo n.º 4
0
 public HomeController(ILogger <HomeController> logger, ILoggerFactory loggerFactory, ICredHubClient credHubClient)
 {
     _logger  = logger;
     _credHub = credHubClient;
 }