-
Notifications
You must be signed in to change notification settings - Fork 429
/
v2_project.go
54 lines (49 loc) · 1.62 KB
/
v2_project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package api
import (
"context"
"net/http"
"net/url"
"github.com/gorilla/mux"
"github.com/ovh/cds/engine/api/database/gorpmapping"
"github.com/ovh/cds/engine/api/repository"
"github.com/ovh/cds/engine/service"
"github.com/ovh/cds/sdk"
)
// getAllRepositoriesHandler Get all repositories
func (api *API) getAllRepositoriesHandler() ([]service.RbacChecker, service.Handler) {
return service.RBAC(api.isHookService),
func(ctx context.Context, w http.ResponseWriter, req *http.Request) error {
repos, err := repository.LoadAllRepositories(ctx, api.mustDB())
if err != nil {
return err
}
return service.WriteJSON(w, repos, http.StatusOK)
}
}
func (api *API) getRepositoryHookHandler() ([]service.RbacChecker, service.Handler) {
return service.RBAC(api.isHookService),
func(ctx context.Context, w http.ResponseWriter, req *http.Request) error {
vars := mux.Vars(req)
repoIdentifier, err := url.PathUnescape(vars["repositoryIdentifier"])
if err != nil {
return sdk.NewErrorWithStack(
err,
sdk.NewErrorFrom(sdk.ErrWrongRequest, "invalid given repository identifier"),
)
}
if !sdk.IsValidUUID(repoIdentifier) {
return sdk.NewErrorFrom(sdk.ErrWrongRequest, "this handler needs the repository uuid")
}
repo, err := repository.LoadRepositoryByID(ctx, api.mustDB(), repoIdentifier, gorpmapping.GetOptions.WithDecryption)
if err != nil {
return err
}
h := sdk.Hook{
HookSignKey: repo.HookSignKey,
UUID: repo.ID,
HookType: sdk.RepositoryEntitiesHook,
Configuration: repo.HookConfiguration,
}
return service.WriteJSON(w, h, http.StatusOK)
}
}