private static void Run(CommandLineApplication cmd, ILogger log) { cmd.Description = "Create a new sleet.json config file."; var awss3 = cmd.Option("--s3", "Add a template entry for an Amazon S3 storage feed.", CommandOptionType.NoValue); var azure = cmd.Option("--azure", "Add a template entry for an azure storage feed.", CommandOptionType.NoValue); var folder = cmd.Option("--local", "Add a template entry for a local folder feed.", CommandOptionType.NoValue); var output = cmd.Option("--output", "Output path. If not specified the file will be created in the working directory.", CommandOptionType.SingleValue); var verbose = cmd.Option(Constants.VerboseOption, Constants.VerboseDesc, CommandOptionType.NoValue); cmd.HelpOption(Constants.HelpOption); cmd.OnExecute(async() => { // Init logger Util.SetVerbosity(log, verbose.HasValue()); var outputPath = output.HasValue() ? output.Value() : null; FileSystemStorageType storageType = awss3.HasValue() ? FileSystemStorageType.AmazonS3 : azure.HasValue() ? FileSystemStorageType.Azure : folder.HasValue() ? FileSystemStorageType.Local : FileSystemStorageType.Unspecified; var success = await CreateConfigCommand.RunAsync(storageType, outputPath, log); return(success ? 0 : 1); }); }
public static async Task <bool> RunAsync(FileSystemStorageType storageType, string output, ILogger log) { var outputPath = Directory.GetCurrentDirectory(); if (!string.IsNullOrEmpty(output)) { outputPath = output; } outputPath = Path.GetFullPath(outputPath); if (Directory.Exists(outputPath)) { outputPath = Path.Combine(outputPath, "sleet.json"); } if (File.Exists(outputPath)) { log.LogError($"File already exists {outputPath}"); return(false); } if (!Directory.Exists(Path.GetDirectoryName(outputPath))) { log.LogError($"Directory does not exist {Path.GetDirectoryName(outputPath)}"); return(false); } // Create the config template var json = new JObject { { "username", "" }, { "useremail", "" } }; var sourcesArray = new JArray(); json.Add("sources", sourcesArray); JObject storageTemplateJson = null; switch (storageType) { case FileSystemStorageType.Local: storageTemplateJson = new JObject { { "name", "myLocalFeed" }, { "type", "local" }, { "path", Path.Combine(Directory.GetCurrentDirectory(), "myFeed") }, { "baseURI", "https://example.com/feed/" } }; break; case FileSystemStorageType.Azure: storageTemplateJson = new JObject { { "name", "myAzureFeed" }, { "type", "azure" }, { "container", "myFeed" }, { "connectionString", AzureFileSystem.AzureEmptyConnectionString } }; break; case FileSystemStorageType.AmazonS3: storageTemplateJson = new JObject { { "name", "myAmazonS3Feed" }, { "type", "s3" }, { "bucketName", "bucketname" }, { "region", "us-east-1" }, { "profileName", "credentialsFileProfileName" } }; log.Log(LogLevel.Minimal, "AWS credentials can be specified directly in sleet.json using accessKeyId and secretAccessKey instead of profileName. By default sleet.json is set to use a credentials file profile. To configure keys see: https://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/net-dg-config-creds.html#creds-file"); break; case FileSystemStorageType.Unspecified: storageTemplateJson = new JObject { { "name", "myFeed" }, { "type", "" } }; break; } if (storageTemplateJson != null) { sourcesArray.Add(storageTemplateJson); } await log.LogAsync(LogLevel.Minimal, $"Writing config template to {outputPath}"); File.WriteAllText(outputPath, json.ToString()); await log.LogAsync(LogLevel.Minimal, "Modify this template by changing the name and path for your own feed."); return(true); }
public static async Task <bool> RunAsync(FileSystemStorageType storageType, string output, ILogger log) { var outputPath = Directory.GetCurrentDirectory(); if (!string.IsNullOrEmpty(output)) { outputPath = output; } outputPath = Path.GetFullPath(outputPath); if (Directory.Exists(outputPath)) { outputPath = Path.Combine(outputPath, "sleet.json"); } if (File.Exists(outputPath)) { log.LogError($"File already exists {outputPath}"); return(false); } if (!Directory.Exists(Path.GetDirectoryName(outputPath))) { log.LogError($"Directory does not exist {Path.GetDirectoryName(outputPath)}"); return(false); } // Create the config template var json = new JObject { { "username", "" }, { "useremail", "" } }; var sourcesArray = new JArray(); json.Add("sources", sourcesArray); JObject storageTemplateJson = null; switch (storageType) { case FileSystemStorageType.Local: storageTemplateJson = new JObject { { "name", "myLocalFeed" }, { "type", "local" }, { "path", Path.Combine(Directory.GetCurrentDirectory(), "myFeed") }, { "baseURI", "https://example.com/feed/" } }; break; case FileSystemStorageType.Azure: storageTemplateJson = new JObject { { "name", "myAzureFeed" }, { "type", "azure" }, { "container", "myFeed" }, { "connectionString", AzureFileSystem.AzureEmptyConnectionString } }; break; case FileSystemStorageType.AmazonS3: storageTemplateJson = new JObject { { "name", "myAmazonS3Feed" }, { "type", "s3" }, { "bucketName", "bucketname" }, { "region", "us-east-1" }, { "accessKeyId", "" }, { "secretAccessKey", "" } }; break; } if (storageTemplateJson != null) { sourcesArray.Add(storageTemplateJson); } await log.LogAsync(LogLevel.Minimal, $"Writing config template to {outputPath}"); File.WriteAllText(outputPath, json.ToString()); await log.LogAsync(LogLevel.Minimal, "Modify this template by changing the name and path for your own feed."); return(true); }