use of org.platformlayer.core.model.TagChanges in project platformlayer by platformlayer.
the class TypedPlatformLayerClient method addTags.
public Tags addTags(PlatformLayerKey key, List<Tag> tags) throws PlatformLayerClientException {
TagChanges changeTags = new TagChanges();
changeTags.addTags.addAll(tags);
return changeTags(key, changeTags);
}
use of org.platformlayer.core.model.TagChanges in project platformlayer by platformlayer.
the class ManagedKeystore method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
KeyStore keystore = null;
boolean dirty = false;
List<String> keyAliases;
{
byte[] data = target.readBinaryFile(path);
try {
if (data != null) {
keystore = KeyStoreUtils.load(data, keystoreSecret);
} else {
keystore = KeyStoreUtils.createEmpty(keystoreSecret);
dirty = true;
}
keyAliases = KeyStoreUtils.getKeyAliases(keystore);
} catch (GeneralSecurityException e) {
throw new OpsException("Error reading keystore", e);
} catch (IOException e) {
throw new OpsException("Error reading keystore", e);
}
}
if (keyAliases.contains(alias)) {
try {
Certificate[] existingCertificateChain = keystore.getCertificateChain(alias);
if (existingCertificateChain == null || existingCertificateChain.length == 0) {
keyAliases.remove(alias);
} else {
boolean remove = false;
if (key != null) {
X509Certificate[] wantCertificateChain = key.getCertificateChain();
// is the same
if (!Objects.equal(wantCertificateChain[0], existingCertificateChain[0])) {
log.warn("Key found, but mismatch on certificate; will remove");
remove = true;
}
}
if (remove) {
// TODO: Rename instead??
keystore.deleteEntry(alias);
dirty = true;
keyAliases.remove(alias);
}
}
} catch (KeyStoreException e) {
throw new OpsException("Error reading from keystore", e);
}
}
if (!keyAliases.contains(alias)) {
if (key == null) {
insertSelfSignedKey(keystore);
} else {
insertKey(keystore, key);
}
dirty = true;
keyAliases.add(alias);
}
if (tagWithPublicKeys != null) {
List<String> publicKeySigs = Lists.newArrayList();
try {
// for (String alias : keyAliases) {
Certificate[] cert = keystore.getCertificateChain(alias);
if (cert.length == 0) {
log.warn("Ignoring zero length certificate chain for: " + alias);
// continue;
} else {
PublicKey certPublicKey = cert[0].getPublicKey();
String sigString = OpenSshUtils.getSignatureString(certPublicKey);
publicKeySigs.add(sigString);
}
// }
} catch (GeneralSecurityException e) {
throw new OpsException("Error reading public keys", e);
}
List<String> existingSigs = Tag.PUBLIC_KEY_SIG.find(tagWithPublicKeys.getTags());
List<String> missing = Lists.newArrayList();
for (String publicKeySig : publicKeySigs) {
if (!existingSigs.contains(publicKeySig)) {
missing.add(publicKeySig);
}
}
if (!missing.isEmpty()) {
TagChanges tagChanges = new TagChanges();
for (String add : missing) {
tagChanges.addTags.add(Tag.PUBLIC_KEY_SIG.build(add));
}
platformlayer.changeTags(tagWithPublicKeys.getKey(), tagChanges);
}
}
if (dirty) {
byte[] data;
try {
data = KeyStoreUtils.serialize(keystore, keystoreSecret);
} catch (GeneralSecurityException e) {
throw new OpsException("Error serializing keystore", e);
} catch (IOException e) {
throw new OpsException("Error serializing keystore", e);
}
FileUpload.upload(target, path, data);
}
}
use of org.platformlayer.core.model.TagChanges in project platformlayer by platformlayer.
the class Tagger method handler.
@Handler
public void handler() throws OpsException {
if (OpsContext.isDelete() || OpsContext.isConfigure()) {
TagChanges tagChanges = tagChangesProvider.get();
if (tagChanges != null) {
log.info("Setting tags on " + platformLayerKey);
if (OpsContext.isDelete()) {
// Swap the tags for a removal
Tags x = tagChanges.addTags;
tagChanges.addTags = tagChanges.removeTags;
tagChanges.removeTags = x;
}
platformLayer.changeTags(platformLayerKey, tagChanges, null);
}
}
}
use of org.platformlayer.core.model.TagChanges in project platformlayer by platformlayer.
the class OpenstackInstanceController method addChildren.
@Override
protected void addChildren() throws OpsException {
final OpenstackInstance model = OpsContext.get().getInstance(OpenstackInstance.class);
CloudInstanceMapper instance;
{
instance = injected(CloudInstanceMapper.class);
instance.instance = model;
addChild(instance);
}
{
OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {
@Override
public TagChanges get() {
OpenstackComputeMachine machine = OpsContext.get().getInstance(OpenstackComputeMachine.class);
TagChanges tagChanges = new TagChanges();
tagChanges.addTags.add(Tag.INSTANCE_KEY.build(model.getKey()));
tagChanges.addTags.addAll(machine.buildAddressTags());
return tagChanges;
}
};
instance.addChild(Tagger.build(model, tagChanges));
}
// Note: We can't bootstrap an instance, because we can't log in to it,
// because the public key is not our service's public key
// if (model.publicPorts != null) {
// for (int publicPort : model.publicPorts) {
// PublicPorts publicPortForward = injected(PublicPorts.class);
// publicPortForward.port = publicPort;
// publicPortForward.backendItem = model;
// kvm.addChild(publicPortForward);
// }
// }
}
use of org.platformlayer.core.model.TagChanges in project platformlayer by platformlayer.
the class OpenstackPublicEndpointController method addChildren.
// @Inject
// ImageFactory imageFactory;
//
@Override
protected void addChildren() throws OpsException {
final OpenstackPublicEndpoint model = OpsContext.get().getInstance(OpenstackPublicEndpoint.class);
OpenstackInstance instance = client.getItem(model.instance, OpenstackInstance.class);
CloudInstanceMapper instanceMapper;
{
instanceMapper = injected(CloudInstanceMapper.class);
instanceMapper.instance = instance;
addChild(instanceMapper);
}
final EnsureFirewallIngress ingress;
{
ingress = injected(EnsureFirewallIngress.class);
ingress.model = model;
instanceMapper.addChild(ingress);
}
{
OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {
@Override
public TagChanges get() {
TagChanges tagChanges = new TagChanges();
String address = ingress.getPublicAddress();
if (Strings.isNullOrEmpty(address)) {
throw new IllegalStateException();
}
EndpointInfo endpoint = new EndpointInfo(address, model.publicPort);
tagChanges.addTags.add(endpoint.toTag());
return tagChanges;
}
};
Tagger tagger = injected(Tagger.class);
tagger.platformLayerKey = model.getKey();
tagger.tagChangesProvider = tagChanges;
instanceMapper.addChild(tagger);
Tagger tagInstance = injected(Tagger.class);
tagInstance.platformLayerKey = null;
tagInstance.platformLayerKey = model.instance;
tagInstance.tagChangesProvider = tagChanges;
instanceMapper.addChild(tagInstance);
}
}
Aggregations