mirror of
https://github.com/harness/drone.git
synced 2025-04-27 13:13:07 +00:00
[MAINT] added repos endpoints to swagger (#33)
* added repos endpoints * todo comments removed in create repo method
This commit is contained in:
parent
91a75ed601
commit
2b69b3d24a
@ -38,7 +38,8 @@ type CreateInput struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new repository.
|
// Create creates a new repository.
|
||||||
//nolint:funlen,goimports // needs refactor
|
//
|
||||||
|
//nolint:funlen // needs refactor
|
||||||
func (c *Controller) Create(ctx context.Context, session *auth.Session, in *CreateInput) (*types.Repository, error) {
|
func (c *Controller) Create(ctx context.Context, session *auth.Session, in *CreateInput) (*types.Repository, error) {
|
||||||
log := zerolog.Ctx(ctx)
|
log := zerolog.Ctx(ctx)
|
||||||
// ensure we reference a space
|
// ensure we reference a space
|
||||||
@ -100,8 +101,7 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea
|
|||||||
}
|
}
|
||||||
|
|
||||||
if in.License != "" && in.License != "none" {
|
if in.License != "" && in.License != "none" {
|
||||||
// TODO: The caller shouldn't need to know the actual location.
|
content, err = resources.ReadLicense(in.License)
|
||||||
content, err = resources.Licence.ReadFile(fmt.Sprintf("license/%s.txt", in.License))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -112,8 +112,7 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea
|
|||||||
}
|
}
|
||||||
|
|
||||||
if in.GitIgnore != "" {
|
if in.GitIgnore != "" {
|
||||||
// TODO: The caller shouldn't need to know the actual location.
|
content, err = resources.ReadGitIgnore(in.GitIgnore)
|
||||||
content, err = resources.Gitignore.ReadFile(fmt.Sprintf("gitignore/%s.gitignore", in.GitIgnore))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -139,7 +138,7 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea
|
|||||||
log.Error().Err(err).
|
log.Error().Err(err).
|
||||||
Msg("Repository creation failed.")
|
Msg("Repository creation failed.")
|
||||||
|
|
||||||
// TODO: cleanup git repo!
|
// TODO: cleanup git repo!
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ package repo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/harness/gitness/internal/api/render"
|
"github.com/harness/gitness/internal/api/render"
|
||||||
"github.com/harness/gitness/resources"
|
"github.com/harness/gitness/resources"
|
||||||
@ -14,22 +13,18 @@ import (
|
|||||||
|
|
||||||
func HandleGitIgnore() http.HandlerFunc {
|
func HandleGitIgnore() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
entries, err := resources.Gitignore.ReadDir("gitignore")
|
files, err := resources.GitIgnores()
|
||||||
files := make([]string, len(entries))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.ErrorMessagef(w, http.StatusInternalServerError, "error loading gitignore files: %v", err)
|
render.ErrorMessagef(w, http.StatusInternalServerError, "error loading gitignore files: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i, filename := range entries {
|
|
||||||
files[i] = strings.ReplaceAll(filename.Name(), ".gitignore", "")
|
|
||||||
}
|
|
||||||
render.JSON(w, http.StatusOK, files)
|
render.JSON(w, http.StatusOK, files)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleLicence() http.HandlerFunc {
|
func HandleLicence() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
response, err := resources.Licence.ReadFile("licence/index.json")
|
response, err := resources.Licenses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.ErrorMessagef(w, http.StatusInternalServerError, "error loading licence file: %v", err)
|
render.ErrorMessagef(w, http.StatusInternalServerError, "error loading licence file: %v", err)
|
||||||
return
|
return
|
||||||
|
@ -13,9 +13,7 @@ import (
|
|||||||
"github.com/harness/gitness/internal/api/request"
|
"github.com/harness/gitness/internal/api/request"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
// HandleCreate returns an http.HandlerFunc that creates a new space.
|
||||||
* HandleCreate returns an http.HandlerFunc that creates a new space.
|
|
||||||
*/
|
|
||||||
func HandleCreate(spaceCtrl *space.Controller) http.HandlerFunc {
|
func HandleCreate(spaceCtrl *space.Controller) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
@ -13,9 +13,7 @@ import (
|
|||||||
"github.com/harness/gitness/internal/api/request"
|
"github.com/harness/gitness/internal/api/request"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
// HandleCreatePath writes json-encoded path information to the http response body.
|
||||||
* Writes json-encoded path information to the http response body.
|
|
||||||
*/
|
|
||||||
func HandleCreatePath(spaceCtrl *space.Controller) http.HandlerFunc {
|
func HandleCreatePath(spaceCtrl *space.Controller) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
@ -13,9 +13,7 @@ import (
|
|||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
// HandleListPaths writes json-encoded path information to the http response body.
|
||||||
* Writes json-encoded path information to the http response body.
|
|
||||||
*/
|
|
||||||
func HandleListPaths(spaceCtrl *space.Controller) http.HandlerFunc {
|
func HandleListPaths(spaceCtrl *space.Controller) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
@ -12,9 +12,7 @@ import (
|
|||||||
"github.com/harness/gitness/internal/api/request"
|
"github.com/harness/gitness/internal/api/request"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
// HandleListServiceAccounts Writes json-encoded service account information to the http response body.
|
||||||
* Writes json-encoded service account information to the http response body.
|
|
||||||
*/
|
|
||||||
func HandleListServiceAccounts(spaceCtrl *space.Controller) http.HandlerFunc {
|
func HandleListServiceAccounts(spaceCtrl *space.Controller) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
@ -13,9 +13,7 @@ import (
|
|||||||
"github.com/harness/gitness/internal/api/request"
|
"github.com/harness/gitness/internal/api/request"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
// HandleUpdate updates an existing space.
|
||||||
* Updates an existing space.
|
|
||||||
*/
|
|
||||||
func HandleUpdate(spaceCtrl *space.Controller) http.HandlerFunc {
|
func HandleUpdate(spaceCtrl *space.Controller) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
@ -41,6 +41,8 @@ func Generate() *openapi3.Spec {
|
|||||||
buildAccount(&reflector)
|
buildAccount(&reflector)
|
||||||
buildUser(&reflector)
|
buildUser(&reflector)
|
||||||
buildUsers(&reflector)
|
buildUsers(&reflector)
|
||||||
|
spaceOperations(&reflector)
|
||||||
|
repoOperations(&reflector)
|
||||||
|
|
||||||
//
|
//
|
||||||
// define security scheme
|
// define security scheme
|
||||||
|
174
internal/api/openapi/repo.go
Normal file
174
internal/api/openapi/repo.go
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
// Copyright 2022 Harness Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Polyform Free Trial License
|
||||||
|
// that can be found in the LICENSE.md file for this repository.
|
||||||
|
|
||||||
|
package openapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/harness/gitness/internal/api/controller/repo"
|
||||||
|
"github.com/harness/gitness/internal/api/usererror"
|
||||||
|
"github.com/harness/gitness/types"
|
||||||
|
"github.com/swaggest/openapi-go/openapi3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type createRepositoryRequest struct {
|
||||||
|
repo.CreateInput
|
||||||
|
}
|
||||||
|
|
||||||
|
type gitignoreRequest struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type licenseRequest struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type repoRequest struct {
|
||||||
|
Ref string `json:"ref" path:"ref"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type updateRepoRequest struct {
|
||||||
|
repoRequest
|
||||||
|
repo.UpdateInput
|
||||||
|
}
|
||||||
|
|
||||||
|
type moveRepoRequest struct {
|
||||||
|
repoRequest
|
||||||
|
repo.MoveInput
|
||||||
|
}
|
||||||
|
|
||||||
|
type createRepoPathRequest struct {
|
||||||
|
repoRequest
|
||||||
|
repo.CreatePathInput
|
||||||
|
}
|
||||||
|
|
||||||
|
type deleteRepoPathRequest struct {
|
||||||
|
repoRequest
|
||||||
|
PathID string `json:"pathID" path:"pathID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//nolint:funlen
|
||||||
|
func repoOperations(reflector *openapi3.Reflector) {
|
||||||
|
createRepository := openapi3.Operation{}
|
||||||
|
createRepository.WithTags("repository")
|
||||||
|
createRepository.WithMapOfAnything(map[string]interface{}{"operationId": "createRepository"})
|
||||||
|
_ = reflector.SetRequest(&createRepository, new(createRepositoryRequest), http.MethodPost)
|
||||||
|
_ = reflector.SetJSONResponse(&createRepository, new(types.Repository), http.StatusCreated)
|
||||||
|
_ = reflector.SetJSONResponse(&createRepository, new(usererror.Error), http.StatusBadRequest)
|
||||||
|
_ = reflector.SetJSONResponse(&createRepository, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&createRepository, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&createRepository, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos", createRepository)
|
||||||
|
|
||||||
|
opListGitignore := openapi3.Operation{}
|
||||||
|
opListGitignore.WithTags("repository")
|
||||||
|
opListGitignore.WithMapOfAnything(map[string]interface{}{"operationId": "listGitignore"})
|
||||||
|
_ = reflector.SetRequest(&opListGitignore, new(gitignoreRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opListGitignore, []string{}, http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opListGitignore, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opListGitignore, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opListGitignore, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/resources/gitignore", opListGitignore)
|
||||||
|
|
||||||
|
opListLicenses := openapi3.Operation{}
|
||||||
|
opListLicenses.WithTags("repository")
|
||||||
|
opListLicenses.WithMapOfAnything(map[string]interface{}{"operationId": "listLicenses"})
|
||||||
|
_ = reflector.SetRequest(&opListLicenses, new(licenseRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opListLicenses, []struct {
|
||||||
|
Label string `json:"label"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}{}, http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opListLicenses, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opListLicenses, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opListLicenses, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/resources/license", opListLicenses)
|
||||||
|
|
||||||
|
opFind := openapi3.Operation{}
|
||||||
|
opFind.WithTags("repository")
|
||||||
|
opFind.WithMapOfAnything(map[string]interface{}{"operationId": "findRepository"})
|
||||||
|
_ = reflector.SetRequest(&opFind, new(repoRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opFind, new(types.Repository), http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opFind, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opFind, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opFind, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opFind, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{ref}", opFind)
|
||||||
|
|
||||||
|
opUpdate := openapi3.Operation{}
|
||||||
|
opUpdate.WithTags("repository")
|
||||||
|
opUpdate.WithMapOfAnything(map[string]interface{}{"operationId": "updateRepository"})
|
||||||
|
_ = reflector.SetRequest(&opUpdate, new(updateRepoRequest), http.MethodPatch)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(types.Repository), http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusBadRequest)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodPatch, "/repos/{ref}", opUpdate)
|
||||||
|
|
||||||
|
opDelete := openapi3.Operation{}
|
||||||
|
opDelete.WithTags("repository")
|
||||||
|
opDelete.WithMapOfAnything(map[string]interface{}{"operationId": "deleteRepository"})
|
||||||
|
_ = reflector.SetRequest(&opDelete, new(repoRequest), http.MethodDelete)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, nil, http.StatusNoContent)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodDelete, "/repos/{ref}", opDelete)
|
||||||
|
|
||||||
|
opMove := openapi3.Operation{}
|
||||||
|
opMove.WithTags("repository")
|
||||||
|
opMove.WithMapOfAnything(map[string]interface{}{"operationId": "moveRepository"})
|
||||||
|
_ = reflector.SetRequest(&opMove, new(moveRepoRequest), http.MethodPost)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(types.Repository), http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(usererror.Error), http.StatusBadRequest)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{ref}/move", opMove)
|
||||||
|
|
||||||
|
opServiceAccounts := openapi3.Operation{}
|
||||||
|
opServiceAccounts.WithTags("repository")
|
||||||
|
opServiceAccounts.WithMapOfAnything(map[string]interface{}{"operationId": "listRepositoryServiceAccounts"})
|
||||||
|
_ = reflector.SetRequest(&opServiceAccounts, new(repoRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, []types.ServiceAccount{}, http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{ref}/serviceAccounts", opServiceAccounts)
|
||||||
|
|
||||||
|
opListPaths := openapi3.Operation{}
|
||||||
|
opListPaths.WithTags("repository")
|
||||||
|
opListPaths.WithMapOfAnything(map[string]interface{}{"operationId": "listRepositoryPaths"})
|
||||||
|
_ = reflector.SetRequest(&opListPaths, new(repoRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, []types.Path{}, http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{ref}/paths", opListPaths)
|
||||||
|
|
||||||
|
opCreatePath := openapi3.Operation{}
|
||||||
|
opCreatePath.WithTags("repository")
|
||||||
|
opCreatePath.WithMapOfAnything(map[string]interface{}{"operationId": "createRepositoryPath"})
|
||||||
|
_ = reflector.SetRequest(&opCreatePath, new(createRepoPathRequest), http.MethodPost)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(types.Path), http.StatusCreated)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(usererror.Error), http.StatusBadRequest)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{ref}/paths", opCreatePath)
|
||||||
|
|
||||||
|
onDeletePath := openapi3.Operation{}
|
||||||
|
onDeletePath.WithTags("repository")
|
||||||
|
onDeletePath.WithMapOfAnything(map[string]interface{}{"operationId": "deleteRepositoryPath"})
|
||||||
|
_ = reflector.SetRequest(&onDeletePath, new(deleteRepoPathRequest), http.MethodDelete)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, nil, http.StatusNoContent)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodDelete, "/repos/{ref}/paths/{pathID}", onDeletePath)
|
||||||
|
}
|
167
internal/api/openapi/space.go
Normal file
167
internal/api/openapi/space.go
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
// Copyright 2022 Harness Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Polyform Free Trial License
|
||||||
|
// that can be found in the LICENSE.md file for this repository.
|
||||||
|
|
||||||
|
package openapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/harness/gitness/internal/api/controller/space"
|
||||||
|
"github.com/harness/gitness/internal/api/usererror"
|
||||||
|
"github.com/harness/gitness/types"
|
||||||
|
"github.com/swaggest/openapi-go/openapi3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type createSpaceRequest struct {
|
||||||
|
space.CreateInput
|
||||||
|
}
|
||||||
|
|
||||||
|
type spaceRequest struct {
|
||||||
|
Ref string `json:"ref" path:"ref"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type updateSpaceRequest struct {
|
||||||
|
spaceRequest
|
||||||
|
space.UpdateInput
|
||||||
|
}
|
||||||
|
|
||||||
|
type moveSpaceRequest struct {
|
||||||
|
spaceRequest
|
||||||
|
space.MoveInput
|
||||||
|
}
|
||||||
|
|
||||||
|
type createPathRequest struct {
|
||||||
|
spaceRequest
|
||||||
|
space.CreatePathInput
|
||||||
|
}
|
||||||
|
|
||||||
|
type deletePathRequest struct {
|
||||||
|
spaceRequest
|
||||||
|
PathID string `json:"pathID" path:"pathID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//nolint:funlen // api spec generation no need for checking func complexity
|
||||||
|
func spaceOperations(reflector *openapi3.Reflector) {
|
||||||
|
opCreate := openapi3.Operation{}
|
||||||
|
opCreate.WithTags("space")
|
||||||
|
opCreate.WithMapOfAnything(map[string]interface{}{"operationId": "createSpace"})
|
||||||
|
_ = reflector.SetRequest(&opCreate, new(createSpaceRequest), http.MethodPost)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreate, new(types.Space), http.StatusCreated)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreate, new(usererror.Error), http.StatusBadRequest)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreate, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreate, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreate, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces", opCreate)
|
||||||
|
|
||||||
|
opGet := openapi3.Operation{}
|
||||||
|
opGet.WithTags("space")
|
||||||
|
opGet.WithMapOfAnything(map[string]interface{}{"operationId": "getSpace"})
|
||||||
|
_ = reflector.SetRequest(&opGet, new(spaceRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opGet, new(types.Space), http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opGet, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opGet, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opGet, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opGet, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{ref}", opGet)
|
||||||
|
|
||||||
|
opUpdate := openapi3.Operation{}
|
||||||
|
opUpdate.WithTags("space")
|
||||||
|
opUpdate.WithMapOfAnything(map[string]interface{}{"operationId": "updateSpace"})
|
||||||
|
_ = reflector.SetRequest(&opUpdate, new(updateSpaceRequest), http.MethodPatch)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(types.Space), http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusBadRequest)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodPatch, "/spaces/{ref}", opUpdate)
|
||||||
|
|
||||||
|
opDelete := openapi3.Operation{}
|
||||||
|
opDelete.WithTags("space")
|
||||||
|
opDelete.WithMapOfAnything(map[string]interface{}{"operationId": "deleteSpace"})
|
||||||
|
_ = reflector.SetRequest(&opDelete, new(spaceRequest), http.MethodDelete)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, nil, http.StatusNoContent)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opDelete, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodDelete, "/spaces/{ref}", opDelete)
|
||||||
|
|
||||||
|
opMove := openapi3.Operation{}
|
||||||
|
opMove.WithTags("space")
|
||||||
|
opMove.WithMapOfAnything(map[string]interface{}{"operationId": "moveSpace"})
|
||||||
|
_ = reflector.SetRequest(&opMove, new(moveSpaceRequest), http.MethodPost)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(types.Space), http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(usererror.Error), http.StatusBadRequest)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opMove, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{ref}/move", opMove)
|
||||||
|
|
||||||
|
opSpaces := openapi3.Operation{}
|
||||||
|
opSpaces.WithTags("space")
|
||||||
|
opSpaces.WithMapOfAnything(map[string]interface{}{"operationId": "listSpaces"})
|
||||||
|
_ = reflector.SetRequest(&opSpaces, new(spaceRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opSpaces, []types.Space{}, http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opSpaces, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opSpaces, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opSpaces, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opSpaces, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{ref}/spaces", opSpaces)
|
||||||
|
|
||||||
|
opRepos := openapi3.Operation{}
|
||||||
|
opRepos.WithTags("space")
|
||||||
|
opRepos.WithMapOfAnything(map[string]interface{}{"operationId": "listRepos"})
|
||||||
|
_ = reflector.SetRequest(&opRepos, new(spaceRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opRepos, []types.Repository{}, http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opRepos, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opRepos, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opRepos, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opRepos, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{ref}/repos", opRepos)
|
||||||
|
|
||||||
|
opServiceAccounts := openapi3.Operation{}
|
||||||
|
opServiceAccounts.WithTags("space")
|
||||||
|
opServiceAccounts.WithMapOfAnything(map[string]interface{}{"operationId": "listServiceAccounts"})
|
||||||
|
_ = reflector.SetRequest(&opServiceAccounts, new(spaceRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, []types.ServiceAccount{}, http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opServiceAccounts, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{ref}/serviceAccounts", opServiceAccounts)
|
||||||
|
|
||||||
|
opListPaths := openapi3.Operation{}
|
||||||
|
opListPaths.WithTags("space")
|
||||||
|
opListPaths.WithMapOfAnything(map[string]interface{}{"operationId": "listPaths"})
|
||||||
|
_ = reflector.SetRequest(&opListPaths, new(spaceRequest), http.MethodGet)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, []types.Path{}, http.StatusOK)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&opListPaths, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{ref}/paths", opListPaths)
|
||||||
|
|
||||||
|
opCreatePath := openapi3.Operation{}
|
||||||
|
opCreatePath.WithTags("space")
|
||||||
|
opCreatePath.WithMapOfAnything(map[string]interface{}{"operationId": "createPath"})
|
||||||
|
_ = reflector.SetRequest(&opCreatePath, new(createPathRequest), http.MethodPost)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(types.Path), http.StatusCreated)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(usererror.Error), http.StatusBadRequest)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&opCreatePath, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{ref}/paths", opCreatePath)
|
||||||
|
|
||||||
|
onDeletePath := openapi3.Operation{}
|
||||||
|
onDeletePath.WithTags("space")
|
||||||
|
onDeletePath.WithMapOfAnything(map[string]interface{}{"operationId": "deletePath"})
|
||||||
|
_ = reflector.SetRequest(&onDeletePath, new(deletePathRequest), http.MethodDelete)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, nil, http.StatusNoContent)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, new(usererror.Error), http.StatusInternalServerError)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, new(usererror.Error), http.StatusUnauthorized)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, new(usererror.Error), http.StatusForbidden)
|
||||||
|
_ = reflector.SetJSONResponse(&onDeletePath, new(usererror.Error), http.StatusNotFound)
|
||||||
|
_ = reflector.Spec.AddOperation(http.MethodDelete, "/spaces/{ref}/paths/{pathID}", onDeletePath)
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.27.1
|
// protoc-gen-go v1.28.1
|
||||||
// protoc v3.19.4
|
// protoc v3.21.7
|
||||||
// source: repo.proto
|
// source: repo.proto
|
||||||
|
|
||||||
package rpc
|
package rpc
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.2.0
|
// - protoc-gen-go-grpc v1.2.0
|
||||||
// - protoc v3.19.4
|
// - protoc v3.21.7
|
||||||
// source: repo.proto
|
// source: repo.proto
|
||||||
|
|
||||||
package rpc
|
package rpc
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.27.1
|
// protoc-gen-go v1.28.1
|
||||||
// protoc v3.19.4
|
// protoc v3.21.7
|
||||||
// source: shared.proto
|
// source: shared.proto
|
||||||
|
|
||||||
package rpc
|
package rpc
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
// Use of this source code is governed by the Polyform Free Trial License
|
// Use of this source code is governed by the Polyform Free Trial License
|
||||||
// that can be found in the LICENSE.md file for this repository.
|
// that can be found in the LICENSE.md file for this repository.
|
||||||
|
|
||||||
// Package router provides http handlers for serving the
|
// Package request provides http handlers for serving the
|
||||||
// web applicationa and API endpoints.
|
// web applications and API endpoints.
|
||||||
package request
|
package request
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -141,9 +141,10 @@ func setupRepos(r chi.Router, config *types.Config, repoCtrl *repo.Controller) {
|
|||||||
r.Route("/repos", func(r chi.Router) {
|
r.Route("/repos", func(r chi.Router) {
|
||||||
// Create takes path and parentId via body, not uri
|
// Create takes path and parentId via body, not uri
|
||||||
r.Post("/", handlerrepo.HandleCreate(config, repoCtrl))
|
r.Post("/", handlerrepo.HandleCreate(config, repoCtrl))
|
||||||
r.Get("/gitignore", handlerrepo.HandleGitIgnore())
|
r.Route("/resources", func(r chi.Router) {
|
||||||
r.Get("/licence", handlerrepo.HandleLicence())
|
r.Get("/gitignore", handlerrepo.HandleGitIgnore())
|
||||||
|
r.Get("/license", handlerrepo.HandleLicence())
|
||||||
|
})
|
||||||
r.Route(fmt.Sprintf("/{%s}", request.PathParamRepoRef), func(r chi.Router) {
|
r.Route(fmt.Sprintf("/{%s}", request.PathParamRepoRef), func(r chi.Router) {
|
||||||
// repo level operations
|
// repo level operations
|
||||||
r.Get("/", handlerrepo.HandleFind(repoCtrl))
|
r.Get("/", handlerrepo.HandleFind(repoCtrl))
|
||||||
@ -152,8 +153,6 @@ func setupRepos(r chi.Router, config *types.Config, repoCtrl *repo.Controller) {
|
|||||||
|
|
||||||
r.Post("/move", handlerrepo.HandleMove(repoCtrl))
|
r.Post("/move", handlerrepo.HandleMove(repoCtrl))
|
||||||
r.Get("/serviceAccounts", handlerrepo.HandleListServiceAccounts(repoCtrl))
|
r.Get("/serviceAccounts", handlerrepo.HandleListServiceAccounts(repoCtrl))
|
||||||
r.Get("/commits", handlerrepo.HandleListCommits(repoCtrl))
|
|
||||||
r.Get("/content/*", handlerrepo.HandleGetContent(repoCtrl))
|
|
||||||
|
|
||||||
// repo path operations
|
// repo path operations
|
||||||
r.Route("/paths", func(r chi.Router) {
|
r.Route("/paths", func(r chi.Router) {
|
||||||
|
@ -25,9 +25,7 @@ type GitHandler interface {
|
|||||||
http.Handler
|
http.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// NewGitHandler returns a new GitHandler.
|
||||||
* NewGitHandler returns a new GitHandler.
|
|
||||||
*/
|
|
||||||
func NewGitHandler(
|
func NewGitHandler(
|
||||||
repoStore store.RepoStore,
|
repoStore store.RepoStore,
|
||||||
authenticator authn.Authenticator) GitHandler {
|
authenticator authn.Authenticator) GitHandler {
|
||||||
|
@ -8,6 +8,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/harness/gitness/internal/api/openapi"
|
||||||
|
"github.com/harness/gitness/internal/api/render"
|
||||||
|
|
||||||
"github.com/harness/gitness/internal/store"
|
"github.com/harness/gitness/internal/store"
|
||||||
"github.com/harness/gitness/web"
|
"github.com/harness/gitness/web"
|
||||||
"github.com/swaggest/swgui/v3emb"
|
"github.com/swaggest/swgui/v3emb"
|
||||||
@ -51,7 +54,18 @@ func NewWebHandler(systemStore store.SystemStore) WebHandler {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// openapi playground endpoints
|
// openapi playground endpoints
|
||||||
swagger := v3emb.NewHandler("API Definition", "/api/v1/swagger.yaml", "/swagger")
|
r.HandleFunc("/openapi.yaml", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
spec := openapi.Generate()
|
||||||
|
data, err := spec.MarshalYAML()
|
||||||
|
if err != nil {
|
||||||
|
render.ErrorMessagef(w, http.StatusInternalServerError, "error serializing openapi.yaml: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Header().Set("Content-Type", "application/yaml")
|
||||||
|
_, _ = w.Write(data)
|
||||||
|
})
|
||||||
|
swagger := v3emb.NewHandler("API Definition", "/openapi.yaml", "/swagger")
|
||||||
r.With(sec.Handler).Handle("/swagger", swagger)
|
r.With(sec.Handler).Handle("/swagger", swagger)
|
||||||
r.With(sec.Handler).Handle("/swagger/*", swagger)
|
r.With(sec.Handler).Handle("/swagger/*", swagger)
|
||||||
|
|
||||||
|
@ -4,12 +4,48 @@
|
|||||||
|
|
||||||
package resources
|
package resources
|
||||||
|
|
||||||
import "embed"
|
import (
|
||||||
|
"embed"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//go:embed gitignore
|
//go:embed gitignore
|
||||||
Gitignore embed.FS
|
gitignore embed.FS
|
||||||
|
|
||||||
//go:embed license
|
//go:embed license
|
||||||
Licence embed.FS
|
licence embed.FS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Licenses returns map of licences in license folder.
|
||||||
|
func Licenses() ([]byte, error) {
|
||||||
|
return licence.ReadFile("license/index.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadLicense reads licence from license folder.
|
||||||
|
func ReadLicense(name string) ([]byte, error) {
|
||||||
|
content, err := licence.ReadFile(fmt.Sprintf("license/%s.txt", name))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return content, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitIgnores lists all files in gitignore folder and return file names.
|
||||||
|
func GitIgnores() ([]string, error) {
|
||||||
|
entries, err := gitignore.ReadDir("gitignore")
|
||||||
|
files := make([]string, len(entries))
|
||||||
|
if err != nil {
|
||||||
|
return []string{}, err
|
||||||
|
}
|
||||||
|
for i, filename := range entries {
|
||||||
|
files[i] = strings.ReplaceAll(filename.Name(), ".gitignore", "")
|
||||||
|
}
|
||||||
|
return files, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadGitIgnore reads gitignore file from license folder.
|
||||||
|
func ReadGitIgnore(name string) ([]byte, error) {
|
||||||
|
return gitignore.ReadFile(fmt.Sprintf("gitignore/%s.gitignore", name))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user