コード例 #1
0
ファイル: Program.cs プロジェクト: ktairov/YellowDrawer
        static void Main(string[] args)
        {
            var encryptionProvider = new AesStorageEncryptionProvider("cuwRX6tRedZGFlAG2vOBytIS4iaWOv8D");

            var cloudStorageAccount = CloudStorageAccount.Parse(connectionStringAzure);
            var azureProvider       = new AzureBlobStorageProvider(cloudStorageAccount);

            var fileSystemProvider = new FileSystemStorageProvider("C://");
            var amazonClient       = new AmazonS3Client(awsAccessKey, awsSecretKey, Amazon.RegionEndpoint.USEast1);
            var amazonProvider     = new AmazonStorageProvider(amazonClient, amazonBaseUrl, awsBucketName);

            var           client        = new MongoClient(mongoConnectionString);
            var           server        = client.GetDatabase(mongoDataBase);
            IGridFSBucket _bucket       = new GridFSBucket(server);
            var           mongoProvider = new GridFSStorageProvider(_bucket);

            var iv = encryptionProvider.GenerateIV();

            TestWriteEncryptionProvider(azureProvider, encryptionProvider, iv);
            TestReadEncryptionProvider(azureProvider, encryptionProvider, iv);

            TestProvider(azureProvider, "Azure");
            TestProvider(amazonProvider, "Amazon");
            TestProvider(mongoProvider, "Mongo");


            Console.ReadLine();
        }
コード例 #2
0
 // Constructor
 public AzureFileSystem(string containerName)
 {
     // Set container name (if none specified, specify the development container default)
     // All letters in a container name must be lowercase
     _containerName = !string.IsNullOrEmpty(containerName) ? containerName.ToLowerInvariant() : "DevelopmentContainer";
     _provider      = new AzureBlobStorageProvider(_containerName);
 }
コード例 #3
0
 protected override void OnInit()
 {
     CloudStorageAccount.TryParse("UseDevelopmentStorage=true", out _devAccount);
     _platformConfigurationAccessor = new DefaultPlatformConfigurationAccessor();
     _azureBlobStorageProvider      = new AzureBlobStorageProvider(new ShellSettings {
         Name = "default"
     }, new ConfigurationMimeTypeProvider(), _platformConfigurationAccessor);
 }
コード例 #4
0
        protected override void OnInit()
        {
            CloudStorageAccount.TryParse("UseDevelopmentStorage=true", out _devAccount);

            _azureBlobStorageProvider = new AzureBlobStorageProvider(new ShellSettings {
                Name = "default"
            }, _devAccount);
        }
コード例 #5
0
        protected override void OnInit()
        {
            CloudStorageAccount.TryParse("UseDevelopmentStorage=true", out _devAccount);

            _azureBlobStorageProvider = new AzureBlobStorageProvider(new ShellSettings {
                Name = "default"
            }, new ConfigurationMimeTypeProvider(new DefaultCacheManager(typeof(ConfigurationMimeTypeProvider), new DefaultCacheHolder(new DefaultCacheContextAccessor()))));
        }
コード例 #6
0
        // Constructor
        public AzureFileSystem(String userName, String password, String containerName, Modes mode)
        {
            _userName = userName;
            _password = password;

            // Set container name (if none specified, specify the development container default)
            _containerName = !String.IsNullOrEmpty(containerName) ? containerName : "DevelopmentContainer";
            _provider      = new AzureBlobStorageProvider(containerName);
        }
