Example #1
0
        static async Task Main(string[] args)
        {
            //Gremlin playground
            //PeopleService ps = new PeopleService(DevConnectionString.GremlinEnpointUrl, DevConnectionString.GremlinPrimaryKey); ;
            //await GremlinUtils.InsertAllPeople();

            //Mongo playground

            //MongoUtils.ConfigureCaseInsensitiveIndex();

            //var items = MongoUtils.QueryAzureServices();
            //var items = MongoUtils.QueryCaseInsensitve("sql server registries");
            //PrintItems(items);

            //MongoUtils.MonitorChanges();

            //MongoUtils.InsertAllAzureServices();

            //CreateBson();

            //ModernSQLUtils.InsertAllAzureServices();

            await KeyvaultSecrets.GetAKVSecretsUsingCert();

            Console.WriteLine("Done press return to exit");
            Console.ReadLine();
        }
        public void Load()
        {
            //we need to fulfil a synchronous contract with an async implementation
            //hence we need to wait on the calling thread for the async op to complete
            using (AutoResetEvent ar = new AutoResetEvent(false))
            {
                Exception fail = null;
                //TODO handle the error continuation
                switch (_useLocalCert)
                {
                case AuthMethod.LocalCert:
                    KeyvaultSecrets.GetAKVSecretsUsingCert(_keyvaultbase).ContinueWith((a) =>
                    {
                        result = a.Result;
                        ar.Set();
                    }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion);

                    KeyvaultSecrets.GetAKVSecretsUsingCert(_keyvaultbase).ContinueWith((a) =>
                    {
                        fail = a.Exception.InnerException != null ? a.Exception.InnerException : a.Exception;
                        ar.Set();
                    }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted);
                    break;

                case AuthMethod.Secret:
                    KeyvaultSecrets.GetAKVSecretsUsingSecret(_secret, _appclientid, _keyvaultbase).ContinueWith((a) =>
                    {
                        result = a.Result;
                        ar.Set();
                    }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion);

                    KeyvaultSecrets.GetAKVSecretsUsingSecret(_secret, _appclientid, _keyvaultbase).ContinueWith((a) =>
                    {
                        fail = a.Exception.InnerException != null ? a.Exception.InnerException : a.Exception;
                        ar.Set();
                    }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted);
                    break;

                case AuthMethod.MSI:
                    KeyvaultSecrets.GetAKVSecretsUsingMSI(_keyvaultbase).ContinueWith((a) =>
                    {
                        result = a.Result;
                        ar.Set();
                    }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion);

                    KeyvaultSecrets.GetAKVSecretsUsingMSI(_keyvaultbase).ContinueWith((a) =>
                    {
                        fail = a.Exception.InnerException != null ? a.Exception.InnerException : a.Exception;
                        ar.Set();
                    }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted);
                    break;
                }
                bool signaled = ar.WaitOne(10000); //TODO constant
                if (fail != null)
                {
                    throw fail;
                }
                if (!signaled)
                {
                    throw new Exception("Config load timeout exceeded");
                }
            }
        }