feat: Add API for git docs and supported shh keys (#14641)

This commit is contained in:
Anagh Hegde 2022-06-22 21:50:04 +05:30 committed by GitHub
parent ed59802702
commit 14eb9b4cb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 21 deletions

View File

@ -629,7 +629,7 @@ public class GitExecutorImpl implements GitExecutor {
}
errorMessage.append(" while merging branch: ").append(destinationBranch).append(" <= ").append(sourceBranch);
mergeStatus.setMessage(errorMessage.toString());
mergeStatus.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT);
mergeStatus.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT.getDocUrl());
}
mergeStatus.setStatus(mergeResult.getMergeStatus().name());
return mergeStatus;

View File

@ -2,11 +2,20 @@ package com.appsmith.external.constants;
import lombok.Getter;
@Getter
public class ErrorReferenceDocUrl {
public static final String GIT_MERGE_CONFLICT = "https://docs.appsmith.com/core-concepts/version-control-with-git/merging-branches";
public static final String GIT_PULL_CONFLICT = "https://docs.appsmith.com/core-concepts/version-control-with-git/pull-and-sync";
public static final String GIT_DEPLOY_KEY = "https://docs.appsmith.com/core-concepts/version-control-with-git/connecting-to-git-repository#generating-a-deploy-key";
public static final String FILE_PATH_NOT_SET = "https://docs.appsmith.com/core-concepts/version-control-with-git/updating-local-file-path";
public static final String GIT_UPSTREAM_CHANGES = "https://docs.appsmith.com/core-concepts/version-control-with-git/working-with-branches#syncing-local-with-remote-branch";
public enum ErrorReferenceDocUrl {
GIT_MERGE_CONFLICT("https://docs.appsmith.com/core-concepts/version-control-with-git/merging-branches"),
GIT_PULL_CONFLICT("https://docs.appsmith.com/core-concepts/version-control-with-git/pull-and-sync"),
GIT_DEPLOY_KEY("https://docs.appsmith.com/core-concepts/version-control-with-git/connecting-to-git-repository#generating-a-deploy-key"),
FILE_PATH_NOT_SET("https://docs.appsmith.com/core-concepts/version-control-with-git/updating-local-file-path"),
GIT_UPSTREAM_CHANGES("https://docs.appsmith.com/core-concepts/version-control-with-git/working-with-branches#syncing-local-with-remote-branch"),
DEPLOY_KEY_DOC_URL("https://docs.github.com/en/developers/overview/managing-deploy-keys");
private final String docUrl;
ErrorReferenceDocUrl(String docUrl) {
this.docUrl = docUrl;
}
public String getDocUrl() { return this.docUrl;}
}

View File

@ -1,5 +0,0 @@
package com.appsmith.server.constants;
public class GitConstants {
public final static String DEPLOY_KEY_DOC_URL = "https://docs.github.com/en/developers/overview/managing-deploy-keys";
}

View File

@ -14,6 +14,7 @@ import com.appsmith.server.dtos.ApplicationImportDTO;
import com.appsmith.server.dtos.GitCommitDTO;
import com.appsmith.server.dtos.GitConnectDTO;
import com.appsmith.server.dtos.GitDeployKeyDTO;
import com.appsmith.server.dtos.GitDocsDTO;
import com.appsmith.server.dtos.GitMergeDTO;
import com.appsmith.server.dtos.GitPullDTO;
import com.appsmith.server.dtos.ResponseDTO;
@ -35,6 +36,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
@ -227,11 +230,17 @@ public class GitControllerCE {
.map(result -> new ResponseDTO<>((HttpStatus.OK.value()), result, null));
}
@GetMapping("/protocol/keys")
@GetMapping("/protocol/key-types")
public Mono<ResponseDTO<List<GitDeployKeyDTO>>> getSupportedKeys() {
log.debug("Going to list the list of supported keys");
return Mono.just(GitDeployKeyGenerator.getSupportedProtocols())
.map(gitDeployKeyDTOS -> new ResponseDTO<>(HttpStatus.OK.value(), gitDeployKeyDTOS, null));
}
@GetMapping("/doc-urls")
public Mono<ResponseDTO<List<GitDocsDTO>>> getGitDocs() {
return service.getGitDocUrls()
.map(gitDocDTO -> new ResponseDTO<>(HttpStatus.OK.value(), gitDocDTO, null));
}
}