コード例 #7
0
        private static async Task CheckDomainsForValidCertificateAsync(ILogger log, CancellationToken cancellationToken,
                                                                       ExecutionContext executionContext)
        {
            // internal storage (used for letsencrypt account metadata)
            IStorageProvider storageProvider = new AzureBlobStorageProvider(Environment.GetEnvironmentVariable("AzureWebJobsStorage"), "letsencrypt");

            IConfigurationProcessor processor = new ConfigurationProcessor();
            var configurations = await AutoRenewal.LoadConfigFilesAsync(storageProvider, processor, log, cancellationToken, executionContext);

            IAuthenticationService authenticationService = new AuthenticationService(storageProvider);
            var az = new AzureHelper();

            var tokenProvider  = new AzureServiceTokenProvider();
            var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(tokenProvider.KeyVaultTokenCallback));
            var storageFactory = new StorageFactory(az);

            var renewalOptionsParser = new RenewalOptionParser(az, keyVaultClient, storageFactory, log);
            var certificateBuilder   = new CertificateBuilder();

            IRenewalService renewalService = new RenewalService(authenticationService, renewalOptionsParser, certificateBuilder, log);
            var             errors         = new List <Exception>();
            var             httpClient     = new HttpClient();

            foreach ((var name, var config) in configurations)
            {
                using (log.BeginScope($"Checking certificates from {name}"))
                {
                    foreach (var cert in config.Certificates)
                    {
                        var hostNames = string.Join(";", cert.HostNames);
                        try
                        {
                            // check each domain to verify HTTPS certificate is valid
                            var request = WebRequest.CreateHttp($"https://{cert.HostNames.First()}");
                            request.ServerCertificateValidationCallback += ValidateTestServerCertificate;
                            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { }
                        }
                        catch (Exception e)
                        {
                            log.LogError(e, $"Certificate check failed for: {hostNames}!");
                            errors.Add(e);
                            continue;
                        }
                        log.LogInformation($"Certificate for {hostNames} looks valid");
                    }
                }
            }
            if (!configurations.Any())
            {
                log.LogWarning("No configurations where processed, refere to the sample on how to set up configs!");
            }
            if (errors.Any())
            {
                throw new AggregateException("Failed to process all certificates", errors);
            }
        }
コード例 #8
0
        public void Put_Media_Into_Storage()
        {
            // Arrange
            var azStorageProvider = new AzureBlobStorageProvider(ConnString, ContainerName);
            var fileStream        = File.OpenRead(MediaFilePath);
            var mediaId           = GetMediaId();

            mediaList.Add(mediaId);

            // Act
            azStorageProvider.Put(fileStream, mediaId);

            // Assert
            Assert.AreEqual(mediaId, azStorageProvider.GetBlobReference(mediaId)?.Name);
        }
