Esempio n. 1
0
        private void PushLogToS3(string key, string log)
        {
            if (string.IsNullOrEmpty(Settings.ResultsBucket))
            {
                return;
            }

            try
            {
                WriteInfo("Pushing log to S3...");
                using (var s3 = new Amazon.S3.AmazonS3Client(Credentials, RegionEndpoint))
                {
                    s3.PutObjectAsync(new PutObjectRequest
                    {
                        BucketName  = Settings.ResultsBucket,
                        Key         = key,
                        ContentBody = log
                    }).Wait();
                }
            }
            catch (Exception e)
            {
                WriteError("Error pushing logs to S3: {0}", e);
            }
        }
        public async Task <String> SaveFileToAws(FileDto file)
        {
            var keyId     = _configuration.GetSection("AWS").GetValue <String>("AWSAccessKeyId");
            var keySecret = _configuration.GetSection("AWS").GetValue <String>("AWSSecretAccessKey");

            var config = new Amazon.S3.AmazonS3Config();

            config.RegionEndpoint = Amazon.RegionEndpoint.EUWest3;

            var client = new Amazon.S3.AmazonS3Client(keyId, keySecret, config);

            var fileName = $"users-uploads/{Guid.NewGuid().ToString()}-{file.FileName}";

            var request = new Amazon.S3.Model.PutObjectRequest
            {
                BucketName   = "teller-uploads",
                ContentType  = file.ContentType,
                InputStream  = file.ReadStream,
                Key          = fileName,
                StorageClass = Amazon.S3.S3StorageClass.Standard,
                CannedACL    = Amazon.S3.S3CannedACL.PublicRead,
            };

            var response = await client.PutObjectAsync(request);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                return("https://teller-uploads.s3.amazonaws.com/" + fileName);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        private async void View_SendLogOutput(object sender, EventArgs e)
        {
            View.Sending = true;
            try
            {
                var logId = DateTime.UtcNow.ToString("dd MMMM yyyy hh:mm:ss", CultureInfo.InvariantCulture);

                var file = Path.Combine(Resources.GameUserDir, "minidump.dmp");
                if (FileSystem.Current.FileExists(file))
                {
                    var transfer      = new TransferUtility(_game.SupportS3BucketAccessKey, _game.SupportS3BucketSecretKey, Amazon.RegionEndpoint.USEast1);
                    var uploadRequest = new TransferUtilityUploadRequest();
                    uploadRequest.FilePath   = file;
                    uploadRequest.BucketName = _game.SupportS3Bucket;
                    uploadRequest.Key        = logId + "/minidump.dmp";
                    await transfer.UploadAsync(uploadRequest);
                }

                var client     = new Amazon.S3.AmazonS3Client(_game.SupportS3BucketAccessKey, _game.SupportS3BucketSecretKey, Amazon.RegionEndpoint.USEast1);
                var putRequest = new PutObjectRequest();
                putRequest.ContentBody = SubmitCoreErrorPresenter.GetLogContent(_game, _detail);
                putRequest.BucketName  = _game.SupportS3Bucket;
                putRequest.Key         = logId + "/log.txt";
                await client.PutObjectAsync(putRequest);
            }
            catch (Exception ex)
            {
                Message.Show("Failed to send error report");
                Logger.Current.Write(ex, "Failed to send error report");
            }
            View.Sending = false;
            CloseView();
        }
Esempio n. 4
0
 public async Task UpsertFileAsync(string filePath)
 {
     var key = PathRelativeToSourceDirectory(filePath);
     await _s3Client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest {
         Key        = key,
         BucketName = _bucketName
     }).ConfigureAwait(false);
 }
Esempio n. 5
0
        public static void PutObject(string Key, Stream InputStream)
        {
            Amazon.S3.AmazonS3Client s3Client = new Amazon.S3.AmazonS3Client(Amazon.RegionEndpoint.GetBySystemName(S3Region));

            var result = s3Client.PutObjectAsync(new PutObjectRequest {
                InputStream = InputStream, BucketName = S3BucketName, Key = Key
            }).GetAwaiter().GetResult();

            if (result.HttpStatusCode != HttpStatusCode.OK)
            {
                throw new Exception($"Error putting object to S3: {result.HttpStatusCode.ToString()}");
            }
        }
 /// <summary>
 /// Upload content to S3 bucket
 /// </summary>
 /// <param name="content">Content.</param>
 /// <param name="bucket">Bucket.</param>
 /// <param name="key">Key.</param>
 private void uploadContent(String content, String bucket, String key)
 {
     using (var s3client = new Amazon.S3.AmazonS3Client())
     {
         var uploadPromise = s3client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest
         {
             BucketName  = bucket,
             Key         = key,
             ContentBody = content
         });
         uploadPromise.Wait();
         context.Logger.LogLine($"Uploaded s3://{bucket}/{key} ETAG {uploadPromise.Result.ETag}");
     }
 }
