예제 #1
0
        /// <summary>
        /// Implements the <see cref="ProcessRecord"/> method for <see cref="SetTransmissionCredentialsCmdlet"/>.
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                var config = new TransmissionCredentials
                {
                    Host     = Host,
                    User     = User,
                    Password = Password
                };

                TransmissionContext.Credentials = config;

                if (StorePermanent.IsPresent)
                {
                    Task.Run(async() => await AuthService.SetConfig(config));
                }
            }
            catch (Exception e)
            {
                ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to set credentials with error: {e.Message}", e), null, ErrorCategory.OperationStopped, null));
            }
        }
예제 #2
0
        /// <summary>
        /// Create a local config file in the module directory with encrypted auth credentials.
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static async Task SetConfig(TransmissionCredentials config)
        {
            var encrypted = await EncryptionService.Encrypt(JsonConvert.SerializeObject(config));

            await File.WriteAllTextAsync(ConfigFile, encrypted);
        }
예제 #3
0
 /// <summary>
 /// Set credentials to null
 /// </summary>
 public static void Dispose()
 {
     Credentials = null;
 }