示例#1
0
        public JarFinder(IPandoraGitSettings gitSettings, IPandoraContext context)
        {
            _gitSettings = gitSettings;
            _context     = context;
            var cloneOptions = new LibGit2Sharp.CloneOptions
            {
                IsBare              = false,
                Checkout            = true,
                CredentialsProvider = new LibGit2Sharp.Handlers.CredentialsHandler((a, b, c) => new LibGit2Sharp.UsernamePasswordCredentials()
                {
                    Username = gitSettings.Username,
                    Password = gitSettings.Password
                })
            };

            try
            {
                _checkoutDir = LibGit2Sharp.Repository.Clone(gitSettings.SourceUrl, gitSettings.WorkingDir, cloneOptions);
            }
            catch (LibGit2Sharp.LibGit2SharpException ex)
            {
                Exception error = new Exception("Unable to checkout repository. Please check the credentials", ex);
                throw error;
            }
        }
 public static IEnumerable <DeployedSetting> GetAll(IPandoraContext applicationContext)
 {
     return(from setting in GetRepository().GetAll()
            where setting.Key.Cluster == applicationContext.Cluster &&
            setting.Key.Machine == applicationContext.Machine &&
            setting.Key.ApplicationName == applicationContext.ApplicationName
            select setting);
 }
示例#3
0
        public GitConfigurationRepo(IPandoraContext context, Configuration pandoraConfiguration)
        {
            if (pandoraConfiguration is null)
            {
                throw new ArgumentNullException(nameof(pandoraConfiguration));
            }

            this.context = context;
            _cfg         = pandoraConfiguration;
        }
示例#4
0
        public IEnumerable <DeployedSetting> GetAll(IPandoraContext context)
        {
            string pandoraApplication = context.ToApplicationKeyPrefix();

            Console.WriteLine($"Refreshing {pandoraApplication} configuration from Consul - {Thread.CurrentThread.ManagedThreadId}");

            IEnumerable <ReadKeyValueResponse> response = _client.ReadAllKeyValuesAsync(pandoraApplication).GetAwaiter().GetResult();

            List <DeployedSetting> newSettings = response
                                                 .Select(x => new DeployedSetting(x.Key.FromConsulKey(), Encoding.UTF8.GetString(Convert.FromBase64String(x.Value))))
                                                 .ToList();

            Console.WriteLine($"Refreshing {pandoraApplication} configuration from Consul completed - {Thread.CurrentThread.ManagedThreadId}");

            return(newSettings);
        }
示例#5
0
        /// <summary>
        /// Clones the repository needed and then loads the needed configurations in the Pandora object
        /// </summary>
        /// <param name="applicationName">The name of the file with jars in it</param>
        /// <param name="gitSettings">The general git settings needed to clone</param>
        /// <param name="options">Options to get environment specific configurations</param>
        public PandoraGitFactory(IPandoraContext context, IPandoraGitSettings gitSettings)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (gitSettings is null)
            {
                throw new ArgumentNullException(nameof(gitSettings));
            }

            _context     = context;
            _gitSettings = gitSettings;

            Refresh();
        }
示例#6
0
        public T Get <T>(string settingKey, IPandoraContext context)
        {
            var value = Get(settingKey, context);

            if (value == null)
            {
                return(default(T));
            }

            var converter = TypeDescriptor.GetConverter(typeof(T));

            if (converter.IsValid(value))
            {
                T converted = (T)converter.ConvertFrom(value);
                return(converted);
            }
            else
            {
                var result = JsonConvert.DeserializeObject <T>(value);
                return(result);
            }
        }
示例#7
0
        public string Get(string settingKey, IPandoraContext applicationContext)
        {
            if (string.IsNullOrEmpty(settingKey))
            {
                throw new ArgumentNullException(nameof(settingKey));
            }
            if (ReferenceEquals(null, applicationContext))
            {
                throw new ArgumentNullException(nameof(applicationContext));
            }

            var    sanitizedKey  = settingKey.ToLower();
            string keyForMachine = NameBuilder.GetSettingName(applicationContext.ApplicationName, applicationContext.Cluster, applicationContext.Machine, sanitizedKey);

            if (cfgRepo.Exists(keyForMachine))
            {
                return(cfgRepo.Get(keyForMachine));
            }
            else
            {
                string keyForCluster = NameBuilder.GetSettingName(applicationContext.ApplicationName, applicationContext.Cluster, Machine.NotSpecified, sanitizedKey);
                return(cfgRepo.Get(keyForCluster));
            }
        }
示例#8
0
 public static string ToApplicationKeyPrefix(this IPandoraContext context)
 {
     return($"{ConsulForPandora.RootFolder}/{context.ApplicationName}".ToLower());
 }
示例#9
0
 public Pandora(IPandoraContext context, IConfigurationRepository configurationRepository)
 {
     this.context = context;
     this.cfgRepo = configurationRepository;
 }
示例#10
0
        public void Delete(string settingKey, IPandoraContext applicationContex)
        {
            var settingName = NameBuilder.GetSettingName(applicationContex.ApplicationName, applicationContex.Cluster, applicationContex.Machine, settingKey);

            cfgRepo.Delete(settingName);
        }
 public static void SetContext(IPandoraContext applicationContext)
 {
     context = applicationContext;
 }