michaelklishin / quartz-mongodb

A MongoDB-based store for the Quartz scheduler. This fork strives to be as feature complete as possible. Originally by MuleSoft.
Other
247 stars 199 forks source link

Allow credentials to be added to MongoClientSettings #205

Closed sjerman closed 1 year ago

sjerman commented 3 years ago

This allows a uri to be defined without credentials and the credential be added on use.

The newer client APIs allow for this method - and it is bad practise to hard code credentials.

In my case, I store the mongo URI as part of a container config and the credentials as a secret and then combine when starting the container.

  @Bean
  public SchedulerFactoryBean schedulerFactoryBean(SecretReader reader, MongoProperties mongo, QuartzProperties properties) {
    Properties qp = properties.getQuartz();
    qp.put("org.quartz.jobStore.mongoUri", mongo.determineUri());   

    Optional<Secret> osecret = reader.getSecret();    
    if (osecret.isPresent()) {
      Secret secret = osecret.get();
      qp.put("org.quartz.jobStore.authDbName","admin");
      qp.put("org.quartz.jobStore.username",secret.dbUser);
      qp.put("org.quartz.jobStore.password",secret.dbPassword);
    } else if (mongo.getUsername() != null && mongo.getPassword() != null) {
        qp.put("org.quartz.jobStore.authDbName","admin");
        qp.put("org.quartz.jobStore.username",mongo.getUsername());
        qp.put("org.quartz.jobStore.password",new String(mongo.getPassword()));
    }

    SchedulerFactoryBean scheduler = new SchedulerFactoryBean();    

    scheduler.setQuartzProperties(qp);
    scheduler.setStartupDelay(20);
    scheduler.setWaitForJobsToCompleteOnShutdown(true);

    AutowiringSpringBeanJobFactory jobFac = new AutowiringSpringBeanJobFactory();
    jobFac.setApplicationContext(context);
    scheduler.setJobFactory(jobFac);

    return scheduler;
  }
wakecaine1 commented 3 years ago

Bump here as it seems that Travis did time out when this build was checked and since then nothing changed. This could be in new release. @michaelklishin can you rerun pipeline, when you have time? Btw. there is change of Travis domain in near future from org to com. Idk if this will affect anything here