Пример #1
0
        /// <summary>
        /// Initialization routine
        /// </summary>
        /// <param name="action">action</param>
        /// <returns>initialization task</returns>
        private async Task Initialize(Action action)
        {
            // load the environment configuration file from UtilsInternal
            var sr                    = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + environmentName + ".config");
            var certThumbprint        = sr.ReadValue(SocialPlusCertThumbprint);
            var clientID              = sr.ReadValue(EmbeddedSocialClientIdSetting);
            var storeLocation         = StoreLocation.CurrentUser;
            var vaultUrl              = sr.ReadValue(SocialPlusVaultUrlSetting);
            ICertificateHelper cert   = new CertificateHelper(certThumbprint, clientID, storeLocation);
            IKeyVaultClient    client = new AzureKeyVaultClient(cert);

            var log      = new Log(LogDestination.Console, Log.DefaultCategoryName);
            var kv       = new KV(log, clientID, vaultUrl, certThumbprint, storeLocation, client);
            var kvReader = new KVSettingsReader(sr, kv);

            IConnectionStringProvider connectionStringProvider = new ConnectionStringProvider(kvReader);
            int          queueBatchIntervalMs = int.Parse(sr.ReadValue(ServiceBusBatchIntervalMsSetting));
            QueueManager queueManager         = new QueueManager(connectionStringProvider, queueBatchIntervalMs);
            var          sbConnect            = await connectionStringProvider.GetServiceBusConnectionString(ServiceBusInstanceType.Default);

            // the ListQueues action requires an instance of a ServiceBus object
            if (action == Action.ListQueues)
            {
                this.sb = new ServiceBus(sbConnect);
            }

            // all the remaining actions operate on an instance of a ServiceBusQueue object
            if (action != Action.ListQueues)
            {
                // ParseArgs() ensures that queueName is valid here
                this.sbQueue = await ServiceBusQueue.Create(sbConnect, queueName, queueBatchIntervalMs);

                this.selectedQueue = await queueManager.GetQueue((QueueIdentifier)selectedQueueId);
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes static members of the <see cref="KVTests"/> class.
        /// </summary>
        static KVTests()
        {
            FileSettingsReader = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + TestConstants.ConfigFileName);
            SigningKey         = FileSettingsReader.ReadValue(BearerTokenSigningKey);
            ClientId           = FileSettingsReader.ReadValue(EmbeddedSocialClientIdSetting);
            VaultUrl           = FileSettingsReader.ReadValue(SocialPlusVaultUrlSetting);
            CertThumbprint     = FileSettingsReader.ReadValue(SocialPlusCertThumbprint);
            StoreLoc           = StoreLocation.CurrentUser;
            var cert = new CertificateHelper(CertThumbprint, ClientId, StoreLoc);

            Client  = new AzureKeyVaultClient(cert);
            TestLog = new Log(LogDestination.Debug, Log.DefaultCategoryName);
        }
Пример #3
0
        /// <summary>
        /// Generate a list of IKV instances for unit tests
        /// </summary>
        /// <returns>List of IKV instances</returns>
        public IEnumerable <IKV> CreateKV()
        {
            var fileSettingsReader = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + TestConstants.ConfigFileName);
            var clientId           = fileSettingsReader.ReadValue(EmbeddedSocialClientIdSetting);
            var vaultUrl           = fileSettingsReader.ReadValue(SocialPlusVaultUrlSetting);
            var certThumbprint     = fileSettingsReader.ReadValue(SocialPlusCertThumbprint);
            var storeLoc           = StoreLocation.CurrentUser;
            var log = new Log(LogDestination.Debug, Log.DefaultCategoryName);

            foreach (IKeyVaultClient ikvc in this.azureKeyVaultClientFactory.CreateKVClient())
            {
                yield return(new KV(log, clientId, vaultUrl, certThumbprint, storeLoc, ikvc));
            }
        }
        /// <summary>
        /// Retrieves SendGrid key from KV
        /// </summary>
        /// <param name="configFile">config file path</param>
        /// <returns>SendGrid key</returns>
        public static string GetSendGridKey(string configFile)
        {
            var sr                    = new FileSettingsReader(configFile);
            var certThumbprint        = sr.ReadValue(TestConstants.SocialPlusCertThumbprint);
            var clientID              = sr.ReadValue(TestConstants.EmbeddedSocialClientIdSetting);
            var storeLocation         = StoreLocation.CurrentUser;
            var vaultUrl              = sr.ReadValue(TestConstants.SocialPlusVaultUrlSetting);
            ICertificateHelper cert   = new CertificateHelper(certThumbprint, clientID, storeLocation);
            IKeyVaultClient    client = new AzureKeyVaultClient(cert);

            var log      = new Log(LogDestination.Console, Log.DefaultCategoryName);
            var kv       = new KV(log, clientID, vaultUrl, certThumbprint, storeLocation, client);
            var kvReader = new KVSettingsReader(sr, kv);

            return(kvReader.ReadValueAsync("SendGridInstrumentationKey").Result);
        }
