use of org.candlepin.common.config.Configuration in project candlepin by candlepin.
the class OAuth method setupAccessors.
/**
* Look for settings which are in the form of
* candlepin.auth.oauth.consumer.CONSUMERNAME.secret = CONSUMERSECRET and
* create consumers for them.
*/
protected void setupAccessors() {
String prefix = "candlepin.auth.oauth.consumer.";
Configuration oauthConfig = config.strippedSubset(prefix);
for (String key : oauthConfig.getKeys()) {
String[] parts = key.split("\\.");
if ((parts.length == 2) && (parts[1].equals("secret"))) {
String consumerName = parts[0];
String secret = oauthConfig.getString(key);
log.debug(String.format("Creating consumer '%s'", consumerName));
OAuthConsumer consumer = new OAuthConsumer("", consumerName, secret, null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessors.put(consumerName, accessor);
}
}
}
use of org.candlepin.common.config.Configuration in project candlepin by candlepin.
the class DefaultProductServiceAdapterTest method init.
@Before
public void init() {
opc = mock(OwnerProductCurator.class);
idgen = mock(UniqueIdGenerator.class);
Configuration config = mock(Configuration.class);
pki = mock(PKIUtility.class);
extUtil = new X509ExtensionUtil(config);
cc = mock(ContentCurator.class);
pcc = spy(new ProductCertificateCurator(pki, extUtil));
when(config.getBoolean(ConfigProperties.ENV_CONTENT_FILTERING)).thenReturn(false);
dpsa = new DefaultProductServiceAdapter(opc, pcc, cc, idgen);
}
use of org.candlepin.common.config.Configuration in project candlepin by candlepin.
the class CandlepinContextListener method readConfiguration.
protected Configuration readConfiguration(ServletContext context) throws ConfigurationException {
// Use StandardCharsets.UTF_8 when we move to Java 7
Charset utf8 = Charset.forName("UTF-8");
EncryptedConfiguration systemConfig = new EncryptedConfiguration();
systemConfig.setEncoding(utf8);
File configFile = new File(ConfigProperties.DEFAULT_CONFIG_FILE);
if (configFile.canRead()) {
log.debug("Loading system configuration");
// First, read the system configuration
systemConfig.load(configFile);
log.debug("System configuration: " + systemConfig);
}
systemConfig.use(PASSPHRASE_SECRET_FILE).toDecrypt(ENCRYPTED_PROPERTIES);
// load the defaults
MapConfiguration defaults = new MapConfiguration(ConfigProperties.DEFAULT_PROPERTIES);
// Default to Postgresql if jpa.config.hibernate.dialect is unset
DatabaseConfigFactory.SupportedDatabase db = determinDatabaseConfiguration(systemConfig.getString("jpa.config.hibernate.dialect", PostgreSQLDialect.class.getName()));
log.info("Running under {}", db.getLabel());
Configuration databaseConfig = DatabaseConfigFactory.fetchConfig(db);
// users should be doing unbidden so it is undocumented.
return EncryptedConfiguration.merge(systemConfig, databaseConfig, defaults);
}
use of org.candlepin.common.config.Configuration in project candlepin by candlepin.
the class PinsetterKernelTest method deletedCronTask.
@Test
public void deletedCronTask() throws Exception {
Map<String, String> props = new HashMap<>();
props.put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
props.put("org.quartz.jobStore.isClustered", "true");
props.put("pinsetter.org.candlepin.pinsetter.tasks.JobCleaner.schedule", "*/1 * * * * ?");
Configuration config = new MapConfiguration(props);
JobDetail jobDetail = mock(JobDetail.class);
String crongrp = "cron group";
Set<JobKey> jobs = new HashSet<>();
String deletedJobId = "StatisticHistoryTask-taylor-swift";
JobKey deletedKey = jobKey(deletedJobId);
jobs.add(deletedKey);
JobKey key = jobKey("org.candlepin.pinsetter.tasks.JobCleaner");
jobs.add(key);
CronTrigger cronTrigger = mock(CronTrigger.class);
when(cronTrigger.getJobKey()).thenReturn(deletedKey);
when(sched.getJobKeys(eq(jobGroupEquals(crongrp)))).thenReturn(jobs);
when(sched.getTrigger(any(TriggerKey.class))).thenReturn(cronTrigger);
when(sched.getJobDetail(any(JobKey.class))).thenReturn(jobDetail);
doReturn(JobCleaner.class).when(jobDetail).getJobClass();
pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
pk.startup();
verify(jcurator).deleteJobNoStatusReturn(eq(deletedJobId));
verify(sched, atLeastOnce()).deleteJob(deletedKey);
}
use of org.candlepin.common.config.Configuration in project candlepin by candlepin.
the class PinsetterKernelTest method updateSchedule.
@Test
public void updateSchedule() throws Exception {
Map<String, String> props = new HashMap<>();
props.put(ConfigProperties.DEFAULT_TASKS, JobCleaner.class.getName());
props.put("org.quartz.jobStore.isClustered", "true");
props.put("pinsetter.org.candlepin.pinsetter.tasks." + "JobCleaner.schedule", "*/1 * * * * ?");
Configuration config = new MapConfiguration(props);
JobDetail jobDetail = mock(JobDetail.class);
String crongrp = "cron group";
Set<JobKey> jobs = new HashSet<>();
JobKey key = jobKey("org.candlepin.pinsetter.tasks.JobCleaner");
jobs.add(key);
CronTrigger cronTrigger = mock(CronTrigger.class);
when(cronTrigger.getJobKey()).thenReturn(key);
when(cronTrigger.getCronExpression()).thenReturn("*/7 * * * * ?");
when(sched.getJobKeys(eq(jobGroupEquals(crongrp)))).thenReturn(jobs);
when(sched.getTrigger(any(TriggerKey.class))).thenReturn(cronTrigger);
when(sched.getJobDetail(any(JobKey.class))).thenReturn(jobDetail);
doReturn(JobCleaner.class).when(jobDetail).getJobClass();
pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
pk.startup();
verify(sched).deleteJob(key);
verify(jcurator).create(any(JobStatus.class));
}
Aggregations