public void CreateContainers()
        {
            lock (_lock)
            {
                try
                {
                    // Develop any known required Containers, with rights as needed:
                    EnsureContainer(GetContainer(Constants.Storage.BlobStorageContainers.Public),
                                    BlobContainerPublicAccessType.Blob);
                    EnsureContainer(GetContainer(Constants.Storage.BlobStorageContainers.Private),
                                    BlobContainerPublicAccessType.Off);
                    EnsureContainer(GetContainer(Constants.Storage.BlobStorageContainers.Testing),
                                    BlobContainerPublicAccessType.Blob);
                }
                catch (System.Exception ex)

                {
                    _diagnosticsTracingService.Trace(TraceLevel.Error, ConnectionString); //dont do this normally but am really
                    _diagnosticsTracingService.Trace(TraceLevel.Error, ex.Message);
                    _diagnosticsTracingService.Trace(TraceLevel.Error, ex.StackTrace);
                    throw;
                }

                ContainersInitialized = true;
            }
        }
Example #2
0
 public AboutController(IDiagnosticsTracingService diagnosticsTracingService)
 {
     // Tip: Being a template, it is preferable that the HomeController/Default Route does not get injected with a
     // DbContext, as that implies a correct Connection string and/or Authentication, that may fail the first
     // time deployed to Azure.
     diagnosticsTracingService.Trace(TraceLevel.Verbose, "Hi");
 }
        private Principal GetOrCreatePrincipal(AuthenticationSuccessMessage authenticationSuccessMessage, TimeSpan?cacheTimeSpan = null)
        {
            var principalManagmentService = _principalManagmentService;//AppDependencyLocator.Current.GetInstance<PrincipalManagmentService>();
            var identity         = authenticationSuccessMessage.Identity;
            var idp              = identity.GetIdp();
            var sub              = identity.GetSub();
            var unqiueIdentifier = identity.GetSessionUniqueIdentifier();

            var principal = principalManagmentService.Get(idp, sub, unqiueIdentifier, cacheTimeSpan);

            // I am throttling this, whilst it possibly doesn't stop mutli env
            // it limits the exposure
            // there shouldn't be that many new user creates!
            // arguble not to throttle, going to er on side of caution
            if (principal == null)
            {
                try
                {
                    _mutex.Wait();
                    principal = principalManagmentService.CreateIfNotExists(idp, sub,
                                                                            authenticationSuccessMessage.UserId ?? identity.Name ?? "Service",
                                                                            unqiueIdentifier,
                                                                            cacheTimeSpan);
                }
                finally
                {
                    _mutex.Release();
                }
                _diagnosticsTracingService.Trace(TraceLevel.Info, $"new user created idp : {idp}, sub : {sub}");
            }
            return(principal);
        }
Example #4
0
        public async Task <DbConnection> CreateAsync(string connectionStringName)
        {
            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionStringName];

            _diagnosticsTracingService.Trace(TraceLevel.Info, "OpenDbConnectionBuilder.CreateAsync: {0}", connectionStringName);
            _diagnosticsTracingService.Trace(TraceLevel.Info, "OpenDbConnectionBuilder.CreateAsync: {0}", connectionStringSettings);

            var dbConnection = DbProviderFactories
                               .GetFactory(connectionStringSettings.ProviderName)
                               .CreateConnection();

            dbConnection.ConnectionString = connectionStringSettings.ConnectionString;


            await AttachAccessTokenToDbConnection(dbConnection);

            // Think DbContext will open it when first used.
            //await dbConnection.OpenAsync();

            return(dbConnection);
        }
        /// <summary>
        /// Retrieves the secret.
        /// </summary>
        /// <param name="secretKey">The secret key.</param>
        /// <param name="keyVaultUrl">The key vault URL.</param>
        /// <returns></returns>
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task <string> RetrieveSecretAsync(string secretKey, string keyVaultUrl = null)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            secretKey = CleanKeyName(secretKey);

            if (string.IsNullOrWhiteSpace(keyVaultUrl))
            {
                keyVaultUrl = _keyVaultUrl;
            }
            try
            {
                var secret = Task.Run(() => this.KeyVaultClient.GetSecretAsync(keyVaultUrl, secretKey)).Result;
                return(secret.Value);
            }
            catch (System.Exception e)
            {
                _diagnosticsTracingService.Trace(TraceLevel.Warn, $"KeyVault Secret '{secretKey}' not found. Reason given: '{e.Message}'");
                throw;
            }
        }
Example #6
0
        private void SeedByHand(AppCoreDbContext dbContext)
        {
            AttachDebuggerWhenRunningUnderPowershell();

            // Ensure sequence is DataClassification, Tenant, Principal, Role, Session, then Etc.
            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Exception Records. Start...");
            AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederExceptionRecord>().Seed(dbContext);
            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding End. Start...");

            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Data Classifications. Start...");
            AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederDataClassification>().Seed(dbContext);
            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Data Classifications. End.");

            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding System Roles. Start...");
            AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederSystemRole>().Seed(dbContext);
            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding System Roles. End.");

            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Tenants. Start...");
            SeedTenants(dbContext);
            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Tenants. End.");


            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Pricipals. Start...");
            SeedPrincipals(dbContext);
            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Principals. End.");


            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Sessions. Start...");
            AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederSession>().Seed(dbContext);
            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Sessions. End.");

            //After Tenant
            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Notifications. Start...");
            AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederNotification>().Seed(dbContext);
            _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Notifications. End.");
        }