public static void Run(AddClientCertArgs args, Func <ILogger> getLogger)
        {
            args.Validate();
            var settings = RunnerHelper.GetSettings(args.Configfile);
            var clientCertificateProvider = new ClientCertificateProvider(settings);

            var item = clientCertificateProvider.GetClientCertificate(args.PackageSource);

            if (item != null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          Strings.Error_ClientCertificateAlreadyExist,
                                                          args.PackageSource));
            }

            if (args.IsFileCertSettingsProvided())
            {
                item = new FileClientCertItem(args.PackageSource,
                                              args.Path,
                                              args.Password,
                                              args.StorePasswordInClearText,
                                              args.Configfile);
            }
            else if (args.IsStoreCertSettingsProvided())
            {
                item = new StoreClientCertItem(args.PackageSource,
                                               args.FindValue,
                                               args.GetStoreLocation(),
                                               args.GetStoreName(),
                                               args.GetFindBy());
            }
            else
            {
                throw new CommandLineArgumentCombinationException(string.Format(CultureInfo.CurrentCulture,
                                                                                Strings.Error_UnknownClientCertificateStoreType));
            }

            try
            {
                var certificates = item.Search();
                if (!certificates.Any())
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Error_ClientCertificatesNotFound));
                }
            }
            catch
            {
                if (!args.Force)
                {
                    throw;
                }
            }


            clientCertificateProvider.AddOrUpdate(item);

            getLogger().LogInformation(string.Format(CultureInfo.CurrentCulture, Strings.ClientCertificateSuccessfullyAdded, args.PackageSource));
        }
Exemple #2
0
        public static void Run(RemoveClientCertArgs args, Func <ILogger> getLogger)
        {
            args.Validate();

            var settings = RunnerHelper.GetSettings(args.Configfile);
            var clientCertificateProvider = new ClientCertificateProvider(settings);

            var item = clientCertificateProvider.GetClientCertificate(args.PackageSource);

            if (item == null)
            {
                getLogger().LogInformation(string.Format(CultureInfo.CurrentCulture,
                                                         Strings.NoClientCertificatesMatching,
                                                         args.PackageSource));
                return;
            }

            clientCertificateProvider.Remove(new[] { item });

            getLogger().LogInformation(string.Format(CultureInfo.CurrentCulture, Strings.ClientCertificateSuccessfullyRemoved, args.PackageSource));
        }
        public static void Run(UpdateClientCertArgs args, Func <ILogger> getLogger)
        {
            args.Validate();

            var settings = RunnerHelper.GetSettings(args.Configfile);
            var clientCertificateProvider = new ClientCertificateProvider(settings);

            var item = clientCertificateProvider.GetClientCertificate(args.PackageSource);

            if (item == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          Strings.Error_ClientCertificateNotExist,
                                                          args.PackageSource));
            }

            switch (item)
            {
            case FileClientCertItem fileCertItem:
                if (args.IsStoreCertSettingsProvided())
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                              Strings.Error_ClientCertificateTypeMismatch,
                                                              args.PackageSource));
                }

                fileCertItem.Update(args.Path, args.Password, args.StorePasswordInClearText);
                break;

            case StoreClientCertItem storeCertItem:
                if (args.IsFileCertSettingsProvided())
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                              Strings.Error_ClientCertificateTypeMismatch,
                                                              args.PackageSource));
                }

                storeCertItem.Update(args.FindValue,
                                     args.GetStoreLocation(),
                                     args.GetStoreName(),
                                     args.GetFindBy());
                break;
            }

            try
            {
                var certificates = item.Search();
                if (!certificates.Any())
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Error_ClientCertificatesNotFound));
                }
            }
            catch
            {
                if (!args.Force)
                {
                    throw;
                }
            }

            clientCertificateProvider.AddOrUpdate(item);

            getLogger().LogInformation(string.Format(CultureInfo.CurrentCulture, Strings.ClientCertificateSuccessfullyUpdated, args.PackageSource));
        }