public async Task UploadConfiguration(string contents, string destinationPath)
        {
            if (_s3Client == null)
            {
                _s3Client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1);
            }

            var cts = new CancellationTokenSource();

            cts.CancelAfter(s3UploadTimeoutMs);

            PutObjectRequest request = new PutObjectRequest()
            {
                BucketName  = UploadBucket,
                Key         = destinationPath,
                ContentBody = contents
            };

            try {
                Output.Verbose($"Writing object to {request.Key}");
                PutObjectResponse result = await _s3Client.PutObjectAsync(request, cts.Token);

                if (result.HttpStatusCode != System.Net.HttpStatusCode.OK)
                {
                    throw new System.Exception($"Unable to upload config file to s3 {result.ToString()}");
                }
                Output.Success($"Service Configuraiton written to {request.Key}");
            } catch (System.Exception ex)
            {
                throw new System.Exception("Unable to upload config file to s3", ex);
            }
        }
Пример #2
0
        public void Register(CommandLineApplication app, string currentDirectory, CommandOption verboseOption)
        {
            app.Command(CommandName, command =>
            {
                command.Description = Description;

                AddHelpOption(command);
                CreateOptions(command);
                var commandVerboseOption = AddVerboseOption(command);

                command.OnExecute(() =>
                {
                    // Allow `-v` to be added before or after the subcommand, i.e., `dotnet marvel -v build` or `dotnet marvel build -v`
                    Output.UseVerbose = verboseOption.HasValue() || commandVerboseOption.HasValue();

                    var config = new MarvelMicroserviceConfig(currentDirectory);
                    Output.Info($"Running `dotnet {Program.CliCommandName} {CommandName}`...");
                    Output.Verbose("Using verbose logging");
                    Output.Info($"Using solution at {config.BaseDirectory}");

                    TrySetTestAuthentication();
                    var task = Task.Run(async() => await Run(config));
                    var code = task.GetAwaiter().GetResult();

                    if (code == 0)
                    {
                        Output.Success("Success.");
                    }
                    else
                    {
                        Output.Error("Failed.");
                    }
                    return(code);
                });
            });
        }