Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish generating the ssh URL #56

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| `gitUserPassword` | `string` | `"git"` | 用于保存 `git` 仓库的用户密码。 |
| `gitRepositoryDirectory` | `string` | `"/home/git/repository"` | `git` 仓库存放目录。不要使用 `~`。 |
| `gitServerDomain` | `string` | `"localhost"` | 服务器域名。 |
| `gitServerPort` | `int` | `22` | 服务器端口。 |
| `gitRepositorySuffix` | `string` | `".git"` | `git` 仓库后缀。 |
| `deployWithDocker` | `bool` | `true` | 是否使用 `Docker` 进行部署。 |
| `dockerName` | `string` | `"gcs-backend"` | `Docker` 容器名称。 |
Expand Down
3 changes: 2 additions & 1 deletion config_debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"postgresqlUserPassword": "gcs_debug",
"postgresqlDatabaseName": "gcs_debug",
"deleteGitUser": false,
"deleteServiceUser": false
"deleteServiceUser": false,
"md5Salt": "Is that the best you can do?"
}
1 change: 1 addition & 0 deletions config_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"gitUserPassword": "git",
"gitRepositoryDirectory": "/home/git/repository",
"gitServerDomain": "localhost",
"gitServerPort": 22,
"gitRepositorySuffix": ".git",
"deployWithDocker": true,
"dockerName": "gcs-back-end",
Expand Down
6 changes: 3 additions & 3 deletions database/trigger/all_table_trigger.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ CREATE TRIGGER update_t_user_gmt_updated
BEFORE UPDATE ON public.t_user
FOR EACH ROW EXECUTE FUNCTION public.update_gmt_updated_column();

-- The trigger of the t_user_repository table is added.
CREATE TRIGGER update_t_user_repository_gmt_updated
BEFORE UPDATE ON public.t_user_repository
-- The trigger of the t_user_star_repository table is added.
CREATE TRIGGER update_t_user_star_repository_gmt_updated
BEFORE UPDATE ON public.t_user_star_repository
FOR EACH ROW EXECUTE FUNCTION public.update_gmt_updated_column();

-- The trigger of the t_ssh_key table is added.
Expand Down
1 change: 1 addition & 0 deletions script/deploy_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def write_other_config(config):
other_config_map = {
"frontEndUrl": "front-end.url",
"gitServerDomain": "git.server.domain",
"gitServerPort": "git.server.port",
"gitUserName": "git.user.name",
"gitHomeDirectory": "git.home.directory",
"gitRepositoryDirectory": "git.repository.directory",
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/edu/cmipt/gcs/constant/GitConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class GitConstant {

public static String GIT_SERVER_DOMAIN;

public static String GIT_SERVER_PORT;

public static final String SSH_KEY_PREFIX =
"no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ";

Expand Down Expand Up @@ -42,4 +44,9 @@ public void setGIT_REPOSITORY_SUFFIX(String gitRepositorySuffix) {
public void setGIT_SERVER_DOMAIN(String gitServerDomain) {
GitConstant.GIT_SERVER_DOMAIN = gitServerDomain;
}

@Value("${git.server.port}")
public void setGIT_SERVER_PORT(String gitServerPort) {
GitConstant.GIT_SERVER_PORT = gitServerPort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void createRepository(
"private repository is not implemented");
}
String userId = JwtUtil.getId(accessToken);
RepositoryPO repositoryPO = new RepositoryPO(repository, userId);
RepositoryPO repositoryPO = new RepositoryPO(repository, userId, true);
QueryWrapper<RepositoryPO> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", repositoryPO.getUserId());
queryWrapper.eq("repository_name", repositoryPO.getRepositoryName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public record RepositoryDTO(
"REPOSITORYDTO_REPOSITORYDESCRIPTION_SIZE"
+ " {RepositoryDTO.repositoryDescription.Size}")
String repositoryDescription,
@Schema(description = "Whether or Not Private Repo") Boolean isPrivate,
@Schema(description = "Whether or Not Private Repo", example = "false") Boolean isPrivate,
@Schema(description = "Star Count")
@Null(
groups = CreateGroup.class,
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/edu/cmipt/gcs/pojo/repository/RepositoryPO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;

import edu.cmipt.gcs.constant.GitConstant;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.nio.file.Paths;
import java.time.LocalDateTime;

@Data
Expand All @@ -20,11 +23,13 @@ public class RepositoryPO {
private Integer star;
private Integer fork;
private Integer watcher;
private String httpsUrl;
private String sshUrl;
private LocalDateTime gmtCreated;
private LocalDateTime gmtUpdated;
@TableLogic private LocalDateTime gmtDeleted;

public RepositoryPO(RepositoryDTO repositoryDTO, String userId) {
public RepositoryPO(RepositoryDTO repositoryDTO, String userId, boolean generateUrl) {
try {
this.id = Long.valueOf(repositoryDTO.id());
} catch (NumberFormatException e) {
Expand All @@ -44,9 +49,32 @@ public RepositoryPO(RepositoryDTO repositoryDTO, String userId) {
this.star = repositoryDTO.star();
this.fork = repositoryDTO.fork();
this.watcher = repositoryDTO.watcher();
if (generateUrl) {
// TODO: https is not supported now
this.httpsUrl = "";
this.sshUrl =
new StringBuilder("ssh://")
.append(GitConstant.GIT_USER_NAME)
.append("@")
.append(GitConstant.GIT_SERVER_DOMAIN)
.append(":")
.append(GitConstant.GIT_SERVER_PORT)
.append(
Paths.get(
GitConstant.GIT_REPOSITORY_DIRECTORY,
userId.toString(),
repositoryName
+ GitConstant.GIT_REPOSITORY_SUFFIX)
.toString())
.toString();
}
}

public RepositoryPO(RepositoryDTO repositoryDTO, String userId) {
this(repositoryDTO, userId, false);
}

public RepositoryPO(RepositoryDTO repositoryDTO) {
this(repositoryDTO, null);
this(repositoryDTO, null, false);
}
}
8 changes: 6 additions & 2 deletions src/main/java/edu/cmipt/gcs/pojo/repository/RepositoryVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public record RepositoryVO(
@Schema(description = "Owner ID") Long userId,
@Schema(description = "Star Count") Integer star,
@Schema(description = "Fork Count") Integer fork,
@Schema(description = "Watcher Count") Integer watcher) {
@Schema(description = "Watcher Count") Integer watcher,
@Schema(description = "HTTPS URL") String httpsUrl,
@Schema(description = "SSH URL") String sshUrl) {
public RepositoryVO(RepositoryPO repositoryPO) {
this(
repositoryPO.getId().toString(),
Expand All @@ -20,6 +22,8 @@ public RepositoryVO(RepositoryPO repositoryPO) {
repositoryPO.getUserId(),
repositoryPO.getStar(),
repositoryPO.getFork(),
repositoryPO.getWatcher());
repositoryPO.getWatcher(),
repositoryPO.getHttpsUrl(),
repositoryPO.getSshUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

import edu.cmipt.gcs.constant.GitConstant;
import edu.cmipt.gcs.dao.RepositoryMapper;
import edu.cmipt.gcs.dao.UserMapper;
import edu.cmipt.gcs.enumeration.ErrorCodeEnum;
import edu.cmipt.gcs.exception.GenericException;
import edu.cmipt.gcs.pojo.repository.RepositoryPO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -24,8 +22,6 @@ public class RepositoryServiceImpl extends ServiceImpl<RepositoryMapper, Reposit
implements RepositoryService {
private static final Logger logger = LoggerFactory.getLogger(RepositoryServiceImpl.class);

@Autowired private UserMapper userMapper;

/**
* Save a repository and initialize a git repository in the file system.
*
Expand Down Expand Up @@ -81,7 +77,6 @@ public boolean save(RepositoryPO repositoryPO) {
ErrorCodeEnum.REPOSITORY_CREATE_FAILED,
process.errorReader().lines().toList().toString());
}
// TODO: add url in the repositoryPO
} catch (Exception e) {
throw new GenericException(ErrorCodeEnum.REPOSITORY_CREATE_FAILED, e.getMessage());
}
Expand Down
Loading