use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class InstanceBuilder method doOperation.
@Handler
public void doOperation() throws OpsException, IOException {
ItemBase item = ops.getInstance(ItemBase.class);
Tag parentTag = Tag.buildParentTag(item.getKey());
PersistentInstance persistentInstanceTemplate = buildPersistentInstanceTemplate();
persistentInstanceTemplate.getTags().add(parentTag);
// Set during doOperation
Machine machine = null;
PersistentInstance persistentInstance = null;
InstanceBase instance = null;
OpsTarget target = null;
persistentInstance = getOrCreate(parentTag, persistentInstanceTemplate);
if (persistentInstance != null) {
// We have to connect to the underlying machine not-via-DNS for Dns service => use instance id
// TODO: Should we always use the instance id??
instance = instances.findInstance(persistentInstance);
if (instance == null && !OpsContext.isDelete()) {
// A machine has not (yet) been assigned
throw new OpsException("Machine is not yet built").setRetry(TimeSpan.ONE_MINUTE);
}
}
if (instance != null) {
machine = cloudHelpers.toMachine(instance);
}
if (addTagToManaged && !OpsContext.isDelete()) {
// Add tag with instance id to persistent instance (very helpful for
// DNS service!)
PlatformLayerKey machineKey = machine.getKey();
platformLayer.addTag(item.getKey(), Tag.INSTANCE_KEY.build(machineKey));
}
SshKey sshKey = service.getSshKey();
if (machine != null) {
if (OpsContext.isDelete()) {
target = null;
machine = null;
} else {
target = machine.getTarget(sshKey);
}
}
RecursionState recursion = getRecursionState();
if (OpsContext.isDelete() && machine == null) {
// Don't recurse into no machine :-)
recursion.setPreventRecursion(true);
}
recursion.pushChildScope(Machine.class, machine);
recursion.pushChildScope(PersistentInstance.class, persistentInstance);
recursion.pushChildScope(InstanceBase.class, instance);
recursion.pushChildScope(OpsTarget.class, target);
}
use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class StandardTemplateData method findCaKey.
public ManagedSecretKey findCaKey() throws OpsException {
PlatformLayerKey caPath = getCaPath();
if (caPath == null) {
return null;
}
ItemBase sslKeyItem = (ItemBase) platformLayer.getItem(caPath);
ManagedSecretKey key = providers.toInterface(sslKeyItem, ManagedSecretKey.class);
return key;
}
use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class SimpleMultitenantConfiguration method build.
public static MultitenantConfiguration build(Configuration configuration, EncryptionStore encryptionStore, AuthenticationService authenticationService, AuthenticationTokenValidator authenticationTokenValidator) throws OpsException {
String projectKey = configuration.lookup("multitenant.project", null);
String username = configuration.lookup("multitenant.user", null);
String password = configuration.lookup("multitenant.password", null);
String certAlias = configuration.lookup("multitenant.cert", null);
CertificateAndKey certificateAndKey = null;
if (certAlias != null) {
certificateAndKey = encryptionStore.getCertificateAndKey(certAlias);
}
String message = "Invalid multitenant configuration";
if (username == null || projectKey == null) {
throw new OpsException(message);
}
AuthenticationToken authn = null;
if (certificateAndKey != null) {
try {
authn = authenticationService.authenticateWithCertificate(username, certificateAndKey.getPrivateKey(), certificateAndKey.getCertificateChain());
} catch (PlatformlayerAuthenticationClientException e) {
throw new OpsException(message, e);
}
} else if (password != null) {
log.warn("Using password authentication with multitenant");
if (!ApplicationMode.isDevelopment()) {
throw new IllegalStateException();
}
try {
authn = authenticationService.authenticateWithPassword(username, password);
} catch (PlatformlayerAuthenticationClientException e) {
throw new OpsException(message, e);
}
}
if (authn == null) {
throw new OpsException(message);
}
ProjectAuthorization authz = authenticationTokenValidator.validateToken(authn, projectKey);
if (authz == null) {
throw new OpsException(message);
}
// {
// try {
// project = userRepository.findProject(user, projectKey);
// } catch (RepositoryException e) {
// throw new OpsException(message, e);
// }
//
// if (project == null) {
// throw new OpsException(message);
// }
// }
List<PlatformLayerKey> mappedItems = Lists.newArrayList();
for (String key : Splitter.on(",").split(configuration.lookup("multitenant.keys", ""))) {
String[] tokens = key.split("/");
if (tokens.length != 2) {
throw new IllegalStateException();
}
String serviceType = tokens[0];
String itemType = tokens[1];
mappedItems.add(PlatformLayerKey.fromServiceAndItem(serviceType, itemType));
}
if (mappedItems.isEmpty()) {
throw new OpsException(message);
}
MultitenantConfiguration config = new SimpleMultitenantConfiguration(authz, mappedItems);
return config;
}
use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class TreeWalker method visitQueue.
public void visitQueue() throws OpsException {
for (int i = 0; i < queue.size(); i++) {
PlatformLayerKey key = queue.get(i);
if (visited.contains(key)) {
continue;
}
visitChildren(key);
}
}
use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class TreeWalker method foundItem.
protected void foundItem(ItemBase child) throws OpsException {
PlatformLayerKey key = child.getKey();
visited.add(key);
visitChildren(key);
}
Aggregations