示例#1
0
        public override int Invoke(IEnumerable <string> arguments)
        {
            Options.Parse(arguments);

            config = FileActions.OpenFileFrom(ConfigFilename);
            if (config == null)
            {
                logger.Error($"Did not find or cold not access the file \"{ConfigFilename}\".");
                return(0);
            }

            // We assume there is a property in at the root of the json that is called public key and holds our public key for writing values.
            publicKey = FindPublicKey(config);
            if (publicKey == null)
            {
                logger.Error($"Did not find a public key in {ConfigFilename}. Make sure we can find it in the root with the key publicKey");
                return(0);
            }

            if (KeysToExclude != null)
            {
                logger.Info($"Excluding the following keys from encryption: {String.Join(", ", KeysToExclude)}");
            }

            using (new Stopwatch("Encrypting configs"))
            {
                encrypt = new Encrypt {
                    PublicKey = publicKey
                };
                Walker.Action = EncryptIf;
                Walker.FindStringValueByKeys(config.Keys.ToList(), config);
            }

            FileActions.SaveFileTo(ConfigFilename, config);

            return(1);
        }