View File

@ -0,0 +1,13 @@
package com.appsmith.server.dtos;
import com.appsmith.external.constants.ErrorReferenceDocUrl;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class GitDocsDTO {
ErrorReferenceDocUrl docKey;
String docUrl;
}

View File

@ -79,12 +79,12 @@ public enum AppsmithError {
INVALID_CURL_COMMAND(400, 4029, "Invalid cURL command, couldn't import.", AppsmithErrorAction.DEFAULT, null, ErrorType.ARGUMENT_ERROR, null),
INVALID_LOGIN_METHOD(401, 4030, "Please use {0} authentication to login to Appsmith", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR, null),
INVALID_GIT_CONFIGURATION(400, 4031, "Git configuration is invalid. Details: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, null),
INVALID_GIT_SSH_CONFIGURATION(400, 4032, "SSH Key is not configured properly. Did you forget to add SSH key to remote? Can you please try again by reconfiguring the SSH key with write access", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, ErrorReferenceDocUrl.GIT_DEPLOY_KEY),
INVALID_GIT_SSH_CONFIGURATION(400, 4032, "SSH Key is not configured properly. Did you forget to add SSH key to remote? Can you please try again by reconfiguring the SSH key with write access", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, ErrorReferenceDocUrl.GIT_DEPLOY_KEY.getDocUrl()),
INVALID_GIT_REPO(400, 4033, "The remote repo is not empty. Please create a new empty repo and configure the SSH keys. " +
"If you want to clone from remote repo and build application, please use import application from git option.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, null),
DEFAULT_RESOURCES_UNAVAILABLE(400, 4034, "Unexpected state. Default resources are unavailable for {0} with id {1}. Please reach out to Appsmith customer support to resolve this.",
AppsmithErrorAction.LOG_EXTERNALLY, null, ErrorType.BAD_REQUEST, null),
GIT_MERGE_FAILED_REMOTE_CHANGES(406, 4036, "Remote is ahead of local by {0} commits on branch {1}. Please pull remote changes first and try again.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_UPSTREAM_CHANGES),
GIT_MERGE_FAILED_REMOTE_CHANGES(406, 4036, "Remote is ahead of local by {0} commits on branch {1}. Please pull remote changes first and try again.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_UPSTREAM_CHANGES.getDocUrl()),
GIT_MERGE_FAILED_LOCAL_CHANGES(406, 4037, "There are uncommitted changes present in your local branch {0}. Please commit them first and try again", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, null),
REMOVE_LAST_WORKSPACE_ADMIN_ERROR(400, 4038, "The last admin can not be removed from an organization", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR, null),
INVALID_CRUD_PAGE_REQUEST(400, 4039, "Unable to process page generation request, {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null),
@ -128,14 +128,14 @@ public enum AppsmithError {
CLOUD_SERVICES_ERROR(500, 5012, "Received error from cloud services {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR, null),
GIT_APPLICATION_LIMIT_ERROR(402, 4043, "You have reached the maximum number of private git repo counts which can be connected to the organization. Please reach out to Appsmith support to opt for commercial plan.", AppsmithErrorAction.DEFAULT, null, ErrorType.EE_FEATURE_ERROR, null),
GIT_ACTION_FAILED(400, 4044, "git {0} failed. \nDetails: {1}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, null),
GIT_FILE_SYSTEM_ERROR(503, 5013, "Error while accessing the file system. {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, ErrorReferenceDocUrl.FILE_PATH_NOT_SET),
GIT_FILE_SYSTEM_ERROR(503, 5013, "Error while accessing the file system. {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, ErrorReferenceDocUrl.FILE_PATH_NOT_SET.getDocUrl()),
GIT_EXECUTION_TIMEOUT(504, 5014, "Git command execution exceeded the maximum allowed time, please contact Appsmith support for more details", AppsmithErrorAction.DEFAULT, null, ErrorType.CONNECTIVITY_ERROR, null),
INCOMPATIBLE_IMPORTED_JSON(400, 4045, "Provided file is incompatible, please upgrade your instance to resolve this conflict.", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null),
GIT_MERGE_CONFLICTS(400, 4046, "Merge conflicts found: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_MERGE_CONFLICT),
GIT_PULL_CONFLICTS(400, 4047, "Merge conflicts found during the pull operation: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_PULL_CONFLICT),
GIT_MERGE_CONFLICTS(400, 4046, "Merge conflicts found: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_MERGE_CONFLICT.getDocUrl()),
GIT_PULL_CONFLICTS(400, 4047, "Merge conflicts found during the pull operation: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_PULL_CONFLICT.getDocUrl()),
SSH_KEY_GENERATION_ERROR(500, 5015, "Failed to generate SSH keys, please contact Appsmith support for more details", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, null),
GIT_GENERIC_ERROR(504, 5016, "Git command execution error: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, null),
GIT_UPSTREAM_CHANGES(400, 4048, "Looks like there are pending upstream changes. To prevent you from losing history, we will pull the changes and push them to your repo.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_UPSTREAM_CHANGES_PUSH_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_UPSTREAM_CHANGES),
GIT_UPSTREAM_CHANGES(400, 4048, "Looks like there are pending upstream changes. To prevent you from losing history, we will pull the changes and push them to your repo.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_UPSTREAM_CHANGES_PUSH_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_UPSTREAM_CHANGES.getDocUrl()),
GENERIC_JSON_IMPORT_ERROR(400, 4049, "Unable to import application in organization {0} with error {1}", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null),
FILE_PART_DATA_BUFFER_ERROR(500, 5017, "Failed to upload file with error: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null),
MIGRATION_ERROR(500, 5018, "This action is already migrated", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR, null),

View File

@ -11,10 +11,12 @@ import com.appsmith.server.domains.GitProfile;
import com.appsmith.server.dtos.GitCommitDTO;
import com.appsmith.server.dtos.GitConnectDTO;
import com.appsmith.server.dtos.ApplicationImportDTO;
import com.appsmith.server.dtos.GitDocsDTO;
import com.appsmith.server.dtos.GitMergeDTO;
import com.appsmith.server.dtos.GitPullDTO;
import reactor.core.publisher.Mono;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
@ -70,4 +72,6 @@ public interface GitServiceCE {
Mono<Application> discardChanges(String defaultApplicationId, String branchName, Boolean doPull);
Mono<List<GitDocsDTO>> getGitDocUrls();
}

View File

@ -26,6 +26,7 @@ import com.appsmith.server.domains.UserData;
import com.appsmith.server.dtos.ApplicationImportDTO;
import com.appsmith.server.dtos.GitCommitDTO;
import com.appsmith.server.dtos.GitConnectDTO;
import com.appsmith.server.dtos.GitDocsDTO;
import com.appsmith.server.dtos.GitMergeDTO;
import com.appsmith.server.dtos.GitPullDTO;
import com.appsmith.server.exceptions.AppsmithError;
@ -69,6 +70,7 @@ import reactor.core.publisher.Mono;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
@ -1764,7 +1766,7 @@ public class GitServiceCEImpl implements GitServiceCE {
mergeStatus.setConflictingFiles(((CheckoutConflictException) error)
.getConflictingPaths());
}
mergeStatus.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT);
mergeStatus.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT.getDocUrl());
return mergeStatus;
});
} catch (GitAPIException | IOException e) {
@ -2180,6 +2182,25 @@ public class GitServiceCEImpl implements GitServiceCE {
);
}
/**
* In some scenarios:
* connect: after loading the modal, keyTypes is not available, so a network call has to be made to ssh-keypair.
* import: cannot make a ssh-keypair call because application Id doesnt exist yet, so API fails.
* @return Git docs urls for all the scenarios, client will cache this data and use it
*/
@Override
public Mono<List<GitDocsDTO>> getGitDocUrls() {
ErrorReferenceDocUrl[] docSet = ErrorReferenceDocUrl.values();
List<GitDocsDTO> gitDocsDTOList = new ArrayList<>();
for(ErrorReferenceDocUrl docUrl : docSet ) {
GitDocsDTO gitDocsDTO = new GitDocsDTO();
gitDocsDTO.setDocKey(docUrl);
gitDocsDTO.setDocUrl(docUrl.getDocUrl());
gitDocsDTOList.add(gitDocsDTO);
}
return Mono.just(gitDocsDTOList);
}
private Mono<Application> deleteApplicationCreatedFromGitImport(String applicationId, String workspaceId, String repoName) {
Path repoSuffix = Paths.get(workspaceId, applicationId, repoName);
return fileUtils.deleteLocalRepo(repoSuffix)