use of org.craftercms.studio.api.v2.utils.StudioConfiguration.SITES_REPOS_PATH in project studio by craftercms.
the class GitContentRepository method deleteSite.
@Override
public boolean deleteSite(String site) {
boolean toReturn;
String gitLockKey = SITE_SANDBOX_REPOSITORY_GIT_LOCK.replaceAll(PATTERN_SITE, site);
generalLockService.lock(gitLockKey);
try {
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
Repository repository = helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : SANDBOX);
if (repository != null) {
synchronized (repository) {
Repository publishedRepository = helper.getRepository(site, PUBLISHED);
if (publishedRepository != null) {
synchronized (publishedRepository) {
toReturn = helper.deleteSiteGitRepo(site);
}
} else {
toReturn = helper.deleteSiteGitRepo(site);
}
}
} else {
Path sitePath = Paths.get(studioConfiguration.getProperty(REPO_BASE_PATH), studioConfiguration.getProperty(SITES_REPOS_PATH), site);
try {
FileUtils.deleteDirectory(sitePath.toFile());
toReturn = true;
} catch (IOException e) {
logger.error("Error while deleting site " + site, e);
toReturn = false;
}
}
} catch (CryptoException e) {
logger.error("Error while deleting site " + site, e);
toReturn = false;
} finally {
generalLockService.unlock(gitLockKey);
}
return toReturn;
}
use of org.craftercms.studio.api.v2.utils.StudioConfiguration.SITES_REPOS_PATH in project studio by craftercms.
the class ClusterNodeRegistrationImpl method init.
public void init() {
logger.debug("Autoregister cluster if cluster node is configured");
HierarchicalConfiguration<ImmutableNode> registrationData = getConfiguration();
ClusterMember clusterMember = new ClusterMember();
if (registrationData != null && !registrationData.isEmpty()) {
try {
logger.debug("Collect and populate data for cluster node registration");
clusterMember.setLocalAddress(registrationData.getString(CLUSTER_MEMBER_LOCAL_ADDRESS));
Path path = Paths.get(studioConfiguration.getProperty(REPO_BASE_PATH), studioConfiguration.getProperty(SITES_REPOS_PATH));
String authenticationType = registrationData.getString(CLUSTER_MEMBER_AUTHENTICATION_TYPE);
String username = registrationData.getString(CLUSTER_MEMBER_USERNAME);
String password = registrationData.getString(CLUSTER_MEMBER_PASSWORD);
String token = registrationData.getString(CLUSTER_MEMBER_TOKEN);
String privateKey = registrationData.getString(CLUSTER_MEMBER_PRIVATE_KEY);
String gitUrl = studioConfiguration.getProperty(CLUSTERING_SYNC_URL_FORMAT);
if (StringUtils.isEmpty(username)) {
gitUrl = gitUrl.replace("{username}@", "");
} else {
gitUrl = gitUrl.replace("{username}", username);
}
gitUrl = gitUrl.replace("{localAddress}", clusterMember.getLocalAddress()).replace("{absolutePath}", path.toAbsolutePath().normalize().toString()) + "/{siteId}";
clusterMember.setGitUrl(gitUrl);
clusterMember.setState(ClusterMember.State.ACTIVE);
clusterMember.setGitRemoteName(getGitRemoteName(clusterMember));
clusterMember.setGitAuthType(authenticationType.toLowerCase());
clusterMember.setGitUsername(username);
if (StringUtils.isEmpty(password)) {
clusterMember.setGitPassword(password);
} else {
String hashedPassword = encryptor.encrypt(password);
clusterMember.setGitPassword(hashedPassword);
}
if (StringUtils.isEmpty(token)) {
clusterMember.setGitToken(token);
} else {
String hashedToken = encryptor.encrypt(token);
clusterMember.setGitToken(hashedToken);
}
if (StringUtils.isEmpty(privateKey)) {
clusterMember.setGitPrivateKey(privateKey);
} else {
String hashedPrivateKey = encryptor.encrypt(privateKey);
clusterMember.setGitPrivateKey(hashedPrivateKey);
}
clusterMember.setAvailable(1);
logger.debug("Register cluster member");
registerClusterNode(clusterMember);
} catch (CryptoException e) {
logger.error("Failed to register cluster member");
}
}
}
Aggregations