瀏覽代碼

clean up activation codepath. config.paymentsEnabled is now a derived property

tags/v0.1.8
Jonathan Cobb 5 年之前
父節點
當前提交
59fbdb47e9
共有 9 個檔案被更改,包括 45 行新增16 行删除
  1. +2
    -2
      bin/bpost
  2. +2
    -2
      bin/bput
  3. +1
    -1
      bubble-server/src/main/java/bubble/cloud/compute/vultr/VultrDriver.java
  4. +22
    -1
      bubble-server/src/main/java/bubble/dao/cloud/CloudServiceDAO.java
  5. +1
    -0
      bubble-server/src/main/java/bubble/model/cloud/CloudService.java
  6. +16
    -6
      bubble-server/src/main/java/bubble/server/BubbleConfiguration.java
  7. +1
    -2
      bubble-server/src/main/java/bubble/service/boot/ActivationService.java
  8. +0
    -1
      bubble-server/src/main/resources/bubble-config.yml
  9. +0
    -1
      bubble-server/src/test/resources/test-bubble-config.yml

+ 2
- 2
bin/bpost 查看文件

@@ -4,10 +4,10 @@
#
# Usage:
#
# bpost path [file] [options]
# bpost path file [options]
#
# path : an API path
# file : a JSON file to POST. To read from stdin, specify the file as -
# path : an API path
# options : bscript options, see bubble.main.BubbleScriptOptions (and parent classes) for more info
#
# Environment variables


+ 2
- 2
bin/bput 查看文件

@@ -4,10 +4,10 @@
#
# Usage:
#
# bput path [file] [options]
# bput path file [options]
#
# path : an API path
# file : a JSON file to POST. To read from stdin, specify the file as -
# file : a JSON file to PUT. To read from stdin, specify the file as -
# options : bscript options, see bubble.main.BubbleScriptOptions (and parent classes) for more info
#
# Environment variables


+ 1
- 1
bubble-server/src/main/java/bubble/cloud/compute/vultr/VultrDriver.java 查看文件

@@ -81,7 +81,7 @@ public class VultrDriver extends ComputeServiceDriverBase {

@Override public void postSetup() {
if (credentials != null && credentials.hasParam(API_KEY_HEADER) && credentials.getParam(API_KEY_HEADER).contains("{{")) {
final String apiKey = HandlebarsUtil.apply(getHandlebars(), credentials.getParam(API_KEY_HEADER), configuration.getEnvCtx());
final String apiKey = configuration.applyHandlebars(credentials.getParam(API_KEY_HEADER));
credentials.setParam(API_KEY_HEADER, apiKey);
}
super.postSetup();


+ 22
- 1
bubble-server/src/main/java/bubble/dao/cloud/CloudServiceDAO.java 查看文件

@@ -1,10 +1,12 @@
package bubble.dao.cloud;

import bubble.cloud.CloudServiceType;
import bubble.cloud.storage.local.LocalStorageDriver;
import bubble.dao.account.AccountDAO;
import bubble.dao.account.AccountOwnedTemplateDAO;
import bubble.model.account.Account;
import bubble.model.cloud.BubbleNetwork;
import bubble.model.cloud.CloudService;
import bubble.cloud.CloudServiceType;
import bubble.server.BubbleConfiguration;
import org.cobbzilla.wizard.validation.ValidationResult;
import org.hibernate.criterion.Order;
@@ -21,6 +23,7 @@ import static org.cobbzilla.wizard.resources.ResourceUtil.invalidEx;
@Repository
public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> {

@Autowired private AccountDAO accountDAO;
@Autowired private BubbleConfiguration configuration;

@Override public Order getDefaultSortOrder() { return Order.desc("priority"); }
@@ -37,6 +40,12 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> {
}
}
}
if (cloud.hasCredentials() && cloud.getCredentialsJson().contains("{{") && cloud.getCredentialsJson().contains("}}")) {
cloud.setCredentialsJson(configuration.applyHandlebars(cloud.getCredentialsJson()));
}
if (cloud.hasDriverConfig() && cloud.getDriverConfigJson().contains("{{") && cloud.getDriverConfigJson().contains("}}")) {
cloud.setDriverConfigJson(configuration.applyHandlebars(cloud.getDriverConfigJson()));
}
return super.preCreate(cloud);
}

