use of org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException in project studio by craftercms.
the class StudioClusterGlobalRepoSyncTask method addRemoteRepository.
protected void addRemoteRepository(ClusterMember member, String remoteUrl) throws IOException, InvalidRemoteUrlException, ServiceLayerException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setGitDir(Paths.get(studioConfiguration.getProperty(StudioConfiguration.REPO_BASE_PATH), studioConfiguration.getProperty(StudioConfiguration.GLOBAL_REPO_PATH)).resolve(GIT_ROOT).toFile()).readEnvironment().findGitDir().build();
try (Git git = new Git(repo)) {
Config storedConfig = repo.getConfig();
Set<String> remotes = storedConfig.getSubsections(CONFIG_SECTION_REMOTE);
if (remotes.contains(member.getGitRemoteName().replaceFirst(CLUSTER_NODE_REMOTE_NAME_PREFIX, ""))) {
try {
studioClusterUtils.removeRemote(git, member.getGitRemoteName().replaceFirst(CLUSTER_NODE_REMOTE_NAME_PREFIX, ""));
} catch (GitAPIException e) {
logger.debug("Error while cleaning remote repositories for global repo", e);
}
}
if (remotes.contains(member.getGitRemoteName())) {
logger.debug("Remote " + member.getGitRemoteName() + " already exists for global repo");
String storedRemoteUrl = storedConfig.getString(CONFIG_SECTION_REMOTE, member.getGitRemoteName(), CONFIG_PARAMETER_URL);
if (!StringUtils.equals(storedRemoteUrl, remoteUrl)) {
RemoteSetUrlCommand remoteSetUrlCommand = git.remoteSetUrl();
remoteSetUrlCommand.setName(member.getGitRemoteName());
remoteSetUrlCommand.setUri(new URIish(remoteUrl));
remoteSetUrlCommand.call();
}
} else {
logger.debug("Add " + member.getLocalAddress() + " as remote to sandbox");
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName(member.getGitRemoteName());
remoteAddCommand.setUri(new URIish(remoteUrl));
remoteAddCommand.call();
}
} catch (URISyntaxException e) {
logger.error("Remote URL is invalid " + remoteUrl, e);
throw new InvalidRemoteUrlException();
} catch (GitAPIException e) {
logger.error("Error while adding remote " + member.getGitRemoteName() + " (url: " + remoteUrl + ") for global repo", e);
throw new ServiceLayerException("Error while adding remote " + member.getGitRemoteName() + " (url: " + remoteUrl + ") for global repo", e);
}
}
use of org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException in project studio by craftercms.
the class StudioClusterPublishedRepoSyncTask method addRemoteRepository.
protected void addRemoteRepository(String siteId, ClusterMember member, String remoteUrl) throws IOException, InvalidRemoteUrlException, ServiceLayerException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setGitDir(buildRepoPath(siteId).resolve(GIT_ROOT).toFile()).readEnvironment().findGitDir().build();
try (Git git = new Git(repo)) {
Config storedConfig = repo.getConfig();
Set<String> remotes = storedConfig.getSubsections(CONFIG_SECTION_REMOTE);
if (remotes.contains(member.getGitRemoteName().replaceFirst(CLUSTER_NODE_REMOTE_NAME_PREFIX, ""))) {
try {
removeRemote(git, member.getGitRemoteName().replaceFirst(CLUSTER_NODE_REMOTE_NAME_PREFIX, ""));
} catch (GitAPIException e) {
logger.debug("Error while cleaning up remote repository for site " + siteId, e);
}
}
if (remotes.contains(member.getGitRemoteName())) {
logger.debug("Remote " + member.getGitRemoteName() + " already exists for PUBLISHED repo for site " + siteId);
String storedRemoteUrl = storedConfig.getString(CONFIG_SECTION_REMOTE, member.getGitRemoteName(), CONFIG_PARAMETER_URL);
if (!StringUtils.equals(storedRemoteUrl, remoteUrl)) {
RemoteSetUrlCommand remoteSetUrlCommand = git.remoteSetUrl();
remoteSetUrlCommand.setName(member.getGitRemoteName());
remoteSetUrlCommand.setUri(new URIish(remoteUrl));
remoteSetUrlCommand.call();
}
} else {
logger.debug("Add " + member.getLocalAddress() + " as remote to PUBLISHED");
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName(member.getGitRemoteName());
remoteAddCommand.setUri(new URIish(remoteUrl));
remoteAddCommand.call();
}
} catch (URISyntaxException e) {
logger.error("Remote URL is invalid " + remoteUrl, e);
throw new InvalidRemoteUrlException();
} catch (GitAPIException e) {
logger.error("Error while adding remote " + member.getGitRemoteName() + " (url: " + remoteUrl + ") for site " + siteId, e);
throw new ServiceLayerException("Error while adding remote " + member.getGitRemoteName() + " (url: " + remoteUrl + ") for site " + siteId, e);
}
}
use of org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException in project studio by craftercms.
the class StudioClusterSandboxRepoSyncTask method addRemoteRepository.
private void addRemoteRepository(String siteId, ClusterMember member, String remoteUrl) throws IOException, InvalidRemoteUrlException, ServiceLayerException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setGitDir(buildRepoPath(siteId).resolve(GIT_ROOT).toFile()).readEnvironment().findGitDir().build();
try (Git git = new Git(repo)) {
Config storedConfig = repo.getConfig();
Set<String> remotes = storedConfig.getSubsections(CONFIG_SECTION_REMOTE);
if (remotes.contains(member.getGitRemoteName().replaceFirst(CLUSTER_NODE_REMOTE_NAME_PREFIX, ""))) {
try {
removeRemote(git, member.getGitRemoteName().replaceFirst(CLUSTER_NODE_REMOTE_NAME_PREFIX, ""));
} catch (GitAPIException e) {
logger.debug("Error while cleaning up remote repository for site " + siteId, e);
}
}
if (remotes.contains(member.getGitRemoteName())) {
logger.debug("Remote " + member.getGitRemoteName() + " already exists for SANDBOX repo for site " + siteId);
String storedRemoteUrl = storedConfig.getString(CONFIG_SECTION_REMOTE, member.getGitRemoteName(), CONFIG_PARAMETER_URL);
if (!StringUtils.equals(storedRemoteUrl, remoteUrl)) {
RemoteSetUrlCommand remoteSetUrlCommand = git.remoteSetUrl();
remoteSetUrlCommand.setName(member.getGitRemoteName());
remoteSetUrlCommand.setUri(new URIish(remoteUrl));
remoteSetUrlCommand.call();
}
} else {
logger.debug("Add " + member.getLocalAddress() + " as remote to SANDBOX");
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName(member.getGitRemoteName());
remoteAddCommand.setUri(new URIish(remoteUrl));
remoteAddCommand.call();
}
} catch (URISyntaxException e) {
logger.error("Remote URL is invalid " + remoteUrl, e);
throw new InvalidRemoteUrlException();
} catch (GitAPIException e) {
logger.error("Error while adding remote " + member.getGitRemoteName() + " (url: " + remoteUrl + ") for site " + siteId, e);
throw new ServiceLayerException("Error while adding remote " + member.getGitRemoteName() + " (url: " + remoteUrl + ") for site " + siteId, e);
}
}
use of org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException in project studio by craftercms.
the class StudioClusterSandboxRepoSyncTask method addRemoteRepository.
protected void addRemoteRepository(String siteId, RemoteRepository remoteRepository) throws IOException, InvalidRemoteUrlException, ServiceLayerException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setGitDir(buildRepoPath(siteId).resolve(GIT_ROOT).toFile()).readEnvironment().findGitDir().build();
try (Git git = new Git(repo)) {
logger.debug("Add " + remoteRepository.getRemoteName() + " as remote to SANDBOX");
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName(remoteRepository.getRemoteName());
remoteAddCommand.setUri(new URIish(remoteRepository.getRemoteUrl()));
remoteAddCommand.call();
} catch (URISyntaxException e) {
logger.error("Remote URL is invalid " + remoteRepository.getRemoteUrl(), e);
throw new InvalidRemoteUrlException();
} catch (GitAPIException e) {
logger.error("Error while adding remote " + remoteRepository.getRemoteName() + " (url: " + remoteRepository.getRemoteUrl() + ") for site " + siteId, e);
throw new ServiceLayerException("Error while adding remote " + remoteRepository.getRemoteName() + " (url: " + remoteRepository.getRemoteUrl() + ") for site " + siteId, e);
}
}
use of org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException in project studio by craftercms.
the class ContentServiceImpl method pushToRemote.
@Override
public boolean pushToRemote(String siteId, String remoteName, String remoteBranch) throws ServiceLayerException, InvalidRemoteUrlException, AuthenticationException, CryptoException {
if (!siteService.exists(siteId)) {
throw new SiteNotFoundException();
}
boolean toRet = _contentRepository.pushToRemote(siteId, remoteName, remoteBranch);
SiteFeed siteFeed = siteService.getSite(siteId);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_PUSH_TO_REMOTE);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(userService.getCurrentUser().getUsername());
auditLog.setPrimaryTargetId(remoteName + "/" + remoteBranch);
auditLog.setPrimaryTargetType(TARGET_TYPE_REMOTE_REPOSITORY);
auditLog.setPrimaryTargetValue(remoteName + "/" + remoteBranch);
auditServiceInternal.insertAuditLog(auditLog);
return toRet;
}
Aggregations