Пример #5
0
        /// <summary>
        /// Returns a URL to access an image on the CDN
        /// </summary>
        /// <param name="blobHandle">unique handle to the image</param>
        /// <returns>URL to get the image</returns>
        private static Uri FormImageUriOnCDN(string blobHandle)
        {
            var sr     = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + TestConstants.ConfigFileName);
            var cdnUrl = sr.ReadValue("CDNUrl");

            return(new Uri(cdnUrl + "images/" + blobHandle));
        }
        /// <summary>
        /// Initializes static members of the <see cref="TestConstants"/> class.
        /// </summary>
        static TestConstants()
        {
#if OBA_DEV_ALEC
            string environmentName = "oba-dev-alec";
            ConfigFileName = environmentName + ".config";
#endif
#if OBA_DEV_SHARAD
            string environmentName = "oba-dev-sharad";
            ConfigFileName = environmentName + ".config";
#endif
#if OBA_PPE
            string environmentName = "oba-ppe";
            ConfigFileName = environmentName + ".config";
#endif
#if OBA_PROD
            string environmentName = "oba-prod";
            ConfigFileName = environmentName + ".config";
#endif

            // use the fsr to read values that are not secrets
            var fsr = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + ConfigFileName);

            EmbeddedSocialAdminUserHandle = fsr.ReadValue("EmbeddedSocialAdminUserHandle");
            EmbeddedSocialAppKey          = fsr.ReadValue("EmbeddedSocialAppKey");
            EmbeddedSocialUri             = new Uri(fsr.ReadValue("EmbeddedSocialUri"));

            AADOBAAppId    = fsr.ReadValue("AADOBAAppId");
            AADOBAHomePage = fsr.ReadValue("AADOBAHomePage");
            AADTenantId    = fsr.ReadValue("AADTenantId");

            KeyVaultUri       = fsr.ReadValue("KeyVaultUri");
            OBACertThumbprint = fsr.ReadValue("OBACertThumbprint");
            OBARegionsListUri = fsr.ReadValue("OBARegionsListUri");

            // use the kvr to read secrets
            ICertificateHelper cert     = new CertificateHelper(OBACertThumbprint, AADOBAAppId, StoreLocation.CurrentUser);
            IKeyVaultClient    kvClient = new AzureKeyVaultClient(cert);
            var log = new Log(LogDestination.Debug, Log.DefaultCategoryName);
            var kv  = new KV(log, AADOBAAppId, KeyVaultUri, OBACertThumbprint, StoreLocation.CurrentUser, kvClient);
            var kvr = new KVSettingsReader(fsr, kv);

            AzureStorageConnectionString = kvr.ReadValueAsync("AzureStorageConnectionString").Result;
            OBAApiKey                  = kvr.ReadValueAsync("OBAApiKey").Result;
            SendGridEmailAddr          = kvr.ReadValueAsync("SendGridEmailAddr").Result;
            SendGridKey                = kvr.ReadValueAsync("SendGridKey").Result;
            ServiceBusConnectionString = kvr.ReadValueAsync("ServiceBusConnectionString").Result;

            // Obtain an AAD token using a cert from the local store for the current user
            AADSettings       aadSettings = new AADSettings(TestConstants.AADTenantId, TestConstants.AADOBAAppId, TestConstants.AADOBAHomePage, TestConstants.OBACertThumbprint);
            CertificateHelper certHelper  = new CertificateHelper(TestConstants.OBACertThumbprint, TestConstants.AADOBAAppId, StoreLocation.CurrentUser);
            EmbeddedSocialAADToken = certHelper.GetAccessToken(aadSettings.Authority, aadSettings.AppUri).Result;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureKeyVaultClientFactory"/> class.
        /// Creates a whole bunch of mocked Azure key vault clients
        /// </summary>
        public AzureKeyVaultClientFactory()
        {
            var fileSettingsReader = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + TestConstants.ConfigFileName);
            var clientId           = fileSettingsReader.ReadValue(EmbeddedSocialClientIdSetting);
            var certThumbprint     = fileSettingsReader.ReadValue(SocialPlusCertThumbprint);
            var storeLocation      = StoreLocation.CurrentUser;
            var cert = new CertificateHelper(certThumbprint, clientId, storeLocation);

            Mock <AzureKeyVaultClient> mock1 = new Mock <AzureKeyVaultClient>(cert);

            mock1.CallBase = true;
            mock1.Setup(c => c.GetKeyAsync(It.IsNotNull <string>(), It.IsAny <CancellationToken>())).ThrowsAsync(new ArgumentNullException());

            Mock <AzureKeyVaultClient> mock2 = new Mock <AzureKeyVaultClient>(cert);

            mock2.CallBase = true;
            mock2.Setup(c => c.GetSecretAsync(It.IsNotNull <string>(), It.IsAny <CancellationToken>())).ThrowsAsync(new ArgumentNullException());

            Mock <AzureKeyVaultClient> mock3 = new Mock <AzureKeyVaultClient>(cert);

            mock3.CallBase = true;
            mock3.Setup(c => c.SignAsync(It.IsNotNull <string>(), It.IsNotNull <string>(), It.IsNotNull <string>(), It.IsNotNull <string>(), It.IsNotNull <byte[]>(), It.IsNotNull <CancellationToken>()));

            Mock <AzureKeyVaultClient> mock4 = new Mock <AzureKeyVaultClient>(cert);

            mock4.CallBase = true;

            this.methodToExceptionList[typeof(AzureKeyVaultClient).GetMethod("GetKeyAsync")] = new List <Exception> {
                new ArgumentNullException()
            };
            this.methodToExceptionList[typeof(AzureKeyVaultClient).GetMethod("GetSecretAsync")] = new List <Exception> {
                new ArgumentNullException()
            };
            this.methodToExceptionList[typeof(AzureKeyVaultClient).GetMethod("SignAsync")] = new List <Exception> {
                new ArgumentNullException()
            };

            this.listOfAzureKeyVaultClients.Add(this.MakeBlankMock(cert));
            foreach (Mock <AzureKeyVaultClient> mock in this.MakeMocks(cert))
            {
                this.listOfAzureKeyVaultClients.Add(mock);
            }
        }
