Esempio n. 1
0
        private CommandLineApplication SetupDecryptCommand(CommandLineApplication app, CommandOption keyDirOption, string name)
        {
            return(app.Command(name, context =>
            {
                context.Out = _standardOut;
                context.Error = _standardError;
                context.Description = "decrypt an EJSON file";
                context.HelpOption("--help");

                var fileNameArgument = context.Argument("<file>", "name of the file to decrypt");

                var outputToFileOption = context.Option("-o", "print output to the provided file, rather than stdout", CommandOptionType.SingleValue);

                context.OnExecute(() =>
                {
                    var keyDir = keyDirOption.Value();

                    if (outputToFileOption.HasValue())
                    {
                        var output = _eJsonCrypto.SaveDecryptedJsonFromFile(fileNameArgument.Value, outputToFileOption.Value(), keyDir);
                        context.Out.WriteLine(output);
                    }
                    else
                    {
                        var json = _eJsonCrypto.GetDecryptedJsonFromFile(fileNameArgument.Value, keyDir);
                        context.Out.WriteLine(json);
                    }

                    return 0;
                });
            }));
        }
Esempio n. 2
0
 public void Load(string filename, bool optional = false, bool overwriteAppSettings = true, bool overwriteConnectionStrings = true)
 {
     if (File.Exists(filename))
     {
         var keyProvider = GetKeyProvider();
         var json        = _ejsonCrypto.GetDecryptedJsonFromFile(filename, keyProvider);
         var dictionary  = new JavaScriptSerializer().DeserializeObject(json)  as Dictionary <string, object>;
         _configurationLoader.Load(dictionary, true, true);
     }
     else
     {
         if (!optional)
         {
             throw new FileNotFoundException("cannot find ejson", filename);
         }
     }
 }