@@ -45,6 +54,13 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> {
final ValidationResult errors = testDriver(cloud, configuration);
if (errors.isInvalid()) throw invalidEx(errors);
}
if (cloud.getType() == CloudServiceType.payment
&& cloud.template()
&& cloud.enabled()
&& !configuration.paymentsEnabled()) {
// a public template for a payment cloud has been added, and payments were not enabled -- now they are
configuration.refreshPublicSystemConfigs();
}
return super.postCreate(cloud, context);
}

@@ -83,4 +99,9 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> {
return found.isEmpty() ? null : found.get(0);
}

public boolean paymentsEnabled() {
final Account admin = accountDAO.findFirstAdmin();
if (admin == null) return false;
return !findPublicTemplatesByType(admin.getUuid(), CloudServiceType.payment).isEmpty();
}
}

+ 1
- 0
bubble-server/src/main/java/bubble/model/cloud/CloudService.java 查看文件

@@ -143,6 +143,7 @@ public class CloudService extends IdentifiableBaseParentEntity implements Accoun
@Size(max=100000, message="err.driverConfigJson.length")
@Type(type=ENCRYPTED_STRING) @Column(columnDefinition="varchar("+(100000+ENC_PAD)+")")
@JsonIgnore @Getter @Setter private String driverConfigJson;
public boolean hasDriverConfig () { return !empty(driverConfigJson); }

@Transient public JsonNode getDriverConfig () { return json(driverConfigJson, JsonNode.class); }
public CloudService setDriverConfig (JsonNode node) { return setDriverConfigJson(node == null ? null : json(node)); }


+ 16
- 6
bubble-server/src/main/java/bubble/server/BubbleConfiguration.java 查看文件

@@ -5,6 +5,7 @@ import bubble.BubbleHandlebars;
import bubble.client.BubbleApiClient;
import bubble.cloud.CloudServiceDriver;
import bubble.dao.account.AccountDAO;
import bubble.dao.cloud.CloudServiceDAO;
import bubble.model.cloud.BubbleNetwork;
import bubble.model.cloud.BubbleNode;
import bubble.server.listener.BubbleFirstTimeListener;
@@ -20,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.DefaultedMap;
import org.apache.commons.lang.ArrayUtils;
import org.cobbzilla.util.collection.MapBuilder;
import org.cobbzilla.util.handlebars.HandlebarsUtil;
import org.cobbzilla.util.handlebars.HasHandlebars;
import org.cobbzilla.util.http.ApiConnectionInfo;
import org.cobbzilla.util.io.FileUtil;
@@ -195,11 +197,10 @@ public class BubbleConfiguration extends PgRestServerConfiguration

@Getter @Setter private LegalInfo legal = new LegalInfo();

@Getter @Setter private Boolean paymentsEnabled = false;
public boolean paymentsEnabled() { return paymentsEnabled != null && paymentsEnabled; }

@Override @JsonIgnore public Handlebars getHandlebars() { return BubbleHandlebars.instance.getHandlebars(); }

public String applyHandlebars(String val) { return HandlebarsUtil.apply(getHandlebars(), val, getEnvCtx()); }

public ApiClientBase newApiClient() { return new BubbleApiClient(new ApiConnectionInfo(getLoopbackApiBase())); }