Пример #8
0
        /// <summary>
        /// Initialization routine
        /// </summary>
        /// <returns>init task</returns>
        private async Task Initialize()
        {
            // load the environment configuration file from UtilsInternal
            var sr                    = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + environmentName + ".config");
            var certThumbprint        = sr.ReadValue(SocialPlusCertThumbprint);
            var clientID              = sr.ReadValue(EmbeddedSocialClientIdSetting);
            var storeLocation         = StoreLocation.CurrentUser;
            var vaultUrl              = sr.ReadValue(SocialPlusVaultUrlSetting);
            ICertificateHelper cert   = new CertificateHelper(certThumbprint, clientID, storeLocation);
            IKeyVaultClient    client = new AzureKeyVaultClient(cert);

            var log      = new Log(LogDestination.Console, Log.DefaultCategoryName);
            var kv       = new KV(log, clientID, vaultUrl, certThumbprint, storeLocation, client);
            var kvReader = new KVSettingsReader(sr, kv);
            IConnectionStringProvider connectionStringProvider = new ConnectionStringProvider(kvReader);

            cvsUrl = await connectionStringProvider.GetCVSUrl(CVSInstanceType.Default);

            cvsSubscriptionKey = await connectionStringProvider.GetCVSKey(CVSInstanceType.Default);
        }
        /// <summary>
        /// Initializes the store instance for a specific environment name
        /// </summary>
        /// <param name="environmentName">name of environment</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        protected async Task Init(string environmentName)
        {
            var sr                    = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + environmentName + ".config");
            var certThumbprint        = sr.ReadValue(SocialPlusCertThumbprint);
            var clientID              = sr.ReadValue(EmbeddedSocialClientIdSetting);
            var vaultUrl              = sr.ReadValue(SocialPlusVaultUrlSetting);
            var storeLocation         = StoreLocation.CurrentUser;
            ICertificateHelper cert   = new CertificateHelper(certThumbprint, clientID, storeLocation);
            IKeyVaultClient    client = new AzureKeyVaultClient(cert);

            var log      = new Log(LogDestination.Console, Log.DefaultCategoryName);
            IKV kv       = new KV(log, clientID, vaultUrl, certThumbprint, storeLocation, client);
            var kvReader = new KVSettingsReader(sr, kv);

            ConnectionStringProvider csp             = new ConnectionStringProvider(kvReader);
            string azureTableStorageConnectionString = await kvReader.ReadValueAsync("AzureStorageConnectionString");

            // Retrieve the storage account from the connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azureTableStorageConnectionString);

            // Create the table client.
            this.tableClient = storageAccount.CreateCloudTableClient();
        }
