public String buildNotificationDbName(String domainName) { String prefix = this.notificationDatabasePrefix; String suffix = this.notificationDatabaseSuffix; return buildDbName(domainName, "notify-notification-", prefix, suffix); }
public CouchServersConfig(CouchServersConfig couch) { setMasterUrl(couch.getMasterUrl()); setMasterUsername(couch.getMasterUsername()); setMasterPassword(couch.getMasterPassword()); setMasterDatabaseName(couch.getMasterDatabaseName()); setNotificationUrl(couch.getNotificationUrl()); setNotificationUsername(couch.getNotificationUsername()); setNotificationPassword(couch.getNotificationPassword()); setNotificationDatabasePrefix(couch.getNotificationDatabasePrefix()); setNotificationDatabaseSuffix(couch.getNotificationDatabaseSuffix()); setRequestUrl(couch.getRequestUrl()); setRequestUsername(couch.getRequestUsername()); setRequestPassword(couch.getRequestPassword()); setRequestDatabasePrefix(couch.getRequestDatabasePrefix()); setRequestDatabaseSuffix(couch.getRequestDatabaseSuffix()); }
@Autowired public DomainStore(CouchServers couchServers) { super(couchServers.getMasterDatabase()); this.couchServers = couchServers; this.notificationCouchServer = couchServers.getNotificationServer(); this.requestCouchServer = couchServers.getRequestServer(); }
@Bean public CouchServersConfig couchServersConfig() { CouchServersConfig config = new CouchServersConfig(); config.setMasterUrl(couchUrl); config.setMasterUsername(username); config.setMasterPassword(password); config.setMasterDatabaseName("test-notify-master"); config.setNotificationUrl(couchUrl); config.setNotificationUsername(username); config.setNotificationPassword(password); config.setNotificationDatabasePrefix("test-notify-"); config.setNotificationDatabaseSuffix("-notification"); config.setRequestUrl(couchUrl); config.setRequestUsername(username); config.setRequestPassword(password); config.setRequestDatabasePrefix("test-notify-"); config.setRequestDatabaseSuffix("-request"); return config; }
this.notificationDatabasePrefix = serversConfig.getNotificationDatabasePrefix(); this.notificationDatabaseSuffix = serversConfig.getNotificationDatabaseSuffix(); this.requestDatabasePrefix = serversConfig.getRequestDatabasePrefix(); this.requestDatabaseSuffix = serversConfig.getRequestDatabaseSuffix(); CouchSetup masterConfig = new CouchSetup(serversConfig.getMasterUrl()) .setHttpClient(JerseyCouchHttpClient.class) .setJsonStrategy(jsonStrategy) .setUserName(serversConfig.getMasterUsername()) .setPassword(serversConfig.getMasterPassword()); masterServer = new CouchServer(masterConfig); masterDatabase = initMasterDatabase(serversConfig, masterServer); CouchSetup notificationConfig = new CouchSetup(serversConfig.getNotificationUrl()) .setHttpClient(JerseyCouchHttpClient.class) .setJsonStrategy(jsonStrategy) .setUserName(serversConfig.getNotificationUsername()) .setPassword(serversConfig.getNotificationPassword()); notificationServer = new CouchServer(notificationConfig); CouchSetup requestConfig = new CouchSetup(serversConfig.getRequestUrl()) .setHttpClient(JerseyCouchHttpClient.class) .setJsonStrategy(jsonStrategy) .setUserName(serversConfig.getRequestUsername()) .setPassword(serversConfig.getRequestPassword()); requestServer = new CouchServer(requestConfig);
CouchServersConfig serversConfig = couchServers.getServersConfig(); Configuration httpClientConfig = new ClientConfig(); ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(httpClientConfig); Client client = clientBuilder.build(); client.register(HttpAuthenticationFeature.basic(serversConfig.getRequestUsername(), serversConfig.getRequestPassword())); String couchBaseUrl = serversConfig.getRequestUrl(); Response response = client.target(couchBaseUrl) .path("_users/" + documentId)
public DomainProfileEntity createDomain(String domainName, String apiKey, String apiPassword) { String notificationDbName = couchServers.buildNotificationDbName(domainName); String requestDbName = couchServers.buildRequestDbName(domainName); // Create the profile entity DomainProfileEntity profileEntity = DomainProfileEntity.newEntity( domainName, apiKey, apiPassword, notificationDbName, requestDbName, RouteCatalog.newEmptyCatalog()); profileEntity = save(profileEntity); // Create the notify and request databases createNotifyDatabase(profileEntity); createRequestDatabase(profileEntity); // Create the profile and store in couch and in the map. return profileEntity; }
@Bean public CouchEnvironment couchEnvironment() { return new CouchEnvironment().setTesting(true); } }
public void authorize(String username, String password) throws NotAuthorizedException { if (trustedUserStore.containsUser(username) == false || !trustedUserStore.isPasswordMatch(username, password)) { throw new NotAuthorizedException("ADMIN"); } } }
/** * Only used for testing, should use call createDomain(domainName) * TODO - assert we are in development or it's the system test domain * * @param domainName the name of the domain * @param apiKey the api key for the domain * @param apiPassword the api password for the domain * @return the domain */ public DomainProfile recreateDomain(String domainName, String apiKey, String apiPassword) { if (couchServers.getEnvironment().isTesting() == false) { throw ApiException.badRequest("Can only create domain in test environment"); } // Delete mast entry, if it exists. if (hasDomain(domainName)) { DomainProfileEntity domainProfileEntity = findByDomainName(domainName); deleteDomain(domainProfileEntity); } // Create domain profile. DomainProfileEntity domainProfile = createDomain(domainName, apiKey, apiPassword); return domainProfile.toModel(); }
private CouchDatabase initMasterDatabase(CouchServersConfig serversConfig, CouchServer masterServer) { if (couchEnvironment.isTesting()) { CouchFeatureSet featureSet = CouchFeatureSet.builder().add(CouchFeature.ALLOW_DB_DELETE, true).build(); CouchDatabase masterDatabaseForDelete = masterServer.database(serversConfig.getMasterDatabaseName(), featureSet); masterDatabaseForDelete.deleteDatabase(); CouchDatabase localMasterDatabase = masterServer.database(serversConfig.getMasterDatabaseName());
@Autowired public TestFactory(CouchServers couchServers, DomainKernel domainKernel, NotificationKernel notificationKernel) { try { this.notificationKernel = notificationKernel; // Delete any existing test databases. couchServers.deleteDomainDatabases(DOMAIN_NAME); // Create a test domain. domainKernel.recreateDomain(DOMAIN_NAME, API_KEY, API_PASSWORD); } catch (Exception e) { throw new RuntimeException(e); } }
@Bean public SystemConfiguration systemConfiguration() { return new SystemConfiguration("*", false); }
@Bean public TrustedUserStore trustedUserStore() { return new TrustedUserStore(BeanUtils.toMap( "admin:Testing123" )); }
public void deleteDomainDatabases(String domainName) { // if (couchEnvironment.isTesting() == false) { // throw ApiException.badRequest("Databases can only be deleted in the test environment"); // } CouchFeatureSet featureSet = CouchFeatureSet .builder() .add(CouchFeature.ALLOW_DB_DELETE, true) .build(); // Notification DB. String notificationDbName = buildNotificationDbName(domainName); CouchDatabase notificationDatabase = notificationServer.database(notificationDbName, featureSet); if (notificationDatabase.exists()) { notificationDatabase.deleteDatabase(); } // Request DB String requestDbName = buildRequestDbName(domainName); CouchDatabase requestDatabase = requestServer.database(requestDbName, featureSet); if (requestDatabase.exists()) { requestDatabase.deleteDatabase(); } }
public String buildRequestDbName(String domainName) { String prefix = this.requestDatabasePrefix; String suffix = this.requestDatabaseSuffix; return buildDbName(domainName, "notify-request-", prefix, suffix); }
/** * Delete the domain and request and notification databases. * * @param domainProfile - */ public void deleteDomain(DomainProfileEntity domainProfile) { // Delete mast entry, if it exists. couchDatabase.delete() .entity(domainProfile) .onError(r -> log.error(format("Failure deleting domain %s from master db [%s] - %s", domainProfile.getDomainName(), r.getHttpStatus(), r.getErrorReason()))) .execute(); couchServers.deleteDomainDatabases(domainProfile.getDomainName()); }