Esempio n. 7
0
        public override async Task <string> HandleEvent(
            APIGatewayProxyRequest request,
            ILambdaContext context,
            string deliveryId,
            BaseEvent eventPayload)
        {
            var client           = new Amazon.S3.AmazonS3Client();
            var putObjectRequest = new Amazon.S3.Model.PutObjectRequest
            {
                BucketName  = bucketName,
                Key         = deliveryId,
                ContentBody = request.Body
            };

            await client.PutObjectAsync(putObjectRequest);

            return($"Event payload uploaded to {bucketName}/{deliveryId}");
        }
Esempio n. 8
0
        private void PushLogToS3(string key, string log)
        {
            if (string.IsNullOrEmpty(Settings.ResultsBucket))
                return;

            try
            {
                WriteInfo("Pushing log to S3...");
                using (var s3 = new Amazon.S3.AmazonS3Client(Credentials, RegionEndpoint))
                {
                    s3.PutObjectAsync(new PutObjectRequest
                    {
                        BucketName = Settings.ResultsBucket,
                        Key = key,
                        ContentBody = log
                    }).Wait();
                }
            }
            catch(Exception e)
            {
                WriteError("Error pushing logs to S3: {0}", e);
            }
        }
Esempio n. 9
0
        public static async Task Main(string[] args)
        {
            // Archive/Upload the latest code
            var gitStartInfo = new System.Diagnostics.ProcessStartInfo
            {
                WorkingDirectory       = System.Environment.CurrentDirectory,
                FileName               = "git.exe",
                RedirectStandardOutput = true,
                CreateNoWindow         = true
            };

            gitStartInfo.Arguments = "rev-parse --show-toplevel";
            var gitRoot = System.Diagnostics.Process.Start(gitStartInfo);

            gitRoot.WaitForExit();
            var rootFolder = System.IO.Path.GetFullPath(gitRoot.StandardOutput.ReadToEnd().Trim());

            // Archive/Upload the latest code
            gitStartInfo.WorkingDirectory = rootFolder;
            gitStartInfo.Arguments        = "rev-parse HEAD";
            var gitHash = System.Diagnostics.Process.Start(gitStartInfo);

            gitHash.WaitForExit();
            var hash            = gitHash.StandardOutput.ReadToEnd().Trim();
            var archiveFilename = System.Environment.ExpandEnvironmentVariables($"%Temp%\\ASPNETExample-{hash.Substring(0,6)}.zip");

            gitStartInfo.Arguments = $"archive {hash} -o \"{archiveFilename}\"";
            var gitArchive = System.Diagnostics.Process.Start(gitStartInfo);

            gitArchive.WaitForExit();
            if (!System.IO.File.Exists(archiveFilename) || new System.IO.FileInfo(archiveFilename).Length == 0)
            {
                throw new InvalidOperationException($"Empty archive! See {archiveFilename} for details.");
            }
            try
            {
                CICD.SourceBucketKey = $"samples/{System.IO.Path.GetFileName(archiveFilename)}";
                var s3Client = new Amazon.S3.AmazonS3Client();
                await s3Client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest {
                    BucketName = CICD.SourceBucketName,
                    Key        = CICD.SourceBucketKey,
                    FilePath   = archiveFilename
                });
            }
            finally
            {
                if (System.IO.File.Exists(archiveFilename))
                {
                    System.IO.File.Delete(archiveFilename);
                }
            }

            if (string.IsNullOrEmpty(CICD.SourceBucketKey))
            {
                throw new InvalidOperationException("Missing key for source code!");
            }

            var app = new App();

            new CdkStack(app, "DotNetDemo");
            app.Synth();
        }