示例#1
0
        static void CreateVault(IAmazonGlacier glacier)
        {
            var req = new CreateVaultRequest
            {
                VaultName = VaultName
            };

            Task <CreateVaultResponse> res = glacier.CreateVaultAsync(req);

            Task.WaitAll(res);

            if (res.IsCompletedSuccessfully)
            {
                Console.WriteLine($"Successfully created vault {VaultName}");

                // if the user did not update the sample code with their account ID before
                // running, recover the ID from the vault location path as we need the ID
                // to construct the Amazon Resource Name (ARN) of the vault when setting
                // the access policy
                if (_accountId.Equals("-"))
                {
                    _accountId = res.Result.Location.Split('/', StringSplitOptions.RemoveEmptyEntries)[0];
                }
            }
        }
示例#2
0
        protected GlacierGatewayTestBase(bool testMode)
        {
            _logger          = Substitute.For <ILogger <GlacierGateway> >();
            _glacier         = Substitute.For <IAmazonGlacier>();
            _updater         = Substitute.For <IConsolePercentUpdater>();
            _archiveProvider = Substitute.For <IArchiveProvider>();

            // We need to initialize the MemoryStream with some data so that
            // the sanity checks don't fail
            var bytes = Enumerable.Range(0, 100).Select(a => (byte)a).ToArray();

            _archiveProvider.GetFileStream(Arg.Any <string>(), Arg.Any <string>()).Returns(new MemoryStream(bytes));

            _sut = new GlacierGateway(_glacier, _logger, _updater, _archiveProvider, null, testMode);

            _glacier.ListVaultsAsync(Arg.Any <ListVaultsRequest>())
            .Returns(new ListVaultsResponse
            {
                VaultList = new List <DescribeVaultOutput>
                {
                    new DescribeVaultOutput
                    {
                        VaultName = PreexistingVaultName
                    }
                }
            });
            _glacier.CreateVaultAsync(Arg.Any <CreateVaultRequest>())
            .Returns(new CreateVaultResponse
            {
                HttpStatusCode = HttpStatusCode.OK
            });
        }
示例#3
0
        public async Task AssertVaultExists(string vaultName)
        {
            vaultName = GetTrimmedVaultName(vaultName);

            var listResponse = await _glacier.ListVaultsAsync(new ListVaultsRequest
            {
                AccountId = _accountId
            });

            if (listResponse.VaultList.Any(a => a.VaultName.Equals(vaultName)))
            {
                return;
            }

            if (_testMode)
            {
                _logger.LogInformation("Would create vault {0}, but we're in test mode so I'm not", vaultName);
            }
            else
            {
                _logger.LogInformation("Creating vault {0}", vaultName);
                var result = await _glacier.CreateVaultAsync(new CreateVaultRequest
                {
                    AccountId = _accountId,
                    VaultName = vaultName
                });

                _logger.LogDebug("Vault creation result: {0}", result.HttpStatusCode);
            }
        }
示例#4
0
 private Amazon.Glacier.Model.CreateVaultResponse CallAWSServiceOperation(IAmazonGlacier client, Amazon.Glacier.Model.CreateVaultRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Glacier", "CreateVault");
     try
     {
         #if DESKTOP
         return(client.CreateVault(request));
         #elif CORECLR
         return(client.CreateVaultAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }