use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class JdbcUserRepository method grantProjectToProject.
@Override
@JdbcTransaction
public void grantProjectToProject(String grantToProjectKey, String onProjectKey, SecretKey onProjectSecret) throws RepositoryException {
DbHelper db = new DbHelper();
try {
ProjectEntity grantToProject = db.findProjectByKey(grantToProjectKey);
if (grantToProject == null) {
throw new RepositoryException("Project not found");
}
ProjectEntity onProject = db.findProjectByKey(onProjectKey);
if (onProject == null) {
throw new RepositoryException("Project not found");
}
byte[] projectSecretData = onProjectSecret.getEncoded();
PublicKey grantToProjectPublicKey = grantToProject.getPublicKey();
byte[] newSecretData;
try {
SecretStore store = new SecretStore(onProject.secretData);
Writer writer = store.buildWriter();
writer.writeAsymetricProjectKey(projectSecretData, grantToProject.id, grantToProjectPublicKey);
writer.close();
store.appendContents(writer);
newSecretData = store.getEncoded();
} catch (IOException e) {
throw new RepositoryException("Error writing secrets", e);
}
db.updateProjectSecret(onProject.id, newSecretData);
// db.insertUserProject(user.id, project.id);
} catch (SQLException e) {
throw new RepositoryException("Error reading groups", e);
} finally {
db.close();
}
}
use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class PrivateDataHelper method putKeyPair.
public void putKeyPair(ProjectId project, ServiceType serviceType, ServiceMetadataKey keyId, KeyPair keyPair) throws OpsException {
String serialized;
try {
serialized = KeyPairUtils.serialize(keyPair);
} catch (IOException e) {
throw new OpsException("Error serializing key pair", e);
}
try {
serviceAuthorizationService.setPrivateData(serviceType, project, keyId, serialized);
} catch (RepositoryException e) {
throw new OpsException("Error writing to repository", e);
}
saveKeypairInDevelopment(project, serviceType, keyPair);
}
use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method changeTags.
@Override
@JdbcTransaction
public Tags changeTags(ModelClass<?> modelClass, ProjectId project, ManagedItemId itemKey, TagChanges changeTags, Long ifVersion) throws RepositoryException {
DbHelper db = new DbHelper(modelClass, project);
try {
int projectId = db.mapToValue(project);
int modelId = db.mapToValue(modelClass.getItemType());
int serviceId = db.mapToValue(modelClass.getServiceType());
ItemEntity rs = db.queries.findItem(serviceId, modelId, projectId, itemKey.getKey());
if (rs == null) {
// TODO: Better exception??
throw new IllegalStateException("Not found");
}
int itemId = rs.id;
if (ifVersion != null) {
log.warn("CAS version swapping not implemented");
}
Tags tags = new Tags();
mapToTags(db.listTagsForItem(itemId), tags);
if (changeTags.addTags != null) {
for (Tag addTag : changeTags.addTags) {
if (tags.hasTag(addTag)) {
continue;
}
db.insertTag(itemId, addTag);
tags.add(addTag);
}
}
if (changeTags.removeTags != null) {
for (Tag removeTag : changeTags.removeTags) {
boolean removed = tags.remove(removeTag);
if (!removed) {
continue;
}
db.removeTag(itemId, removeTag);
}
}
return tags;
} catch (SQLException e) {
throw new RepositoryException("Error running query", e);
} finally {
db.close();
}
}
use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method createManagedItem.
@Override
@JdbcTransaction
public <T extends ItemBase> T createManagedItem(ProjectId project, T item) throws RepositoryException {
DbHelper db = new DbHelper(item.getClass(), project);
try {
CryptoKey itemSecret = FathomdbCrypto.generateKey();
byte[] data = serialize(item, itemSecret);
byte[] secretData = itemSecrets.encodeItemSecret(itemSecret);
int itemId = db.insertItem(item, data, secretData);
Tags tags = item.tags;
if (tags != null && !tags.isEmpty()) {
db.insertTags(itemId, tags);
}
return item;
} catch (SQLException e) {
throw new RepositoryException("Error running query", e);
} finally {
db.close();
}
}
use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method getManagedItem.
@Override
@JdbcTransaction
public ItemBase getManagedItem(PlatformLayerKey key, boolean fetchTags, SecretProvider secretProvider) throws RepositoryException {
DbHelper db = new DbHelper(key);
try {
ServiceProvider serviceProvider = serviceProviderDirectory.getServiceProvider(key.getServiceType());
if (serviceProvider == null) {
throw new IllegalStateException();
}
ModelClass<?> modelClass = serviceProvider.getModelClass(key.getItemType());
ServiceType serviceType = key.getServiceType();
ItemType itemType = key.getItemType();
ProjectId project = key.getProject();
ManagedItemId itemId = key.getItemId();
return fetchItem(db, serviceType, itemType, project, itemId, modelClass.getJavaClass(), secretProvider, fetchTags);
} catch (SQLException e) {
throw new RepositoryException("Error running query", e);
} finally {
db.close();
}
}
Aggregations