public String getVersion () {
@@ -259,12 +260,13 @@ public class BubbleConfiguration extends PgRestServerConfiguration
final BubbleNode thisNode = getThisNode();
final BubbleNetwork thisNetwork = getThisNetwork();
final AccountDAO accountDAO = getBean(AccountDAO.class);
final CloudServiceDAO cloudDAO = getBean(CloudServiceDAO.class);
final ActivationService activationService = getBean(ActivationService.class);
publicSystemConfigs.set(MapBuilder.build(new Object[][]{
{TAG_ALLOW_REGISTRATION, thisNetwork == null ? null : thisNetwork.getBooleanTag(TAG_ALLOW_REGISTRATION, false)},
{TAG_NETWORK_UUID, thisNetwork == null ? null : thisNetwork.getUuid()},
{TAG_SAGE_LAUNCHER, thisNetwork == null || isSageLauncher()},
{TAG_PAYMENTS_ENABLED, paymentsEnabled()},
{TAG_PAYMENTS_ENABLED, cloudDAO.paymentsEnabled()},
{TAG_CLOUD_DRIVERS, getCloudDriverClasses()},
{TAG_ENTITY_CLASSES, getSortedSimpleEntityClassMap()},
{TAG_LOCALES, getAllLocales()},
@@ -277,12 +279,17 @@ public class BubbleConfiguration extends PgRestServerConfiguration
}
}

// called after activation, because now thisNetwork will be defined. otherwise it remains unchanged
// called after activation, because now thisNetwork will be defined
public void refreshPublicSystemConfigs () {
synchronized (publicSystemConfigs) { publicSystemConfigs.set(null); }
background(this::getPublicSystemConfigs);
}

public boolean paymentsEnabled () {
final Object peValue = getPublicSystemConfigs().get(TAG_PAYMENTS_ENABLED);
return peValue != null && Boolean.parseBoolean(peValue.toString());
}

@Getter @Setter private String[] disallowedCountries;

public boolean hasDisallowedCountries() { return !empty(disallowedCountries); }
@@ -294,11 +301,14 @@ public class BubbleConfiguration extends PgRestServerConfiguration
return false;
}

@Getter @Setter private Boolean defaultPaymentModelsEnabled;
public boolean defaultPaymentModelsEnabled() { return defaultPaymentModelsEnabled != null && defaultPaymentModelsEnabled; }

@JsonIgnore @Getter(lazy=true) private final List<String> defaultCloudModels = initDefaultCloudModels();
private List<String> initDefaultCloudModels () {
final List<String> defaults = new ArrayList<>();
defaults.add("models/defaults/cloudService.json");
if (paymentsEnabled()) defaults.add("models/defaults/cloudService_payment.json");
if (defaultPaymentModelsEnabled()) defaults.add("models/defaults/cloudService_payment.json");
if (testMode()) defaults.addAll(getTestCloudModels());
return defaults;
}


+ 1
- 2
bubble-server/src/main/java/bubble/service/boot/ActivationService.java 查看文件

@@ -17,7 +17,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.cobbzilla.util.collection.ArrayUtil;
import org.cobbzilla.util.handlebars.HandlebarsUtil;
import org.cobbzilla.wizard.api.CrudOperation;
import org.cobbzilla.wizard.client.ApiClientBase;
import org.cobbzilla.wizard.model.Identifiable;
@@ -260,7 +259,7 @@ public class ActivationService {
}

private CloudService[] loadCloudServices(final String modelPath) {
final String cloudsJson = HandlebarsUtil.apply(configuration.getHandlebars(), stream2string(modelPath), configuration.getEnvCtx());
final String cloudsJson = configuration.applyHandlebars(stream2string(modelPath));
final JsonNode cloudsArrayNode = json(cloudsJson, JsonNode.class);
return scrubSpecial(cloudsArrayNode, CloudService.class);
}


+ 0
- 1
bubble-server/src/main/resources/bubble-config.yml 查看文件

@@ -72,4 +72,3 @@ letsencryptEmail: {{LETSENCRYPT_EMAIL}}
localStorageDir: {{LOCALSTORAGE_BASE_DIR}}

disallowedCountries: {{DISALLOWED_COUNTRIES}}
paymentsEnabled: {{BUBBLE_PAYMENTS_ENABLED}}

+ 0
- 1
bubble-server/src/test/resources/test-bubble-config.yml 查看文件

@@ -69,4 +69,3 @@ letsencryptEmail: {{LETSENCRYPT_EMAIL}}
localStorageDir: {{LOCALSTORAGE_BASE_DIR}}

disallowedCountries: {{DISALLOWED_COUNTRIES}}
paymentsEnabled: {{BUBBLE_PAYMENTS_ENABLED}}

Loading…
取消
儲存