plumb API for External Repositories

This commit is contained in:
Neil Hanlon 2024-02-28 19:23:47 -05:00
parent 034fe12c0a
commit 84423b25ab
Signed by: neil
GPG Key ID: 705BC21EC3C70F34
3 changed files with 52 additions and 0 deletions

View File

@ -125,6 +125,7 @@ type Access interface {
GetPluginsForProject(projectId string) (models.Plugins, error) GetPluginsForProject(projectId string) (models.Plugins, error)
GetExternalRepositoriesForProject(projectId string) (models.ExternalRepositories, error) GetExternalRepositoriesForProject(projectId string) (models.ExternalRepositories, error)
GetExternalRepository(projectId string, id string) (models.ExternalRepository, error)
DeleteExternalRepositoryForProject(projectId string, externalRepositoryId string) error DeleteExternalRepositoryForProject(projectId string, externalRepositoryId string) error
CreateExternalRepositoryForProject(projectId string, repoURL string, priority *int32, moduleHotfixes bool) (*models.ExternalRepository, error) CreateExternalRepositoryForProject(projectId string, repoURL string, priority *int32, moduleHotfixes bool) (*models.ExternalRepository, error)
FindRepositoriesForPackage(projectId string, pkg string, internalOnly bool) (models.Repositories, error) FindRepositoriesForPackage(projectId string, pkg string, internalOnly bool) (models.Repositories, error)

View File

@ -45,6 +45,16 @@ func (a *Access) GetExternalRepositoriesForProject(projectId string) (ret models
return ret, nil return ret, nil
} }
func (a *Access) GetExternalRepository(projectId string, repoId string) (*models.ExternalRepository, error) {
var r models.ExternalRepository
err := a.query.Select(&r, "select id, created_at, project_id, url, priority, module_hotfixes from external_repositories where project_id = $1 and id = $2 order by created_at desc", projectId, repoId)
if err != nil {
return nil, err
}
return &r, nil
}
func (a *Access) DeleteExternalRepositoryForProject(projectId string, id string) error { func (a *Access) DeleteExternalRepositoryForProject(projectId string, id string) error {
_, err := a.query.Exec("delete from external_repositories where project_id = $1 and id = $2", projectId, id) _, err := a.query.Exec("delete from external_repositories where project_id = $1 and id = $2", projectId, id)
return err return err

View File

@ -236,6 +236,47 @@ func (s *Server) GetRepository(ctx context.Context, req *peridotpb.GetRepository
}, nil }, nil
} }
func (s *Server) ListExternalRepositories(ctx context.Context, req *peridotpb.ListExternalRepositoriesRequest) (*peridotpb.ListExternalRepositoriesResponse, error) {
if err := req.ValidateAll(); err != nil {
return nil, err
}
if err := s.checkPermission(ctx, ObjectProject, req.ProjectId.Value, PermissionView); err != nil {
return nil, err
}
repos, err := s.db.GetExternalRepositoriesForProject(req.ProjectId.Value)
if err != nil {
s.log.Errorf("could not list repositories: %v", err)
return nil, utils.CouldNotRetrieveObjects
}
return &peridotpb.ListExternalRepositoriesResponse {
Repositories: repos.ToProto(),
}, nil
}
func (s *Server) GetExternalRepository(ctx context.Context, req *peridotpb.GetExternalRepositoryRequest) (*peridotpb.GetExternalRepositoryResponse, error) {
if err := req.ValidateAll(); err != nil {
return nil, err
}
if err := s.checkPermission(ctx, ObjectProject, req.ProjectId.Value, PermissionView); err != nil {
return nil, err
}
repos, err := s.db.GetExternalRepositoryForProject(req.ProjectId.Value, &req.Id.Value, false)
if err != nil {
s.log.Errorf("could not list repositories: %v", err)
return nil, utils.CouldNotRetrieveObjects
}
if len(repos) == 0 {
return nil, utils.CouldNotFindObject
}
return &peridotpb.GetRepositoryResponse{
Repository: repos[0].ToProto(),
}, nil
}
func (s *Server) GetProjectCredentials(ctx context.Context, req *peridotpb.GetProjectCredentialsRequest) (*peridotpb.GetProjectCredentialsResponse, error) { func (s *Server) GetProjectCredentials(ctx context.Context, req *peridotpb.GetProjectCredentialsRequest) (*peridotpb.GetProjectCredentialsResponse, error) {
if err := req.ValidateAll(); err != nil { if err := req.ValidateAll(); err != nil {
return nil, err return nil, err