Search in sources :

Example 1 with SITES_REPOS_PATH

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;
}
Also used : Path(java.nio.file.Path) RemoteRepository(org.craftercms.studio.api.v2.dal.RemoteRepository) Repository(org.eclipse.jgit.lib.Repository) ContentRepository(org.craftercms.studio.api.v1.repository.ContentRepository) IOException(java.io.IOException) GitRepositoryHelper(org.craftercms.studio.api.v2.utils.GitRepositoryHelper) CryptoException(org.craftercms.commons.crypto.CryptoException)

Example 2 with SITES_REPOS_PATH

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");
        }
    }
}
Also used : Path(java.nio.file.Path) ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) ImmutableNode(org.apache.commons.configuration2.tree.ImmutableNode) CryptoException(org.craftercms.commons.crypto.CryptoException)

Aggregations

Path (java.nio.file.Path)2 CryptoException (org.craftercms.commons.crypto.CryptoException)2 IOException (java.io.IOException)1 ImmutableNode (org.apache.commons.configuration2.tree.ImmutableNode)1 ContentRepository (org.craftercms.studio.api.v1.repository.ContentRepository)1 ClusterMember (org.craftercms.studio.api.v2.dal.ClusterMember)1 RemoteRepository (org.craftercms.studio.api.v2.dal.RemoteRepository)1 GitRepositoryHelper (org.craftercms.studio.api.v2.utils.GitRepositoryHelper)1 Repository (org.eclipse.jgit.lib.Repository)1