use of org.platformlayer.ops.crypto.Passwords in project platformlayer by platformlayer.
the class ServiceProviderBase method autoPopulate.
public void autoPopulate(Object item) throws OpsException {
Class<? extends Object> itemClass = item.getClass();
for (Field field : itemClass.getFields()) {
Generate defaultAnnotation = field.getAnnotation(Generate.class);
if (defaultAnnotation != null) {
Class<?> fieldType = field.getType();
Object value;
try {
value = field.get(item);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Error getting field: " + field, e);
}
if (value == null) {
String defaultValue = defaultAnnotation.value();
if (!Strings.isNullOrEmpty(defaultValue)) {
value = defaultValue;
} else {
if (fieldType == Secret.class) {
Passwords passwords = new Passwords();
Secret secret = passwords.generateRandomPassword(12);
value = secret;
}
}
if (value != null) {
try {
field.set(item, value);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Error setting field: " + field, e);
}
}
}
}
}
}
use of org.platformlayer.ops.crypto.Passwords in project platformlayer by platformlayer.
the class WordpressProvider method beforeCreateItem.
@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
super.beforeCreateItem(item);
// TODO: This doesn't feel like the right place for this
if (item instanceof WordpressService) {
WordpressService wordpressService = (WordpressService) item;
Passwords passwords = new Passwords();
if (Secret.isNullOrEmpty(wordpressService.adminPassword)) {
wordpressService.adminPassword = passwords.generateRandomPassword(10);
}
if (Secret.isNullOrEmpty(wordpressService.databasePassword)) {
wordpressService.databasePassword = passwords.generateRandomPassword(20);
}
if (Secret.isNullOrEmpty(wordpressService.wordpressSecretKey)) {
wordpressService.wordpressSecretKey = passwords.generateRandomPassword(50);
}
}
}
use of org.platformlayer.ops.crypto.Passwords in project platformlayer by platformlayer.
the class OpenLdapProvider method beforeCreateItem.
@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
super.beforeCreateItem(item);
// TODO: This doesn't feel like the right place for this
if (item instanceof LdapService) {
LdapService ldapService = (LdapService) item;
Passwords passwords = new Passwords();
if (Secret.isNullOrEmpty(ldapService.ldapServerPassword)) {
ldapService.ldapServerPassword = passwords.generateRandomPassword(12);
}
}
if (item instanceof LdapDomain) {
LdapDomain ldapService = (LdapDomain) item;
Passwords passwords = new Passwords();
if (Secret.isNullOrEmpty(ldapService.adminPassword)) {
ldapService.adminPassword = passwords.generateRandomPassword(12);
}
}
}
use of org.platformlayer.ops.crypto.Passwords in project platformlayer by platformlayer.
the class MysqlProvider method beforeCreateItem.
@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
super.beforeCreateItem(item);
// TODO: This doesn't feel like the right place for this
if (item instanceof MysqlServer) {
MysqlServer mysqlServer = (MysqlServer) item;
Passwords passwords = new Passwords();
if (Secret.isNullOrEmpty(mysqlServer.rootPassword)) {
mysqlServer.rootPassword = passwords.generateRandomPassword(12);
}
}
}
Aggregations