コード例 #9
0
        private static async Task <Configuration[]> LoadConfigFilesAsync(AzureBlobStorageProvider storageProvider, CancellationToken cancellationToken)
        {
            var files = await storageProvider.ListAsync("", cancellationToken);

            var configs = new List <Configuration>();

            foreach (var file in files)
            {
                if (!file.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                configs.Add(ParseConfiguration(await storageProvider.GetAsync(file, cancellationToken)));
            }
            return(configs.ToArray());
        }
コード例 #10
0
        static async Task Main(string[] args)
        {
            try
            {
                var provider = new AzureBlobStorageProvider(
                    TestSettings.Instance.AzureStorageName,
                    TestSettings.Instance.AzureStorageKey,
                    "$logs",
                    false);

                var monitor = new AzureBlobMonitor(provider);

                await monitor.DoWork();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.ReadLine();
        }
コード例 #11
0
        public static async Task ScanRepositoriesAsync(
            [TimerTrigger(Schedule.Every5Minutes, RunOnStartup = true)] TimerInfo timer,
            ILogger log,
            CancellationToken cancellationToken)
        {
            var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage") ?? throw new ArgumentNullException("Storage connection string not set");
            var storageProvider  = new AzureBlobStorageProvider(connectionString, "configuration");

            var configurations = await LoadConfigFilesAsync(storageProvider, cancellationToken);

            var configParser = new ConfigurationParser(log);

            foreach (var cfg in configurations)
            {
                var automation    = new MirrorAutomationLogic(log);
                var source        = configParser.GetRepositorySource(cfg.Source);
                var mirrorService = configParser.GetMirrorService(cfg.MirrorViaConfig, source);
                var targets       = configParser.GetRepositoryTargets(cfg.TargetConfig);
                log.LogInformation($"Processing source {source.SourceId} (to be replicated to {Join(", ", " and ", targets.Select(t => t.TargetId))})");
                await automation.ProcessAsync(source, mirrorService, targets, cancellationToken);
            }
        }
コード例 #12
0
        public static Task <string> ConvertToMP3(string originUrl)
        {
            ProcessStartInfo psi = new ProcessStartInfo();

            psi.FileName = System.Web.HttpContext.Current.Server.MapPath(exe_path);

            string filename = Path.GetFileNameWithoutExtension(originUrl);
            string mp3_path = System.Web.HttpContext.Current.Server.MapPath("~/mp3/") + filename + ".mp3";

            psi.Arguments              = string.Format(@"-i ""{0}"" -y ""{1}""", originUrl, mp3_path);
            psi.CreateNoWindow         = true;
            psi.ErrorDialog            = false;
            psi.UseShellExecute        = false;
            psi.WindowStyle            = ProcessWindowStyle.Hidden;
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardInput  = false;
            psi.RedirectStandardError  = true;
            Process exeProcess = Process.Start(psi);

            exeProcess.PriorityClass = ProcessPriorityClass.High;
            string outString = string.Empty;

            exeProcess.OutputDataReceived += (s, e) =>
            {
                outString += e.Data;
            };
            exeProcess.BeginOutputReadLine();
            string errString = exeProcess.StandardError.ReadToEnd();

            exeProcess.WaitForExit();

            var stream = File.OpenRead(mp3_path);

            AzureBlobStorageProvider provider = new AzureBlobStorageProvider("mp3");
            var url = provider.Save(stream, ".mp3");

            return(url);
        }
コード例 #13
0
 public AzureFileInfo(AzureCloudFile file, AzureBlobStorageProvider provider)
 {
     _file     = file;
     _provider = provider;
 }
コード例 #14
0
        private static async Task RenewAsync(Overrides overrides, ILogger log, CancellationToken cancellationToken,
                                             ExecutionContext executionContext)
        {
            // internal storage (used for letsencrypt account metadata)
            IStorageProvider storageProvider = new AzureBlobStorageProvider(Environment.GetEnvironmentVariable("AzureWebJobsStorage"), "letsencrypt");

            IConfigurationProcessor processor = new ConfigurationProcessor();
            var configurations = await LoadConfigFilesAsync(storageProvider, processor, log, cancellationToken, executionContext);

            IAuthenticationService authenticationService = new AuthenticationService(storageProvider);
            var az = new AzureHelper();

            var tokenProvider  = new AzureServiceTokenProvider();
            var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(tokenProvider.KeyVaultTokenCallback));
            var storageFactory = new StorageFactory(az);

            var renewalOptionsParser = new RenewalOptionParser(az, keyVaultClient, storageFactory, log);
            var certificateBuilder   = new CertificateBuilder();

            IRenewalService renewalService = new RenewalService(authenticationService, renewalOptionsParser, certificateBuilder, log);
            var             stopwatch      = new Stopwatch();
            // TODO: with lots of certificate renewals this could run into function timeout (10mins)
            // with 30 days to expiry (default setting) this isn't a big problem as next day all finished certs are skipped
            // user will only get email <= 14 days before expiry so acceptable for now
            var errors = new List <Exception>();

            foreach ((var name, var config) in configurations)
            {
                using (log.BeginScope($"Working on certificates from {name}"))
                {
                    foreach (var cert in config.Certificates)
                    {
                        stopwatch.Restart();
                        var hostNames = string.Join(";", cert.HostNames);
                        cert.Overrides = overrides ?? Overrides.None;
                        try
                        {
                            var result = await renewalService.RenewCertificateAsync(config.Acme, cert, cancellationToken);

                            switch (result)
                            {
                            case RenewalResult.NoChange:
                                log.LogInformation($"Certificate renewal skipped for: {hostNames} (no change required yet)");
                                break;

                            case RenewalResult.Success:
                                log.LogInformation($"Certificate renewal succeeded for: {hostNames}");
                                break;

                            default:
                                throw new ArgumentOutOfRangeException(result.ToString());
                            }
                        }
                        catch (Exception e)
                        {
                            log.LogError(e, $"Certificate renewal failed for: {hostNames}!");
                            errors.Add(e);
                        }
                        log.LogInformation($"Renewing certificates for {hostNames} took: {stopwatch.Elapsed}");
                    }
                }
            }
            if (!configurations.Any())
            {
                log.LogWarning("No configurations where processed, refere to the sample on how to set up configs!");
            }
            if (errors.Any())
            {
                throw new AggregateException("Failed to process all certificates", errors);
            }
        }
コード例 #15
0
ファイル: AzureFileSystem.cs プロジェクト: reebonz/FTP2Azure
 // Constructor
 public AzureFileSystem(string containerName)
 {
     // Set container name (if none specified, specify the development container default)
     _containerName = !string.IsNullOrEmpty(containerName) ? containerName : "DevelopmentContainer";
     _provider      = new AzureBlobStorageProvider(_containerName);
 }
コード例 #16
0
 public UploadController(AzureBlobStorageProvider azureBlobStorageProvider)
 {
     _azureBlobStorageProvider = azureBlobStorageProvider;
 }
コード例 #17
0
 public WishListController()
 {
     db = new WishlistEntities();
     db.Database.CommandTimeout = 60 * 1;
     blobProvider = new AzureBlobStorageProvider(ConfigurationManager.AppSettings["AzureBlobStorage"]);;
 }