Пример #10
0
        /// <summary>
        /// Async version of the Main program
        /// </summary>
        /// <param name="args">command line args</param>
        /// <returns>a task</returns>
        public static async Task AsyncMain(string[] args)
        {
            ParseArgs(args);

            var sr                    = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + environmentName + ".config");
            var certThumbprint        = sr.ReadValue(OBACertThumbprint);
            var clientID              = sr.ReadValue(OBAClientId);
            var storeLocation         = StoreLocation.CurrentUser;
            var vaultUrl              = sr.ReadValue(OBAVaultUrl);
            ICertificateHelper cert   = new CertificateHelper(certThumbprint, clientID, storeLocation);
            IKeyVaultClient    client = new AzureKeyVaultClient(cert);
            var log                   = new Log(LogDestination.Debug, Log.DefaultCategoryName);

            kv = new KV(log, clientID, vaultUrl, certThumbprint, storeLocation, client);
            var kvReader = new KVSettingsReader(sr, kv);

            if (doClean)
            {
                DisplayWarning();
            }

            // display current configuration
            await ValidateAndPrintConfiguration(environmentName, kvReader);

            if (forceOperation == false)
            {
                // get user approval
                Console.Write("Are you sure you want to proceed? [y/n] : ");
                ConsoleKeyInfo keyInfo = Console.ReadKey(false);
                if (keyInfo.KeyChar != 'y')
                {
                    return;
                }

                Console.WriteLine();
            }

            if (doAll || doTables)
            {
                string azureTableStorageConnectionString = await kvReader.ReadValueAsync("AzureStorageConnectionString");

                if (doClean)
                {
                    // Delete tables
                    await Tables.Clean(azureTableStorageConnectionString);
                }

                if (doCreate)
                {
                    // Create tables
                    await Tables.Create(azureTableStorageConnectionString);
                }
            }

            if (doAll || doQueues)
            {
                if (doClean)
                {
                    // Delete queues
                    await Queues.Clean();
                }

                if (doCreate)
                {
                    // Create queues
                    await Queues.Create();
                }
            }

            if (doAll || doLogs)
            {
                string azureDiagnosticsConnectionString = await kvReader.ReadValueAsync("AzureStorageConnectionString");

                if (doClean)
                {
                    // Delete logs
                    await Logs.Clean(azureDiagnosticsConnectionString);
                }

                if (doCreate)
                {
                    // Create queues
                    await Logs.Create();
                }
            }

            Console.WriteLine("All done! Bye!");
        }
Пример #11
0
        /// <summary>
        /// Async version of the Main program
        /// </summary>
        /// <param name="args">command line args</param>
        /// <returns>a task</returns>
        public static async Task AsyncMain(string[] args)
        {
            ParseArgs(args);

            var sr                    = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + environmentName + ".config");
            var certThumbprint        = sr.ReadValue(SocialPlusCertThumbprint);
            var clientID              = sr.ReadValue(EmbeddedSocialClientIdSetting);
            var storeLocation         = StoreLocation.CurrentUser;
            var vaultUrl              = sr.ReadValue(SocialPlusVaultUrlSetting);
            ICertificateHelper cert   = new CertificateHelper(certThumbprint, clientID, storeLocation);
            IKeyVaultClient    client = new AzureKeyVaultClient(cert);

            log = new Log(LogDestination.Console, Log.DefaultCategoryName);
            kv  = new KV(log, clientID, vaultUrl, certThumbprint, storeLocation, client);
            var kvReader = new KVSettingsReader(sr, kv);

            RedisCache redisCache = null;

            if (redisType == RedisType.Volatile)
            {
                var volatileRedis = await kvReader.ReadValueAsync("VolatileRedisConnectionString");

                if (action == "get-info")
                {
                    volatileRedis += ", allowAdmin=1";
                }

                redisCache = new RedisCache(volatileRedis);
            }
            else if (redisType == RedisType.Persistent)
            {
                var persistentRedis = await kvReader.ReadValueAsync("PersistentRedisConnectionString");

                if (action == "get-info")
                {
                    persistentRedis += ", allowAdmin=1";
                }

                redisCache = new RedisCache(persistentRedis);
            }

            // note that the get-info command does not use a container or a table
            if (action == "get-info")
            {
                var actions = new Actions(redisCache, null, null);
                await actions.GetInfo();

                return;
            }

            var container = LookupContainer(containerName);
            var table     = LookupTable(tableName, container);

            if (container != null && table != null)
            {
                var actions = new Actions(redisCache, container, table);
                if (action == "get")
                {
                    await actions.GetObject(partitionKey, objKey);
                }
                else if (action == "get-rank-feed")
                {
                    await actions.GetRankFeed(partitionKey, feedKey, rankFeedOrder);
                }
                else if (action == "delete")
                {
                    await actions.DeleteObject(partitionKey, objKey);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Initialization routine
        /// </summary>
        private void Initialize()
        {
            // load the environment configuration file from UtilsInternal
            var sr                    = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + environmentName + ".config");
            var certThumbprint        = sr.ReadValue(SocialPlusCertThumbprint);
            var clientID              = sr.ReadValue(EmbeddedSocialClientIdSetting);
            var storeLocation         = StoreLocation.CurrentUser;
            var vaultUrl              = sr.ReadValue(SocialPlusVaultUrlSetting);
            ICertificateHelper cert   = new CertificateHelper(certThumbprint, clientID, storeLocation);
            IKeyVaultClient    client = new AzureKeyVaultClient(cert);

            var log      = new Log(LogDestination.Console, Log.DefaultCategoryName);
            var kv       = new KV(log, clientID, vaultUrl, certThumbprint, storeLocation, client);
            var kvReader = new KVSettingsReader(sr, kv);
            IConnectionStringProvider connectionStringProvider = new ConnectionStringProvider(kvReader);
            int queueBatchIntervalMs = int.Parse(sr.ReadValue(ServiceBusBatchIntervalMsSetting));

            // Lots of things need to be created to create an appsManager.
            ICTStoreManager tableStoreManager = new CTStoreManager(connectionStringProvider);
            bool            tableInit         = false;
            Exception       exception         = null;

            try
            {
                // use Task.Run to ensure that the async Initialize routine runs on a threadpool thread
                Task <bool> task = Task <bool> .Run(() => tableStoreManager.Initialize());

                // task.Result blocks until the result is ready
                tableInit = task.Result;
            }
            catch (Exception e)
            {
                exception = e;
            }

            if (tableInit == false)
            {
                string errorMessage = "CTstore version number does not match the expected version number." + Environment.NewLine +
                                      "If your tables are empty, then you probably forgot to provision storage." + Environment.NewLine +
                                      "If not, then you need to convert the data format and update the storage version number.";
                Console.WriteLine(errorMessage);
                if (exception != null)
                {
                    Console.WriteLine("Exception message:" + exception.Message);
                }

                Environment.Exit(0);
            }

            ICBStoreManager blobStoreManager = new CBStoreManager(connectionStringProvider);
            AppsStore       appsStore        = new AppsStore(tableStoreManager);
            UsersStore      usersStore       = new UsersStore(tableStoreManager);
            ViewsManager    viewsManager     = new ViewsManager(
                log,
                appsStore,
                usersStore,
                new UserRelationshipsStore(tableStoreManager),
                new TopicsStore(tableStoreManager),
                new TopicRelationshipsStore(tableStoreManager),
                new CommentsStore(tableStoreManager),
                new RepliesStore(tableStoreManager),
                new LikesStore(tableStoreManager),
                new PinsStore(tableStoreManager),
                new BlobsStore(blobStoreManager));
            PushNotificationsManager pushManager = new PushNotificationsManager(log, new PushRegistrationsStore(tableStoreManager), appsStore, viewsManager, connectionStringProvider);

            this.appsManager = new AppsManager(appsStore, pushManager);
            SearchManager       searchManager       = new SearchManager(log, connectionStringProvider);
            PopularUsersManager popularUsersManager = new PopularUsersManager(usersStore);
            QueueManager        queueManager        = new QueueManager(connectionStringProvider, queueBatchIntervalMs);
            SearchQueue         searchQueue         = new SearchQueue(queueManager);

            this.usersManager = new UsersManager(usersStore, pushManager, popularUsersManager, searchQueue);
        }
Пример #13
0
        /// <summary>
        /// Async version of the Main program
        /// </summary>
        /// <param name="args">command line args</param>
        /// <returns>a task</returns>
        public static async Task AsyncMain(string[] args)
        {
            ParseArgs(args);

            var sr                    = new FileSettingsReader(ConfigurationManager.AppSettings["ConfigRelativePath"] + Path.DirectorySeparatorChar + environmentName + ".config");
            var certThumbprint        = sr.ReadValue(SocialPlusCertThumbprint);
            var clientID              = sr.ReadValue(EmbeddedSocialClientIdSetting);
            var storeLocation         = StoreLocation.CurrentUser;
            var vaultUrl              = sr.ReadValue(SocialPlusVaultUrlSetting);
            ICertificateHelper cert   = new CertificateHelper(certThumbprint, clientID, storeLocation);
            IKeyVaultClient    client = new AzureKeyVaultClient(cert);

            log = new Log(LogDestination.Console, Log.DefaultCategoryName);
            kv  = new KV(log, clientID, vaultUrl, certThumbprint, storeLocation, client);
            var kvReader = new KVSettingsReader(sr, kv);

            // Create a null connection string provider needed for blobStoreManager and tableStoreManager
            NullConnectionStringProvider connectionStringProvider = new NullConnectionStringProvider();

            if (doUpgradeStoreVersion)
            {
                if (!forceOperation)
                {
                    Console.WriteLine("You must specify the -Force option when using -UpgradeStoreVersion");
                    Console.WriteLine("The -UpgradeStoreVersion option is only intended to be used by our version upgrade scripts");
                    Console.WriteLine("If you are trying to use this by hand, you're probably doing something wrong.");
                    return;
                }

                CTStoreManager tableStoreManager = new CTStoreManager(connectionStringProvider);
                string         redisPersistentConnectionString = await kvReader.ReadValueAsync("PersistentRedisConnectionString");

                string azureTableStorageConnectionString = await kvReader.ReadValueAsync("AzureStorageConnectionString");
                await UpgradeStoreVersion(tableStoreManager, azureTableStorageConnectionString, redisPersistentConnectionString);

                return;
            }

            if (doClean)
            {
                DisplayWarning();
            }

            // display current configuration
            await ValidateAndPrintConfiguration(environmentName, kvReader);

            if (forceOperation == false)
            {
                // get user approval
                Console.Write("Are you sure you want to proceed? [y/n] : ");
                ConsoleKeyInfo keyInfo = Console.ReadKey(false);
                if (keyInfo.KeyChar != 'y')
                {
                    return;
                }
            }

            // Mr Clean!!
            Console.WriteLine();
            Console.WriteLine();

            if (doAll || doSearch)
            {
                string searchServiceName = await kvReader.ReadValueAsync("SearchServiceName");

                string searchServiceAdminKey = await kvReader.ReadValueAsync("SearchServiceAdminKey");

                if (doClean)
                {
                    // delete search indices
                    await DeleteSearch(searchServiceName, searchServiceAdminKey);
                }

                if (doCreate)
                {
                    // create search indices
                    await ProvisionSearch(searchServiceName, searchServiceAdminKey);
                }
            }

            if (doAll || doQueues)
            {
                string serviceBusConnectionString = await kvReader.ReadValueAsync("ServiceBusConnectionString");

                if (doClean)
                {
                    // Delete queues
                    await DeleteServiceBusQueues(serviceBusConnectionString);
                }

                if (doCreate)
                {
                    // Create queues
                    await ProvisionServiceBusQueues(serviceBusConnectionString);
                }
            }

            if (doAll || doTables)
            {
                CTStoreManager tableStoreManager = new CTStoreManager(connectionStringProvider);
                string         azureTableStorageConnectionString = await kvReader.ReadValueAsync("AzureStorageConnectionString");

                if (doClean)
                {
                    // Delete tables
                    await DeleteAzureTables(azureTableStorageConnectionString);
                }

                if (doCreate)
                {
                    await ProvisionAzureStorageTables(tableStoreManager, azureTableStorageConnectionString);
                }
            }

            if (doAll || doBlobs)
            {
                CBStoreManager blobStoreManager = new CBStoreManager(connectionStringProvider);
                string         azureBlobStorageConnectionString = await kvReader.ReadValueAsync("AzureBlobStorageConnectionString");

                if (doClean)
                {
                    // Delete blobs
                    await DeleteAzureBlobs(blobStoreManager, azureBlobStorageConnectionString);
                }

                if (doCreate)
                {
                    await ProvisionAzureStorageBlobs(blobStoreManager, azureBlobStorageConnectionString);
                }
            }

            if (doAll || doRedis)
            {
                if (doClean)
                {
                    // Delete redis cache
                    string redisVolatileConnectionString = await kvReader.ReadValueAsync("VolatileRedisConnectionString") + ", allowAdmin=1";

                    string redisPersistentConnectionString = await kvReader.ReadValueAsync("PersistentRedisConnectionString") + ", allowAdmin=1";

                    DeleteRedisCaches(redisVolatileConnectionString, redisPersistentConnectionString);
                }

                if (doCreate)
                {
                    string redisPersistentConnectionString = await kvReader.ReadValueAsync("PersistentRedisConnectionString");

                    CTStoreManager tableStoreManager = new CTStoreManager(connectionStringProvider);
                    await ProvisionRedisCaches(redisPersistentConnectionString, tableStoreManager);
                }
            }

            if (doAll || doLogs)
            {
                CBStoreManager blobStoreManager = new CBStoreManager(connectionStringProvider);
                string         azureBlobStorageConnectionString = await kvReader.ReadValueAsync("AzureBlobStorageConnectionString");

                if (doClean)
                {
                    // Delete logs
                    await DeleteAzureLogs(azureBlobStorageConnectionString);
                }

                if (doCreate)
                {
                    // No need to create the Azure logs (aka WAD* tables). Azure Diagnostics creates them automatically.
                }
            }

            // bye
            Console.WriteLine();
            Console.WriteLine("All done! Bye!");
            Console.WriteLine();
        }
Пример #14
0
 public async Task KVHashWrongKey()
 {
     string hashingKey = FileSettingsReader.ReadValue(HashingKeyId);
     await AssertUtils.AssertThrowsExceptionAsync <KeyVaultClientException>(async() => { await this.kv.HashAsync(hashingKey.Remove(hashingKey.Length - 1), Rand.GenerateRandomBytes(1024)); });
 }