repo stringlengths 6 47 | file_url stringlengths 77 269 | file_path stringlengths 5 186 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-07 08:35:43 2026-01-07 08:55:24 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/rule_create.go | app/api/handler/space/rule_create.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/services/rules"
)
// HandleRuleCreate adds a new protection rule to a space.
func HandleRuleCreate(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(rules.CreateInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
rule, err := spaceCtrl.RuleCreate(ctx, session, spaceRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, rule)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/membership_update.go | app/api/handler/space/membership_update.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleMembershipUpdate handles API that changes the role of an existing space membership.
func HandleMembershipUpdate(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
userUID, err := request.GetUserUIDFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(space.MembershipUpdateInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
memberInfo, err := spaceCtrl.MembershipUpdate(ctx, session, spaceRef, userUID, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, memberInfo)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/list_secrets.go | app/api/handler/space/list_secrets.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/types"
)
func HandleListSecrets(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
filter := request.ParseListQueryFilterFromRequest(r)
ret, totalCount, err := spaceCtrl.ListSecrets(ctx, session, spaceRef, filter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
// Strip out data in the returned value
secrets := []types.Secret{}
for _, s := range ret {
secrets = append(secrets, *s.CopyWithoutData())
}
render.Pagination(r, w, filter.Page, filter.Size, int(totalCount))
render.JSON(w, http.StatusOK, secrets)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/find.go | app/api/handler/space/find.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
/*
* Writes json-encoded space information to the http response body.
*/
func HandleFind(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
space, err := spaceCtrl.Find(ctx, session, spaceRef)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, space)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/label_find.go | app/api/handler/space/label_find.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleFindLabel(labelCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
key, err := request.GetLabelKeyFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
includeValues, err := request.ParseIncludeValuesFromQuery(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
label, err := labelCtrl.FindLabel(ctx, session, spaceRef, key, includeValues)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, label)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/export_progress.go | app/api/handler/space/export_progress.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleExportProgress(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
progress, err := spaceCtrl.ExportProgress(ctx, session, spaceRef)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, progress)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/rule_list.go | app/api/handler/space/rule_list.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleRuleList lists a protection rules of a space.
func HandleRuleList(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
filter := request.ParseRuleFilter(r)
inherited, err := request.ParseInheritedFromQuery(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
}
rules, rulesCount, err := spaceCtrl.RuleList(ctx, session, spaceRef, inherited, filter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.Pagination(r, w, filter.Page, filter.Size, int(rulesCount))
render.JSON(w, http.StatusOK, rules)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/pr_count.go | app/api/handler/space/pr_count.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleCountPullReqs(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
includeSubspaces, err := request.GetIncludeSubspacesFromQuery(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
pullReqFilter, err := request.ParsePullReqFilter(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
count, err := spaceCtrl.CountPullReqs(ctx, session, spaceRef, includeSubspaces, pullReqFilter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, count)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/label_list.go | app/api/handler/space/label_list.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleListLabels(labelCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
filter, err := request.ParseLabelFilter(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
labels, total, err := labelCtrl.ListLabels(ctx, session, spaceRef, filter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.Pagination(r, w, filter.Page, filter.Size, int(total))
render.JSON(w, http.StatusOK, labels)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/list.go | app/api/handler/space/list.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/types/enum"
)
// HandleListSpaces writes json-encoded list of child spaces in the request body.
func HandleListSpaces(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
spaceFilter, err := request.ParseSpaceFilter(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
if spaceFilter.Order == enum.OrderDefault {
spaceFilter.Order = enum.OrderAsc
}
spaces, totalCount, err := spaceCtrl.ListSpaces(ctx, session, spaceRef, spaceFilter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.Pagination(r, w, spaceFilter.Page, spaceFilter.Size, int(totalCount))
render.JSON(w, http.StatusOK, spaces)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/label_delete.go | app/api/handler/space/label_delete.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleDeleteLabel(labelCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
identifier, err := request.GetLabelKeyFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
err = labelCtrl.DeleteLabel(ctx, session, spaceRef, identifier)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.DeleteSuccessful(w)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/label_save.go | app/api/handler/space/label_save.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/types"
)
func HandleSaveLabel(labelCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(types.SaveInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid request body: %s.", err)
return
}
label, err := labelCtrl.SaveLabel(ctx, session, spaceRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, label)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/list_executions.go | app/api/handler/space/list_executions.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleListExecutions(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
filter, err := request.ParseListExecutionsFilterFromRequest(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
executions, totalCount, err := spaceCtrl.ListExecutions(ctx, session, spaceRef, filter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.Pagination(r, w, filter.Page, filter.Size, int(totalCount))
render.JSON(w, http.StatusOK, executions)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/membership_list.go | app/api/handler/space/membership_list.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleMembershipList handles API that lists all memberships of a space.
func HandleMembershipList(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
filter := request.ParseMembershipUserFilter(r)
memberships, membershipsCount, err := spaceCtrl.MembershipList(ctx, session, spaceRef, filter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.Pagination(r, w, filter.Page, filter.Size, int(membershipsCount))
render.JSON(w, http.StatusOK, memberships)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/rule_delete.go | app/api/handler/space/rule_delete.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleRuleDelete deletes a protection rule of a space.
func HandleRuleDelete(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
ruleIdentifier, err := request.GetRuleIdentifierFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
err = spaceCtrl.RuleDelete(ctx, session, spaceRef, ruleIdentifier)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.DeleteSuccessful(w)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/export.go | app/api/handler/space/export.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleExport(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(space.ExportInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
err = spaceCtrl.Export(ctx, session, spaceRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
w.WriteHeader(http.StatusAccepted)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/usage.go | app/api/handler/space/usage.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"time"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleUsageMetric(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
now := time.Now()
start := now.Add(-30 * 24 * time.Hour).UnixMilli()
startDate := request.QueryParamAsUnixMillisOrDefault(
r,
request.QueryParamStartTime,
start,
)
endDate := request.QueryParamAsUnixMillisOrDefault(
r,
request.QueryParamEndTime,
now.UnixMilli(),
)
metric, err := spaceCtrl.GetUsageMetrics(
ctx,
session,
spaceRef,
startDate,
endDate,
)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, metric)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/list_templates.go | app/api/handler/space/list_templates.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleListTemplates(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
filter := request.ParseListQueryFilterFromRequest(r)
ret, totalCount, err := spaceCtrl.ListTemplates(ctx, session, spaceRef, filter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.Pagination(r, w, filter.Page, filter.Size, int(totalCount))
render.JSON(w, http.StatusOK, ret)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/list_infraproviders.go | app/api/handler/space/list_infraproviders.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/infraprovider"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleListInfraProviderConfigs(infraProviderCtrl *infraprovider.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
infraProviderConfigs, err := infraProviderCtrl.List(ctx, session, spaceRef, false)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, infraProviderConfigs)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/pr_list.go | app/api/handler/space/pr_list.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleListPullReqs(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
includeSubspaces, err := request.GetIncludeSubspacesFromQuery(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
pullReqFilter, err := request.ParsePullReqFilter(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
pullreqs, err := spaceCtrl.ListPullReqs(ctx, session, spaceRef, includeSubspaces, pullReqFilter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, pullreqs)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/membership_add.go | app/api/handler/space/membership_add.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleMembershipAdd handles API that adds a new membership to a space.
func HandleMembershipAdd(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(space.MembershipAddInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
memberInfo, err := spaceCtrl.MembershipAdd(ctx, session, spaceRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, memberInfo)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/list_service_accounts.go | app/api/handler/space/list_service_accounts.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleListServiceAccounts Writes json-encoded service account information to the http response body.
func HandleListServiceAccounts(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
filter := request.ParsePrincipalFilter(r)
inherited, err := request.ParseInheritedFromQuery(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
serviceAccountInfos, count, err := spaceCtrl.ListServiceAccounts(
ctx, session, spaceRef, inherited, filter,
)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.Pagination(r, w, filter.Page, filter.Size, int(count))
render.JSON(w, http.StatusOK, serviceAccountInfos)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/membership_delete.go | app/api/handler/space/membership_delete.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleMembershipDelete handles API that deletes an existing space membership.
func HandleMembershipDelete(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
userUID, err := request.GetUserUIDFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
err = spaceCtrl.MembershipDelete(ctx, session, spaceRef, userUID)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.DeleteSuccessful(w)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/update_public_access.go | app/api/handler/space/update_public_access.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleUpdatePublicAccess updates public access mode of an existing space.
func HandleUpdatePublicAccess(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(space.UpdatePublicAccessInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid request body: %s.", err)
return
}
space, err := spaceCtrl.UpdatePublicAccess(ctx, session, spaceRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, space)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/list_gitspaces.go | app/api/handler/space/list_gitspaces.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"net/http"
"strconv"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
const HeaderTotalWithoutFilter = "x-total-no-filter"
func HandleListGitspaces(spacesCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
filter := request.ParseGitspaceFilter(r)
repos, filterCount, totalCount, err := spacesCtrl.ListGitspaces(ctx, session, spaceRef, filter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
w.Header().Set(HeaderTotalWithoutFilter, strconv.FormatInt(totalCount, 10))
render.Pagination(r, w, filter.QueryFilter.Page, filter.QueryFilter.Size, int(filterCount))
render.JSON(w, http.StatusOK, repos)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/label_define.go | app/api/handler/space/label_define.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/types"
)
func HandleDefineLabel(labelCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(types.DefineLabelInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid request body: %s.", err)
return
}
label, err := labelCtrl.DefineLabel(ctx, session, spaceRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, label)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/events.go | app/api/handler/space/events.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"context"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/rs/zerolog/log"
)
// HandleEvents returns a http.HandlerFunc that watches for events on a space.
func HandleEvents(appCtx context.Context, spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { //nolint:contextcheck
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx) //nolint:contextcheck
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err) //nolint:contextcheck
return
}
chEvents, chErr, sseCancel, err := spaceCtrl.Events(ctx, session, spaceRef) //nolint:contextcheck
if err != nil {
render.TranslatedUserError(ctx, w, err) //nolint:contextcheck
return
}
defer func() {
if err := sseCancel(ctx); err != nil {
log.Ctx(ctx).Err(err).Msgf("failed to cancel sse stream for space '%s'", spaceRef)
}
}()
render.StreamSSE(ctx, w, appCtx.Done(), chEvents, chErr) //nolint:contextcheck
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/rule_update.go | app/api/handler/space/rule_update.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/services/rules"
)
// HandleRuleUpdate updates a protection rule of a space.
func HandleRuleUpdate(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
ruleIdentifier, err := request.GetRuleIdentifierFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(rules.UpdateInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
rule, err := spaceCtrl.RuleUpdate(ctx, session, spaceRef, ruleIdentifier, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, rule)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/update.go | app/api/handler/space/update.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleUpdate updates an existing space.
func HandleUpdate(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(space.UpdateInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid request body: %s.", err)
return
}
space, err := spaceCtrl.Update(ctx, session, spaceRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, space)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/space/import.go | app/api/handler/space/import.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package space
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleImport(spaceCtrl *space.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
in := new(space.ImportInput)
err := json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
space, err := spaceCtrl.Import(ctx, session, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, space)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/template/create.go | app/api/handler/template/create.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package template
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/template"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleCreate returns a http.HandlerFunc that creates a new template.
func HandleCreate(templateCtrl *template.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
in := new(template.CreateInput)
err := json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
template, err := templateCtrl.Create(ctx, session, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, template)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/template/delete.go | app/api/handler/template/delete.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package template
import (
"net/http"
"github.com/harness/gitness/app/api/controller/template"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/paths"
"github.com/harness/gitness/types/enum"
)
func HandleDelete(templateCtrl *template.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
templateRef, err := request.GetTemplateRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
spaceRef, templateIdentifier, err := paths.DisectLeaf(templateRef)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
resolverType, err := request.GetTemplateTypeFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
tempalateTypeEnum, err := enum.ParseResolverType(resolverType)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
err = templateCtrl.Delete(ctx, session, spaceRef, templateIdentifier, tempalateTypeEnum)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.DeleteSuccessful(w)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/template/find.go | app/api/handler/template/find.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package template
import (
"net/http"
"github.com/harness/gitness/app/api/controller/template"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/paths"
"github.com/harness/gitness/types/enum"
)
// HandleFind finds a template from the database.
func HandleFind(templateCtrl *template.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
templateRef, err := request.GetTemplateRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
spaceRef, templateIdentifier, err := paths.DisectLeaf(templateRef)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
resolverType, err := request.GetTemplateTypeFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
tempalateTypeEnum, err := enum.ParseResolverType(resolverType)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
template, err := templateCtrl.Find(ctx, session, spaceRef, templateIdentifier, tempalateTypeEnum)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, template)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/template/update.go | app/api/handler/template/update.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package template
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/template"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/paths"
"github.com/harness/gitness/types/enum"
)
func HandleUpdate(templateCtrl *template.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
in := new(template.UpdateInput)
err := json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
templateRef, err := request.GetTemplateRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
spaceRef, templateIdentifier, err := paths.DisectLeaf(templateRef)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
resolverType, err := request.GetTemplateTypeFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
}
resolverTypeEnum, err := enum.ParseResolverType(resolverType)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
template, err := templateCtrl.Update(ctx, session, spaceRef, templateIdentifier,
resolverTypeEnum, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, template)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/migrate/webhooks.go | app/api/handler/migrate/webhooks.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package migrate
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/migrate"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleWebhooks returns a http.HandlerFunc that import webhooks.
func HandleWebhooks(migCtrl *migrate.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(migrate.WebhooksInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
hooks, err := migCtrl.Webhooks(ctx, session, repoRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, hooks)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/migrate/rules.go | app/api/handler/migrate/rules.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package migrate
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/migrate"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleRules handles API that imports protection rule(s) to a repository.
func HandleRules(migCtrl *migrate.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(migrate.RulesInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
rules, err := migCtrl.Rules(ctx, session, repoRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, rules)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/migrate/pullreq.go | app/api/handler/migrate/pullreq.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package migrate
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/migrate"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandlePullRequests handles API that imports pull requests to a repository.
func HandlePullRequests(migCtrl *migrate.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(migrate.PullreqsInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
pullReqs, err := migCtrl.PullRequests(ctx, session, repoRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, pullReqs)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/migrate/update_state.go | app/api/handler/migrate/update_state.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package migrate
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/migrate"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleUpdateRepoState handles API that updates the repository state.
func HandleUpdateRepoState(migCtrl *migrate.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(migrate.UpdateStateInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
repo, err := migCtrl.UpdateRepoState(ctx, session, repoRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, repo)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/migrate/create_repo.go | app/api/handler/migrate/create_repo.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package migrate
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/migrate"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleCreateRepo handles API that create an empty repo ready for migration.
func HandleCreateRepo(migCtrl *migrate.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
in := new(migrate.CreateRepoInput)
err := json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
repo, err := migCtrl.CreateRepo(ctx, session, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, repo)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/migrate/label.go | app/api/handler/migrate/label.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package migrate
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/migrate"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
// HandleLabels returns a http.HandlerFunc that import labels.
func HandleLabels(migCtrl *migrate.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
spaceRef, err := request.GetSpaceRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(migrate.LabelsInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
labels, err := migCtrl.Labels(ctx, session, spaceRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, labels)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/lfs/transfer.go | app/api/handler/lfs/transfer.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package lfs
import (
"encoding/json"
"errors"
"net/http"
apiauth "github.com/harness/gitness/app/api/auth"
"github.com/harness/gitness/app/api/controller/lfs"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/url"
)
func HandleLFSTransfer(lfsCtrl *lfs.Controller, urlProvider url.Provider) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(lfs.TransferInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
w.Header().Set("Content-Type", "application/vnd.git-lfs+json")
out, err := lfsCtrl.LFSTransfer(ctx, session, repoRef, in)
if errors.Is(err, apiauth.ErrUnauthorized) {
render.GitBasicAuth(ctx, w, urlProvider)
return
}
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, out)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/lfs/upload.go | app/api/handler/lfs/upload.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package lfs
import (
"errors"
"net/http"
apiauth "github.com/harness/gitness/app/api/auth"
"github.com/harness/gitness/app/api/controller/lfs"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/url"
)
func HandleLFSUpload(controller *lfs.Controller, urlProvider url.Provider) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
oid, err := request.GetObjectIDFromQuery(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
size, err := request.GetObjectSizeFromQuery(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
// apply max byte size from the request body
res, err := controller.Upload(ctx, session, repoRef, lfs.Pointer{OId: oid, Size: size}, r.Body)
if errors.Is(err, apiauth.ErrUnauthorized) {
render.GitBasicAuth(ctx, w, urlProvider)
return
}
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, res)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/lfs/download.go | app/api/handler/lfs/download.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package lfs
import (
"errors"
"fmt"
"net/http"
apiauth "github.com/harness/gitness/app/api/auth"
"github.com/harness/gitness/app/api/controller/lfs"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/url"
"github.com/rs/zerolog/log"
)
func HandleLFSDownload(controller *lfs.Controller, urlProvider url.Provider) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
oid, err := request.GetObjectIDFromQuery(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
resp, err := controller.Download(ctx, session, repoRef, oid)
if errors.Is(err, apiauth.ErrUnauthorized) {
render.GitBasicAuth(ctx, w, urlProvider)
return
}
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
defer func() {
if err := resp.Data.Close(); err != nil {
log.Ctx(ctx).Warn().Err(err).Msgf("failed to close LFS file reader for %q.", oid)
}
}()
w.Header().Add("Content-Length", fmt.Sprint(resp.Size))
// apply max byte size
render.Reader(ctx, w, http.StatusOK, resp.Data)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/keywordsearch/search.go | app/api/handler/keywordsearch/search.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package keywordsearch
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/keywordsearch"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/types"
)
// HandleSearch returns keyword search results on repositories.
func HandleSearch(ctrl *keywordsearch.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
searchInput := types.SearchInput{}
err := json.NewDecoder(r.Body).Decode(&searchInput)
if err != nil {
render.BadRequestf(ctx, w, "invalid Request Body: %s.", err)
return
}
result, err := ctrl.Search(ctx, session, searchInput)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, result)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/pipeline/create.go | app/api/handler/pipeline/create.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pipeline
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/pipeline"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleCreate(pipelineCtrl *pipeline.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
in := new(pipeline.CreateInput)
err = json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
pipeline, err := pipelineCtrl.Create(ctx, session, repoRef, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusCreated, pipeline)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/pipeline/delete.go | app/api/handler/pipeline/delete.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pipeline
import (
"net/http"
"github.com/harness/gitness/app/api/controller/pipeline"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleDelete(pipelineCtrl *pipeline.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
pipelineIdentifier, err := request.GetPipelineIdentifierFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
err = pipelineCtrl.Delete(ctx, session, repoRef, pipelineIdentifier)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.DeleteSuccessful(w)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/pipeline/find.go | app/api/handler/pipeline/find.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pipeline
import (
"net/http"
"github.com/harness/gitness/app/api/controller/pipeline"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleFind(pipelineCtrl *pipeline.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
pipelineIdentifier, err := request.GetPipelineIdentifierFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
pipeline, err := pipelineCtrl.Find(ctx, session, repoRef, pipelineIdentifier)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, pipeline)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/handler/pipeline/update.go | app/api/handler/pipeline/update.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pipeline
import (
"encoding/json"
"net/http"
"github.com/harness/gitness/app/api/controller/pipeline"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
)
func HandleUpdate(pipelineCtrl *pipeline.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
in := new(pipeline.UpdateInput)
err := json.NewDecoder(r.Body).Decode(in)
if err != nil {
render.BadRequestf(ctx, w, "Invalid Request Body: %s.", err)
return
}
pipelineIdentifier, err := request.GetPipelineIdentifierFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
repoRef, err := request.GetRepoRefFromPath(r)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
pipeline, err := pipelineCtrl.Update(ctx, session, repoRef, pipelineIdentifier, in)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return
}
render.JSON(w, http.StatusOK, pipeline)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/git.go | app/api/request/git.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"fmt"
"net/http"
"strconv"
"strings"
"github.com/harness/gitness/app/api/usererror"
gittypes "github.com/harness/gitness/git/api"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
HeaderParamGitProtocol = "Git-Protocol"
PathParamCommitSHA = "commit_sha"
QueryParamGitRef = "git_ref"
QueryParamIncludeCommit = "include_commit"
QueryParamIncludeDirectories = "include_directories"
QueryParamFlattenDirectories = "flatten_directories"
QueryParamLineFrom = "line_from"
QueryParamLineTo = "line_to"
QueryParamPath = "path"
QueryParamSince = "since"
QueryParamUntil = "until"
QueryParamCommitter = "committer"
QueryParamCommitterID = "committer_id"
QueryParamAuthor = "author"
QueryParamAuthorID = "author_id"
QueryParamIncludeStats = "include_stats"
QueryParamInternal = "internal"
QueryParamService = "service"
QueryParamCommitSHA = "commit_sha"
QueryParamIncludeGitStats = "include_git_stats"
QueryParamIncludeChecks = "include_checks"
QueryParamIncludeRules = "include_rules"
QueryParamIncludePullReqs = "include_pullreqs"
QueryParamMaxDivergence = "max_divergence"
)
func GetGitRefFromQueryOrDefault(r *http.Request, deflt string) string {
return QueryParamOrDefault(r, QueryParamGitRef, deflt)
}
func GetIncludeCommitFromQueryOrDefault(r *http.Request, deflt bool) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludeCommit, deflt)
}
func GetIncludeStatsFromQueryOrDefault(r *http.Request, deflt bool) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludeStats, deflt)
}
func GetIncludeGitStatsFromQueryOrDefault(r *http.Request, deflt bool) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludeGitStats, deflt)
}
func GetIncludeChecksFromQueryOrDefault(r *http.Request, deflt bool) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludeChecks, deflt)
}
func GetIncludeRulesFromQueryOrDefault(r *http.Request, deflt bool) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludeRules, deflt)
}
func GetIncludePullReqsFromQueryOrDefault(r *http.Request, deflt bool) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludePullReqs, deflt)
}
func GetMaxDivergenceFromQueryOrDefault(r *http.Request, deflt int64) (int64, error) {
return QueryParamAsPositiveInt64OrDefault(r, QueryParamMaxDivergence, deflt)
}
func GetIncludeDirectoriesFromQueryOrDefault(r *http.Request, deflt bool) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludeDirectories, deflt)
}
func GetFlattenDirectoriesFromQueryOrDefault(r *http.Request, deflt bool) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamFlattenDirectories, deflt)
}
func GetCommitSHAFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamCommitSHA)
}
// ParseSortBranch extracts the branch sort parameter from the url.
func ParseSortBranch(r *http.Request) enum.BranchSortOption {
return enum.ParseBranchSortOption(
r.URL.Query().Get(QueryParamSort),
)
}
func ParseBranchMetadataOptions(r *http.Request) (types.BranchMetadataOptions, error) {
includeChecks, err := GetIncludeChecksFromQueryOrDefault(r, false)
if err != nil {
return types.BranchMetadataOptions{}, err
}
includeRules, err := GetIncludeRulesFromQueryOrDefault(r, false)
if err != nil {
return types.BranchMetadataOptions{}, err
}
includePullReqs, err := GetIncludePullReqsFromQueryOrDefault(r, false)
if err != nil {
return types.BranchMetadataOptions{}, err
}
maxDivergence, err := GetMaxDivergenceFromQueryOrDefault(r, 0)
if err != nil {
return types.BranchMetadataOptions{}, err
}
return types.BranchMetadataOptions{
IncludeChecks: includeChecks,
IncludeRules: includeRules,
IncludePullReqs: includePullReqs,
MaxDivergence: int(maxDivergence),
}, nil
}
// ParseBranchFilter extracts the branch filter from the url.
func ParseBranchFilter(r *http.Request) (*types.BranchFilter, error) {
includeCommit, err := GetIncludeCommitFromQueryOrDefault(r, false)
if err != nil {
return nil, err
}
metadataOptions, err := ParseBranchMetadataOptions(r)
if err != nil {
return nil, err
}
return &types.BranchFilter{
Query: ParseQuery(r),
Sort: ParseSortBranch(r),
Order: ParseOrder(r),
Page: ParsePage(r),
Size: ParseLimit(r),
IncludeCommit: includeCommit,
BranchMetadataOptions: metadataOptions,
}, nil
}
// ParseSortTag extracts the tag sort parameter from the url.
func ParseSortTag(r *http.Request) enum.TagSortOption {
return enum.ParseTagSortOption(
r.URL.Query().Get(QueryParamSort),
)
}
// ParseTagFilter extracts the tag filter from the url.
func ParseTagFilter(r *http.Request) *types.TagFilter {
return &types.TagFilter{
Query: ParseQuery(r),
Sort: ParseSortTag(r),
Order: ParseOrder(r),
Page: ParsePage(r),
Size: ParseLimit(r),
}
}
// ParseCommitFilter extracts the commit filter from the url.
func ParseCommitFilter(r *http.Request) (*types.CommitFilter, error) {
// since is optional, skipped if set to 0
since, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamSince, 0)
if err != nil {
return nil, err
}
// until is optional, skipped if set to 0
until, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamUntil, 0)
if err != nil {
return nil, err
}
includeStats, err := GetIncludeStatsFromQueryOrDefault(r, false)
if err != nil {
return nil, err
}
committerIDs, err := QueryParamListAsPositiveInt64(r, QueryParamCommitterID)
if err != nil {
return nil, err
}
authorIDs, err := QueryParamListAsPositiveInt64(r, QueryParamAuthorID)
if err != nil {
return nil, err
}
return &types.CommitFilter{
After: QueryParamOrDefault(r, QueryParamAfter, ""),
PaginationFilter: types.PaginationFilter{
Page: ParsePage(r),
Limit: ParseLimit(r),
},
Path: QueryParamOrDefault(r, QueryParamPath, ""),
Since: since,
Until: until,
Committer: QueryParamOrDefault(r, QueryParamCommitter, ""),
CommitterIDs: committerIDs,
Author: QueryParamOrDefault(r, QueryParamAuthor, ""),
AuthorIDs: authorIDs,
IncludeStats: includeStats,
}, nil
}
// GetGitProtocolFromHeadersOrDefault returns the git protocol from the request headers.
func GetGitProtocolFromHeadersOrDefault(r *http.Request, deflt string) string {
return GetHeaderOrDefault(r, HeaderParamGitProtocol, deflt)
}
// GetGitServiceTypeFromQuery returns the git service type from the request query.
func GetGitServiceTypeFromQuery(r *http.Request) (enum.GitServiceType, error) {
// git prefixes the service names with "git-" in the query
const gitPrefix = "git-"
val, err := QueryParamOrError(r, QueryParamService)
if err != nil {
return "", fmt.Errorf("failed to get param from query: %w", err)
}
if !strings.HasPrefix(val, gitPrefix) {
return "", usererror.BadRequestf("Not a git service type: %q", val)
}
return enum.ParseGitServiceType(val[len(gitPrefix):])
}
func GetFileDiffFromQuery(r *http.Request) (files gittypes.FileDiffRequests) {
paths, _ := QueryParamList(r, "path")
ranges, _ := QueryParamList(r, "range")
for i, filepath := range paths {
start := 0
end := 0
if i < len(ranges) {
linesRange := ranges[i]
parts := strings.Split(linesRange, ":")
if len(parts) > 1 {
end, _ = strconv.Atoi(parts[1])
}
if len(parts) > 0 {
start, _ = strconv.Atoi(parts[0])
}
}
files = append(files, gittypes.FileDiffRequest{
Path: filepath,
StartLine: start,
EndLine: end,
})
}
return
}
func GetCommitSHAFromQueryOrDefault(r *http.Request) string {
return QueryParamOrDefault(r, QueryParamCommitSHA, "")
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/time.go | app/api/request/time.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import "net/http"
const (
QueryParamStartTime = "start_time"
QueryParamEndTime = "end_time"
)
func QueryParamAsUnixMillisOrDefault(
r *http.Request,
param string,
defaultValue int64,
) int64 {
millis, ok, _ := QueryParamAsPositiveInt64(r, param)
if !ok {
return defaultValue
}
return millis
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/lfs.go | app/api/request/lfs.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import "net/http"
const (
QueryParamObjectID = "oid"
QueryParamObjectSize = "size"
)
func GetObjectIDFromQuery(r *http.Request) (string, error) {
return QueryParamOrError(r, QueryParamObjectID)
}
func GetObjectSizeFromQuery(r *http.Request) (int64, error) {
return QueryParamAsPositiveInt64OrError(r, QueryParamObjectSize)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/infra_provider.go | app/api/request/infra_provider.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
)
const (
PathParamInfraProviderConfigIdentifier = "infraprovider_identifier"
)
func GetInfraProviderRefFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamInfraProviderConfigIdentifier)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/archive.go | app/api/request/archive.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/harness/gitness/git/api"
)
const (
PathParamArchiveGitRef = "*"
QueryParamArchivePaths = "path"
QueryParamArchivePrefix = "prefix"
QueryParamArchiveAttributes = "attributes"
QueryParamArchiveTime = "time"
QueryParamArchiveCompression = "compression"
)
func Ext(path string) string {
found := ""
for _, format := range api.ArchiveFormats {
if strings.HasSuffix(path, "."+string(format)) {
if len(found) == 0 || len(found) < len(format) {
found = string(format)
}
}
}
return found
}
func ParseArchiveParams(r *http.Request) (api.ArchiveParams, string, error) {
// separate rev and ref part from url, for example:
// api/v1/repos/root/demo/+/archive/refs/heads/main.zip
// will produce rev=refs/heads and ref=main.zip
path := PathParamOrEmpty(r, PathParamArchiveGitRef)
rev, filename := filepath.Split(path)
// use ext as format specifier
format := Ext(filename)
// prefix is used for git archive to prefix all paths.
prefix, _ := QueryParam(r, QueryParamArchivePrefix)
attributes, _ := QueryParam(r, QueryParamArchiveAttributes)
var mtime *time.Time
timeStr, _ := QueryParam(r, QueryParamArchiveTime)
if timeStr != "" {
value, err := time.Parse(time.DateTime, timeStr)
if err == nil {
mtime = &value
}
}
var compression *int
compressionStr, _ := QueryParam(r, QueryParamArchiveCompression)
if compressionStr != "" {
value, err := strconv.Atoi(compressionStr)
if err == nil {
compression = &value
}
}
archFormat, err := api.ParseArchiveFormat(format)
if err != nil {
return api.ArchiveParams{}, "", err
}
// get name from filename
name := strings.TrimSuffix(filename, "."+format)
return api.ArchiveParams{
Format: archFormat,
Prefix: prefix,
Attributes: api.ArchiveAttribute(attributes),
Time: mtime,
Compression: compression,
Treeish: rev + name,
Paths: r.URL.Query()[QueryParamArchivePaths],
}, filename, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/webhook.go | app/api/request/webhook.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
PathParamWebhookIdentifier = "webhook_identifier"
PathParamWebhookExecutionID = "webhook_execution_id"
)
func GetWebhookIdentifierFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamWebhookIdentifier)
}
func GetWebhookExecutionIDFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamWebhookExecutionID)
}
// ParseWebhookFilter extracts the Webhook query parameters for listing from the url.
func ParseWebhookFilter(r *http.Request) *types.WebhookFilter {
return &types.WebhookFilter{
Query: ParseQuery(r),
Page: ParsePage(r),
Size: ParseLimit(r),
Sort: ParseSortWebhook(r),
Order: ParseOrder(r),
}
}
// ParseWebhookExecutionFilter extracts the WebhookExecution query parameters for listing from the url.
func ParseWebhookExecutionFilter(r *http.Request) *types.WebhookExecutionFilter {
return &types.WebhookExecutionFilter{
Page: ParsePage(r),
Size: ParseLimit(r),
}
}
// ParseSortWebhook extracts the webhook sort parameter from the url.
func ParseSortWebhook(r *http.Request) enum.WebhookAttr {
return enum.ParseWebhookAttr(
r.URL.Query().Get(QueryParamSort),
)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/publickey.go | app/api/request/publickey.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
PathParamPublicKeyIdentifier = "public_key_identifier"
QueryParamPublicKeyScheme = "public_key_scheme"
QueryParamPublicKeyUsage = "public_key_usage"
)
func GetPublicKeyIdentifierFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamPublicKeyIdentifier)
}
// ParsePublicKeyScheme extracts the public key scheme from the url.
func ParsePublicKeyScheme(r *http.Request) []enum.PublicKeyScheme {
strSchemeList, _ := QueryParamList(r, QueryParamPublicKeyScheme)
m := make(map[enum.PublicKeyScheme]struct{}) // use map to eliminate duplicates
for _, s := range strSchemeList {
if state, ok := enum.PublicKeyScheme(s).Sanitize(); ok {
m[state] = struct{}{}
}
}
schemeList := make([]enum.PublicKeyScheme, 0, len(m))
for s := range m {
schemeList = append(schemeList, s)
}
return schemeList
}
// ParsePublicKeyUsage extracts the public key usage from the url.
func ParsePublicKeyUsage(r *http.Request) []enum.PublicKeyUsage {
strUsageList, _ := QueryParamList(r, QueryParamPublicKeyUsage)
m := make(map[enum.PublicKeyUsage]struct{}) // use map to eliminate duplicates
for _, s := range strUsageList {
if state, ok := enum.PublicKeyUsage(s).Sanitize(); ok {
m[state] = struct{}{}
}
}
usageList := make([]enum.PublicKeyUsage, 0, len(m))
for s := range m {
usageList = append(usageList, s)
}
return usageList
}
// ParseListPublicKeyQueryFilterFromRequest parses query filter for public keys from the url.
func ParseListPublicKeyQueryFilterFromRequest(r *http.Request) (types.PublicKeyFilter, error) {
sort := enum.PublicKeySort(ParseSort(r))
sort, ok := sort.Sanitize()
if !ok {
return types.PublicKeyFilter{}, usererror.BadRequest("Invalid value for the sort query parameter.")
}
schemes := ParsePublicKeyScheme(r)
usages := ParsePublicKeyUsage(r)
return types.PublicKeyFilter{
ListQueryFilter: ParseListQueryFilterFromRequest(r),
Sort: sort,
Order: ParseOrder(r),
Usages: usages,
Schemes: schemes,
}, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/membership.go | app/api/request/membership.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
// ParseMembershipUserSort extracts the membership sort parameter from the url.
func ParseMembershipUserSort(r *http.Request) enum.MembershipUserSort {
return enum.ParseMembershipUserSort(
r.URL.Query().Get(QueryParamSort),
)
}
// ParseMembershipUserFilter extracts the membership filter from the url.
func ParseMembershipUserFilter(r *http.Request) types.MembershipUserFilter {
return types.MembershipUserFilter{
ListQueryFilter: ParseListQueryFilterFromRequest(r),
Sort: ParseMembershipUserSort(r),
Order: ParseOrder(r),
}
}
// ParseMembershipSpaceSort extracts the membership space sort parameter from the url.
func ParseMembershipSpaceSort(r *http.Request) enum.MembershipSpaceSort {
return enum.ParseMembershipSpaceSort(
r.URL.Query().Get(QueryParamSort),
)
}
// ParseMembershipSpaceFilter extracts the membership space filter from the url.
func ParseMembershipSpaceFilter(r *http.Request) types.MembershipSpaceFilter {
return types.MembershipSpaceFilter{
ListQueryFilter: ParseListQueryFilterFromRequest(r),
Sort: ParseMembershipSpaceSort(r),
Order: ParseOrder(r),
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/archive_test.go | app/api/request/archive_test.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"context"
"net/http"
"reflect"
"testing"
"github.com/harness/gitness/git/api"
"github.com/go-chi/chi/v5"
)
func TestParseArchiveParams(t *testing.T) {
req := func(param string) *http.Request {
rctx := chi.NewRouteContext()
rctx.URLParams.Add("*", param)
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, rctx)
r, err := http.NewRequestWithContext(ctx, http.MethodGet, "", nil)
if err != nil {
t.Fatal(err)
}
return r
}
type args struct {
r *http.Request
}
tests := []struct {
name string
args args
wantParams api.ArchiveParams
wantFilename string
wantErr bool
}{
{
name: "git archive flag is empty returns error",
args: args{
r: req("refs/heads/main"),
},
wantParams: api.ArchiveParams{},
wantErr: true,
},
{
name: "git archive flag is unknown returns error",
args: args{
r: req("refs/heads/main.7z"),
},
wantParams: api.ArchiveParams{},
wantErr: true,
},
{
name: "git archive flag format 'tar'",
args: args{
r: req("refs/heads/main.tar"),
},
wantParams: api.ArchiveParams{
Format: api.ArchiveFormatTar,
Treeish: "refs/heads/main",
},
wantFilename: "main.tar",
},
{
name: "git archive flag format 'zip'",
args: args{
r: req("refs/heads/main.zip"),
},
wantParams: api.ArchiveParams{
Format: api.ArchiveFormatZip,
Treeish: "refs/heads/main",
},
wantFilename: "main.zip",
},
{
name: "git archive flag format 'gz'",
args: args{
r: req("refs/heads/main.tar.gz"),
},
wantParams: api.ArchiveParams{
Format: api.ArchiveFormatTarGz,
Treeish: "refs/heads/main",
},
wantFilename: "main.tar.gz",
},
{
name: "git archive flag format 'tgz'",
args: args{
r: req("refs/heads/main.tgz"),
},
wantParams: api.ArchiveParams{
Format: api.ArchiveFormatTgz,
Treeish: "refs/heads/main",
},
wantFilename: "main.tgz",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, gotFilename, err := ParseArchiveParams(tt.args.r)
if !tt.wantErr && err != nil {
t.Errorf("ParseArchiveParams() expected error but err was nil")
}
if !reflect.DeepEqual(got, tt.wantParams) {
t.Errorf("ParseArchiveParams() expected = %v, got %v", tt.wantParams, got)
}
if gotFilename != tt.wantFilename {
t.Errorf("ParseArchiveParams() expected filename = %v, got %v", tt.wantFilename, gotFilename)
}
})
}
}
func TestExt(t *testing.T) {
type args struct {
path string
}
tests := []struct {
name string
args args
want string
}{
{
name: "test file without ext",
args: args{
path: "./testdata/test",
},
want: "",
},
{
name: "test file ext tar",
args: args{
path: "./testdata/test.tar",
},
want: "tar",
},
{
name: "test file ext zip",
args: args{
path: "./testdata/test.zip",
},
want: "zip",
},
{
name: "test file ext tar.gz",
args: args{
path: "./testdata/test.tar.gz",
},
want: "tar.gz",
},
{
name: "test file ext tgz",
args: args{
path: "./testdata/test.tgz",
},
want: "tgz",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Ext(tt.args.path); got != tt.want {
t.Errorf("Ext() = %v, want %v", got, tt.want)
}
})
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/context_test.go | app/api/request/context_test.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import "testing"
func TestContext(t *testing.T) {
t.Skip()
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/token.go | app/api/request/token.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
)
const (
PathParamTokenIdentifier = "token_identifier"
)
func GetTokenIdentifierFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamTokenIdentifier)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/execution.go | app/api/request/execution.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const QueryParamPipelineIdentifier = "pipeline_identifier"
// ParseSortExecution extracts the execution sort parameter from the url.
func ParseSortExecution(r *http.Request) enum.ExecutionSort {
result, _ := enum.ExecutionSort(r.URL.Query().Get(QueryParamSort)).Sanitize()
return result
}
func ParseListExecutionsFilterFromRequest(r *http.Request) (types.ListExecutionsFilter, error) {
return types.ListExecutionsFilter{
ListQueryFilter: types.ListQueryFilter{
Query: ParseQuery(r),
Pagination: ParsePaginationFromRequest(r),
},
PipelineIdentifier: QueryParamOrDefault(r, QueryParamPipelineIdentifier, ""),
Sort: ParseSortExecution(r),
Order: ParseOrder(r),
}, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/check.go | app/api/request/check.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/types"
)
// ParseCheckListOptions extracts the status check list API options from the url.
func ParseCheckListOptions(r *http.Request) types.CheckListOptions {
return types.CheckListOptions{
ListQueryFilter: ParseListQueryFilterFromRequest(r),
}
}
// ParseCheckRecentOptions extracts the list recent status checks API options from the url.
func ParseCheckRecentOptions(r *http.Request) (types.CheckRecentOptions, error) {
since, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamSince, 0)
if err != nil {
return types.CheckRecentOptions{}, err
}
return types.CheckRecentOptions{
Query: ParseQuery(r),
Since: since,
}, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/util.go | app/api/request/util.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"errors"
"fmt"
"net/http"
"net/url"
"strconv"
"github.com/harness/gitness/app/api/usererror"
"github.com/go-chi/chi/v5"
)
// GetCookie tries to retrieve the cookie from the request or returns false if it doesn't exist.
func GetCookie(r *http.Request, cookieName string) (string, bool) {
cookie, err := r.Cookie(cookieName)
if errors.Is(err, http.ErrNoCookie) {
return "", false
} else if err != nil {
// this should never happen - documentation and code only return `nil` or `http.ErrNoCookie`
panic(fmt.Sprintf("unexpected error from request.Cookie(...) method: %s", err))
}
return cookie.Value, true
}
// GetHeaderOrDefault returns the value of the first non-empty header occurrence.
// If no value is found, the default value is returned.
func GetHeaderOrDefault(r *http.Request, headerName string, dflt string) string {
val, ok := GetHeader(r, headerName)
if !ok {
return dflt
}
return val
}
// GetHeader returns the value of the first non-empty header occurrence.
// If no value is found, `false` is returned.
func GetHeader(r *http.Request, headerName string) (string, bool) {
for _, val := range r.Header.Values(headerName) {
if val != "" {
return val, true
}
}
return "", false
}
// PathParamOrError tries to retrieve the parameter from the request and
// returns the parameter if it exists and is not empty, otherwise returns an error.
func PathParamOrError(r *http.Request, paramName string) (string, error) {
val, err := PathParam(r, paramName)
if err != nil {
return "", err
}
if val == "" {
return "", usererror.BadRequestf("Parameter '%s' not found in request path.", paramName)
}
return val, nil
}
// PathParamOrEmpty retrieves the path parameter or returns an empty string otherwise.
func PathParamOrEmpty(r *http.Request, paramName string) string {
val, err := PathParam(r, paramName)
if err != nil {
return ""
}
return val
}
// PathParam retrieves the path parameter or returns false if it exists.
func PathParam(r *http.Request, paramName string) (string, error) {
val := chi.URLParam(r, paramName)
if val == "" {
return "", nil
}
val, err := url.PathUnescape(val)
if err != nil {
return "", usererror.BadRequestf("Failed to decode path parameter '%s'.", paramName)
}
return val, nil
}
// QueryParam returns the parameter if it exists.
func QueryParam(r *http.Request, paramName string) (string, bool) {
query := r.URL.Query()
if !query.Has(paramName) {
return "", false
}
return query.Get(paramName), true
}
// QueryParamList returns list of the parameter values if they exist.
func QueryParamList(r *http.Request, paramName string) ([]string, bool) {
query := r.URL.Query()
if !query.Has(paramName) {
return nil, false
}
return query[paramName], true
}
// QueryParamOrDefault retrieves the parameter from the query and
// returns the parameter if it exists, otherwise returns the provided default value.
func QueryParamOrDefault(r *http.Request, paramName string, deflt string) string {
val, ok := QueryParam(r, paramName)
if !ok {
return deflt
}
return val
}
// QueryParamOrError tries to retrieve the parameter from the query and
// returns the parameter if it exists, otherwise returns an error.
func QueryParamOrError(r *http.Request, paramName string) (string, error) {
val, ok := QueryParam(r, paramName)
if !ok {
return "", usererror.BadRequestf("Parameter '%s' not found in query.", paramName)
}
return val, nil
}
// QueryParamAsPositiveInt64 extracts an integer parameter from the request query.
// If the parameter doesn't exist the provided default value is returned.
func QueryParamAsPositiveInt64OrDefault(r *http.Request, paramName string, deflt int64) (int64, error) {
value, ok := QueryParam(r, paramName)
if !ok {
return deflt, nil
}
valueInt, err := strconv.ParseInt(value, 10, 64)
if err != nil || valueInt <= 0 {
return 0, usererror.BadRequestf("Parameter '%s' must be a positive integer.", paramName)
}
return valueInt, nil
}
// QueryParamAsPositiveInt64OrError extracts an integer parameter from the request query.
// If the parameter doesn't exist an error is returned.
func QueryParamAsPositiveInt64OrError(r *http.Request, paramName string) (int64, error) {
value, err := QueryParamOrError(r, paramName)
if err != nil {
return 0, err
}
valueInt, err := strconv.ParseInt(value, 10, 64)
if err != nil || valueInt <= 0 {
return 0, usererror.BadRequestf("Parameter '%s' must be a positive integer.", paramName)
}
return valueInt, nil
}
// QueryParamAsPositiveInt64 extracts an integer parameter from the request query if it exists.
func QueryParamAsPositiveInt64(r *http.Request, paramName string) (int64, bool, error) {
value, ok := QueryParam(r, paramName)
if !ok {
return 0, false, nil
}
valueInt, err := strconv.ParseInt(value, 10, 64)
if err != nil || valueInt <= 0 {
return 0, false, usererror.BadRequestf("Parameter '%s' must be a positive integer.", paramName)
}
return valueInt, true, nil
}
// PathParamAsPositiveInt64 extracts an integer parameter from the request path.
func PathParamAsPositiveInt64(r *http.Request, paramName string) (int64, error) {
rawValue, err := PathParamOrError(r, paramName)
if err != nil {
return 0, err
}
valueInt, err := strconv.ParseInt(rawValue, 10, 64)
if err != nil || valueInt <= 0 {
return 0, usererror.BadRequestf("Parameter '%s' must be a positive integer.", paramName)
}
return valueInt, nil
}
// QueryParamAsBoolOrDefault tries to retrieve the parameter from the query and parse it to bool.
func QueryParamAsBoolOrDefault(r *http.Request, paramName string, deflt bool) (bool, error) {
rawValue, ok := QueryParam(r, paramName)
if !ok || len(rawValue) == 0 {
return deflt, nil
}
boolValue, err := strconv.ParseBool(rawValue)
if err != nil {
return false, usererror.BadRequestf("Parameter '%s' must be a boolean.", paramName)
}
return boolValue, nil
}
// QueryParamListAsPositiveInt64 extracts integer parameter slice from the request query.
func QueryParamListAsPositiveInt64(r *http.Request, paramName string) ([]int64, error) {
valuesString, ok := QueryParamList(r, paramName)
if !ok {
return make([]int64, 0), nil
}
valuesInt := make([]int64, len(valuesString))
for i, vs := range valuesString {
vi, err := strconv.ParseInt(vs, 10, 64)
if err != nil || vi <= 0 {
return nil, usererror.BadRequestf("Parameter %q must be a positive integer.", paramName)
}
valuesInt[i] = vi
}
return valuesInt, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/pullreq.go | app/api/request/pullreq.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"fmt"
"net/http"
"github.com/harness/gitness/errors"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
PathParamPullReqNumber = "pullreq_number"
PathParamPullReqCommentID = "pullreq_comment_id"
PathParamReviewerID = "pullreq_reviewer_id"
PathParamUserGroupID = "user_group_id"
PathParamSourceBranch = "source_branch"
PathParamTargetBranch = "target_branch"
QueryParamCommenterID = "commenter_id"
QueryParamReviewerID = "reviewer_id"
QueryParamReviewDecision = "review_decision"
QueryParamMentionedID = "mentioned_id"
QueryParamExcludeDescription = "exclude_description"
QueryParamSourceRepoRef = "source_repo_ref"
QueryParamSourceBranch = "source_branch"
QueryParamTargetBranch = "target_branch"
)
func GetPullReqNumberFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamPullReqNumber)
}
func GetReviewerIDFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamReviewerID)
}
func GetUserGroupIDFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamUserGroupID)
}
func GetPullReqCommentIDPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamPullReqCommentID)
}
func GetPullReqSourceBranchFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamSourceBranch)
}
func GetPullReqTargetBranchFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamTargetBranch)
}
func GetSourceRepoRefFromQueryOrDefault(r *http.Request, deflt string) string {
return QueryParamOrDefault(r, QueryParamSourceRepoRef, deflt)
}
// ParseSortPullReq extracts the pull request sort parameter from the url.
func ParseSortPullReq(r *http.Request) enum.PullReqSort {
result, _ := enum.PullReqSort(r.URL.Query().Get(QueryParamSort)).Sanitize()
return result
}
// parsePullReqStates extracts the pull request states from the url.
func parsePullReqStates(r *http.Request) []enum.PullReqState {
strStates, _ := QueryParamList(r, QueryParamState)
m := make(map[enum.PullReqState]struct{}) // use map to eliminate duplicates
for _, s := range strStates {
if state, ok := enum.PullReqState(s).Sanitize(); ok {
m[state] = struct{}{}
}
}
states := make([]enum.PullReqState, 0, len(m))
for s := range m {
states = append(states, s)
}
return states
}
// parseReviewDecisions extracts the pull request reviewer decisions from the url.
func parseReviewDecisions(r *http.Request) []enum.PullReqReviewDecision {
strReviewDecisions, _ := QueryParamList(r, QueryParamReviewDecision)
m := make(map[enum.PullReqReviewDecision]struct{}) // use map to eliminate duplicates
for _, s := range strReviewDecisions {
if state, ok := enum.PullReqReviewDecision(s).Sanitize(); ok {
m[state] = struct{}{}
}
}
reviewDecisions := make([]enum.PullReqReviewDecision, 0, len(m))
for s := range m {
reviewDecisions = append(reviewDecisions, s)
}
return reviewDecisions
}
func ParsePullReqMetadataOptions(r *http.Request) (types.PullReqMetadataOptions, error) {
// TODO: Remove the "includeGitStats := true" line and uncomment the following code block.
// Because introduction of "include_git_stats" parameter is a breaking API change,
// we should remove this line only after other teams, who need PR stats
// include the include_git_stats=true in API calls.
includeGitStats := true
/*includeGitStats, err := GetIncludeGitStatsFromQueryOrDefault(r, false)
if err != nil {
return types.PullReqMetadataOptions{}, err
}*/
includeChecks, err := GetIncludeChecksFromQueryOrDefault(r, false)
if err != nil {
return types.PullReqMetadataOptions{}, err
}
includeRules, err := GetIncludeRulesFromQueryOrDefault(r, false)
if err != nil {
return types.PullReqMetadataOptions{}, err
}
return types.PullReqMetadataOptions{
IncludeGitStats: includeGitStats,
IncludeChecks: includeChecks,
IncludeRules: includeRules,
}, nil
}
// ParsePullReqFilter extracts the pull request query parameter from the url.
func ParsePullReqFilter(r *http.Request) (*types.PullReqFilter, error) {
createdBy, err := QueryParamListAsPositiveInt64(r, QueryParamCreatedBy)
if err != nil {
return nil, fmt.Errorf("encountered error parsing createdby filter: %w", err)
}
labelID, err := QueryParamListAsPositiveInt64(r, QueryParamLabelID)
if err != nil {
return nil, fmt.Errorf("encountered error parsing labelid filter: %w", err)
}
valueID, err := QueryParamListAsPositiveInt64(r, QueryParamValueID)
if err != nil {
return nil, fmt.Errorf("encountered error parsing valueid filter: %w", err)
}
createdFilter, err := ParseCreated(r)
if err != nil {
return nil, fmt.Errorf("encountered error parsing pr created filter: %w", err)
}
updatedFilter, err := ParseUpdated(r)
if err != nil {
return nil, fmt.Errorf("encountered error parsing pr updated filter: %w", err)
}
editedFilter, err := ParseEdited(r)
if err != nil {
return nil, fmt.Errorf("encountered error parsing pr edited filter: %w", err)
}
excludeDescription, err := QueryParamAsBoolOrDefault(r, QueryParamExcludeDescription, false)
if err != nil {
return nil, fmt.Errorf("encountered error parsing include description filter: %w", err)
}
authorID, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamAuthorID, 0)
if err != nil {
return nil, fmt.Errorf("encountered error parsing author ID filter: %w", err)
}
commenterID, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamCommenterID, 0)
if err != nil {
return nil, fmt.Errorf("encountered error parsing commenter ID filter: %w", err)
}
reviewerID, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamReviewerID, 0)
if err != nil {
return nil, fmt.Errorf("encountered error parsing reviewer ID filter: %w", err)
}
reviewDecisions := parseReviewDecisions(r)
if len(reviewDecisions) > 0 && reviewerID <= 0 {
return nil, errors.InvalidArgument("Can't use review decisions without providing a reviewer ID")
}
mentionedID, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamMentionedID, 0)
if err != nil {
return nil, fmt.Errorf("encountered error parsing mentioned ID filter: %w", err)
}
metadataOptions, err := ParsePullReqMetadataOptions(r)
if err != nil {
return nil, err
}
if authorID > 0 {
createdBy = append(createdBy, authorID)
}
return &types.PullReqFilter{
Page: ParsePage(r),
Size: ParseLimit(r),
Query: ParseQuery(r),
CreatedBy: createdBy,
SourceRepoRef: r.URL.Query().Get(QueryParamSourceRepoRef),
SourceBranch: r.URL.Query().Get(QueryParamSourceBranch),
TargetBranch: r.URL.Query().Get(QueryParamTargetBranch),
States: parsePullReqStates(r),
Sort: ParseSortPullReq(r),
Order: ParseOrder(r),
LabelID: labelID,
ValueID: valueID,
CommenterID: commenterID,
ReviewerID: reviewerID,
ReviewDecisions: reviewDecisions,
MentionedID: mentionedID,
ExcludeDescription: excludeDescription,
CreatedFilter: createdFilter,
UpdatedFilter: updatedFilter,
EditedFilter: editedFilter,
PullReqMetadataOptions: metadataOptions,
}, nil
}
// ParsePullReqActivityFilter extracts the pull request activity query parameter from the url.
func ParsePullReqActivityFilter(r *http.Request) (*types.PullReqActivityFilter, error) {
// after is optional, skipped if set to 0
after, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamAfter, 0)
if err != nil {
return nil, err
}
// before is optional, skipped if set to 0
before, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamBefore, 0)
if err != nil {
return nil, err
}
// limit is optional, skipped if set to 0
limit, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamLimit, 0)
if err != nil {
return nil, err
}
return &types.PullReqActivityFilter{
After: after,
Before: before,
Limit: int(limit),
Types: parsePullReqActivityTypes(r),
Kinds: parsePullReqActivityKinds(r),
}, nil
}
// parsePullReqActivityKinds extracts the pull request activity kinds from the url.
func parsePullReqActivityKinds(r *http.Request) []enum.PullReqActivityKind {
strKinds := r.URL.Query()[QueryParamKind]
m := make(map[enum.PullReqActivityKind]struct{}) // use map to eliminate duplicates
for _, s := range strKinds {
if kind, ok := enum.PullReqActivityKind(s).Sanitize(); ok {
m[kind] = struct{}{}
}
}
if len(m) == 0 {
return nil
}
kinds := make([]enum.PullReqActivityKind, 0, len(m))
for k := range m {
kinds = append(kinds, k)
}
return kinds
}
// parsePullReqActivityTypes extracts the pull request activity types from the url.
func parsePullReqActivityTypes(r *http.Request) []enum.PullReqActivityType {
strType := r.URL.Query()[QueryParamType]
m := make(map[enum.PullReqActivityType]struct{}) // use map to eliminate duplicates
for _, s := range strType {
if t, ok := enum.PullReqActivityType(s).Sanitize(); ok {
m[t] = struct{}{}
}
}
if len(m) == 0 {
return nil
}
activityTypes := make([]enum.PullReqActivityType, 0, len(m))
for t := range m {
activityTypes = append(activityTypes, t)
}
return activityTypes
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/space.go | app/api/request/space.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"fmt"
"net/http"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
PathParamSpaceRef = "space_ref"
QueryParamIncludeSubspaces = "include_subspaces"
)
func GetSpaceRefFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamSpaceRef)
}
// ParseSortSpace extracts the space sort parameter from the url.
func ParseSortSpace(r *http.Request) enum.SpaceAttr {
return enum.ParseSpaceAttr(
r.URL.Query().Get(QueryParamSort),
)
}
// ParseSpaceFilter extracts the space filter from the url.
func ParseSpaceFilter(r *http.Request) (*types.SpaceFilter, error) {
// recursive is optional to get sapce and its subsapces recursively.
recursive, err := ParseRecursiveFromQuery(r)
if err != nil {
return nil, err
}
// deletedBeforeOrAt is optional to retrieve spaces deleted before or at the specified timestamp.
var deletedBeforeOrAt *int64
deletionVal, ok, err := GetDeletedBeforeOrAtFromQuery(r)
if err != nil {
return nil, err
}
if ok {
deletedBeforeOrAt = &deletionVal
}
// deletedAt is optional to retrieve spaces deleted at the specified timestamp.
var deletedAt *int64
deletedAtVal, ok, err := GetDeletedAtFromQuery(r)
if err != nil {
return nil, err
}
if ok {
deletedAt = &deletedAtVal
}
return &types.SpaceFilter{
Query: ParseQuery(r),
Order: ParseOrder(r),
Page: ParsePage(r),
Sort: ParseSortSpace(r),
Size: ParseLimit(r),
Recursive: recursive,
DeletedAt: deletedAt,
DeletedBeforeOrAt: deletedBeforeOrAt,
}, nil
}
func GetIncludeSubspacesFromQuery(r *http.Request) (bool, error) {
v, err := QueryParamAsBoolOrDefault(r, QueryParamIncludeSubspaces, false)
if err != nil {
return false, fmt.Errorf("failed to parse include subspaces parameter: %w", err)
}
return v, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/favorite.go | app/api/request/favorite.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types/enum"
)
const (
PathParamResourceID = "resource_id"
QueryParamResourceType = "resource_type"
)
// GetResourceIDFromPath extracts the resource id from the url path.
func GetResourceIDFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamResourceID)
}
// ParseResourceType extracts the resource type from the url query param.
func ParseResourceType(r *http.Request) (enum.ResourceType, error) {
resourceType, ok := enum.ResourceType(r.URL.Query().Get(QueryParamResourceType)).Sanitize()
if !ok {
return "", usererror.BadRequest("Invalid resource type")
}
return resourceType, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/repo.go | app/api/request/repo.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"slices"
"strings"
"github.com/harness/gitness/app/auth"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
PathParamRepoRef = "repo_ref"
QueryParamOnlyFavorites = "only_favorites"
QueryParamTag = "tag"
)
func GetRepoRefFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamRepoRef)
}
// ParseSortRepo extracts the repo sort parameter from the url.
func ParseSortRepo(r *http.Request) enum.RepoAttr {
return enum.ParseRepoAttr(
r.URL.Query().Get(QueryParamSort),
)
}
// ParseOnlyFavoritesFromQuery extracts the only_favorites option from the URL.
func ParseOnlyFavoritesFromQuery(r *http.Request) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamOnlyFavorites, false)
}
func ParseTagsFromQuery(r *http.Request) map[string][]string {
tags, ok := QueryParamList(r, QueryParamTag)
if !ok {
return nil
}
result := make(map[string][]string)
for _, t := range tags {
before, after, found := strings.Cut(t, ":")
key := strings.TrimSpace(before)
// key without value
if !found {
// dominates everything else → just set to nil
result[key] = nil
continue
}
// key with value
if _, ok := result[key]; !ok || result[key] != nil {
val := strings.TrimSpace(after)
result[key] = append(result[key], val)
}
}
for key, values := range result {
slices.Sort(values)
result[key] = slices.Compact(values)
}
return result
}
// ParseRepoFilter extracts the repository filter from the url.
func ParseRepoFilter(r *http.Request, session *auth.Session) (*types.RepoFilter, error) {
// recursive is optional to get all repos in a space and its subspaces recursively.
recursive, err := ParseRecursiveFromQuery(r)
if err != nil {
return nil, err
}
// deletedBeforeOrAt is optional to retrieve repos deleted before or at the specified timestamp.
var deletedBeforeOrAt *int64
deletionVal, ok, err := GetDeletedBeforeOrAtFromQuery(r)
if err != nil {
return nil, err
}
if ok {
deletedBeforeOrAt = &deletionVal
}
// deletedAt is optional to retrieve repos deleted at the specified timestamp.
var deletedAt *int64
deletedAtVal, ok, err := GetDeletedAtFromQuery(r)
if err != nil {
return nil, err
}
if ok {
deletedAt = &deletedAtVal
}
order := ParseOrder(r)
if order == enum.OrderDefault {
order = enum.OrderAsc
}
onlyFavorites, err := ParseOnlyFavoritesFromQuery(r)
if err != nil {
return nil, err
}
var onlyFavoritesFor *int64
if onlyFavorites {
onlyFavoritesFor = &session.Principal.ID
}
return &types.RepoFilter{
Query: ParseQuery(r),
Order: order,
Page: ParsePage(r),
Sort: ParseSortRepo(r),
Size: ParseLimit(r),
Recursive: recursive,
DeletedAt: deletedAt,
DeletedBeforeOrAt: deletedBeforeOrAt,
OnlyFavoritesFor: onlyFavoritesFor,
Tags: ParseTagsFromQuery(r),
}, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/secret.go | app/api/request/secret.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
)
const (
PathParamSecretRef = "secret_ref"
)
func GetSecretRefFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamSecretRef)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/diff.go | app/api/request/diff.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
const (
QueryParamIgnoreWhitespace = "ignore_whitespace"
QueryParamIncludePatch = "include_patch"
)
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/auth.go | app/api/request/auth.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
)
const (
QueryParamAccessToken = "access_token"
QueryParamIncludeCookie = "include_cookie"
)
func GetAccessTokenFromQuery(r *http.Request) (string, bool) {
return QueryParam(r, QueryParamAccessToken)
}
func GetIncludeCookieFromQueryOrDefault(r *http.Request, dflt bool) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludeCookie, dflt)
}
func GetTokenFromCookie(r *http.Request, cookieName string) (string, bool) {
return GetCookie(r, cookieName)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/context.go | app/api/request/context.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
// This pattern was inpired by the kubernetes request context package.
// https://github.com/kubernetes/apiserver/blob/master/pkg/endpoints/request/context.go
import (
"context"
"github.com/harness/gitness/app/auth"
"github.com/harness/gitness/types"
"github.com/gliderlabs/ssh"
)
type key int
const (
authSessionKey key = iota
serviceAccountKey
userKey
spaceKey
repoKey
requestIDKey
)
// WithAuthSession returns a copy of parent in which the principal
// value is set.
func WithAuthSession(parent context.Context, v *auth.Session) context.Context {
return context.WithValue(parent, authSessionKey, v)
}
// AuthSessionFrom returns the value of the principal key on the
// context.
func AuthSessionFrom(ctx context.Context) (*auth.Session, bool) {
v, ok := ctx.Value(authSessionKey).(*auth.Session)
return v, ok && v != nil
}
// PrincipalFrom returns the principal of the authsession.
func PrincipalFrom(ctx context.Context) (*types.Principal, bool) {
v, ok := AuthSessionFrom(ctx)
if !ok {
return nil, false
}
return &v.Principal, true
}
// WithUser returns a copy of parent in which the user value is set.
func WithUser(parent context.Context, v *types.User) context.Context {
return context.WithValue(parent, userKey, v)
}
// UserFrom returns the value of the user key on the
// context - ok is true iff a non-nile value existed.
func UserFrom(ctx context.Context) (*types.User, bool) {
v, ok := ctx.Value(userKey).(*types.User)
return v, ok && v != nil
}
// WithServiceAccount returns a copy of parent in which the service account value is set.
func WithServiceAccount(parent context.Context, v *types.ServiceAccount) context.Context {
return context.WithValue(parent, serviceAccountKey, v)
}
// ServiceAccountFrom returns the value of the service account key on the
// context - ok is true iff a non-nile value existed.
func ServiceAccountFrom(ctx context.Context) (*types.ServiceAccount, bool) {
v, ok := ctx.Value(serviceAccountKey).(*types.ServiceAccount)
return v, ok && v != nil
}
// WithSpace returns a copy of parent in which the space value is set.
func WithSpace(parent context.Context, v *types.Space) context.Context {
return context.WithValue(parent, spaceKey, v)
}
// SpaceFrom returns the value of the space key on the
// context - ok is true iff a non-nile value existed.
func SpaceFrom(ctx context.Context) (*types.Space, bool) {
v, ok := ctx.Value(spaceKey).(*types.Space)
return v, ok && v != nil
}
// WithRepo returns a copy of parent in which the repo value is set.
func WithRepo(parent context.Context, v *types.Repository) context.Context {
return context.WithValue(parent, repoKey, v)
}
// RepoFrom returns the value of the repo key on the
// context - ok is true iff a non-nile value existed.
func RepoFrom(ctx context.Context) (*types.Repository, bool) {
v, ok := ctx.Value(repoKey).(*types.Repository)
return v, ok && v != nil
}
// WithRequestID returns a copy of parent in which the request id value is set.
func WithRequestID(parent context.Context, v string) context.Context {
return context.WithValue(parent, requestIDKey, v)
}
// RequestIDFrom returns the value of the request ID key on the
// context - ok is true iff a non-empty value existed.
//
//nolint:revive // need to emphasize that it's the request id we are retrieving.
func RequestIDFrom(ctx context.Context) (string, bool) {
v, ok := ctx.Value(requestIDKey).(string)
return v, ok && v != ""
}
func WithRequestIDSSH(parent ssh.Context, v string) {
ssh.Context.SetValue(parent, requestIDKey, v)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/repo_test.go | app/api/request/repo_test.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"net/url"
"reflect"
"testing"
)
func TestParseTagsFromQuery(t *testing.T) {
tests := []struct {
name string
query string
expected map[string][]string
}{
{
name: "no tags",
query: "",
expected: nil,
},
{
name: "single key-only",
query: "tag=backend",
expected: map[string][]string{
"backend": nil,
},
},
{
name: "single key-value",
query: "tag=backend:golang",
expected: map[string][]string{
"backend": {"golang"},
},
},
{
name: "multiple values same key",
query: "tag=backend:golang&tag=backend:java",
expected: map[string][]string{
"backend": {"golang", "java"},
},
},
{
name: "duplicate values deduped",
query: "tag=backend:golang&tag=backend:golang",
expected: map[string][]string{
"backend": {"golang"},
},
},
{
name: "key-only dominates",
query: "tag=backend&tag=backend:golang&tag=backend:java",
expected: map[string][]string{
"backend": nil,
},
},
{
name: "multiple different keys",
query: "tag=backend:golang&tag=db:postgres",
expected: map[string][]string{
"backend": {"golang"},
"db": {"postgres"},
},
},
{
name: "multiple different keys with duplicates",
query: "tag=backend:python&tag=backend:golang&tag=db:postgres&tag=backend:golang&tag=db:postgres",
expected: map[string][]string{
"backend": {"golang", "python"},
"db": {"postgres"},
},
},
{
name: "empty value",
query: "tag=backend:",
expected: map[string][]string{
"backend": {""},
},
},
{
name: "mixed key-only and value keys",
query: "tag=backend&tag=db:postgres&tag=auth:jwt",
expected: map[string][]string{
"backend": nil,
"db": {"postgres"},
"auth": {"jwt"},
},
},
{
name: "empty key is preserved",
query: "tag=:value&tag=:",
expected: map[string][]string{
"": {"", "value"},
},
},
{
name: "empty key-only",
query: "tag=",
expected: map[string][]string{
"": nil,
},
},
{
name: "two empty key-only",
query: "tag=&tag=",
expected: map[string][]string{
"": nil,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
u, _ := url.Parse("http://example.com/?" + tt.query)
req := &http.Request{URL: u}
got := ParseTagsFromQuery(req)
// compare maps
if !reflect.DeepEqual(got, tt.expected) {
t.Errorf("expected %#v, got %#v", tt.expected, got)
}
})
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/connector.go | app/api/request/connector.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
)
const (
PathParamConnectorRef = "connector_ref"
)
func GetConnectorRefFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamConnectorRef)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/gitspace.go | app/api/request/gitspace.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
PathParamGitspaceIdentifier = "gitspace_identifier"
QueryParamGitspaceOwner = "gitspace_owner"
QueryParamGitspaceStates = "gitspace_states"
QueryParamOrgs = "org_identifiers"
QueryParamProjects = "project_identifiers"
)
func GetGitspaceRefFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamGitspaceIdentifier)
}
// ParseGitspaceSort extracts the gitspace sort parameter from the url.
func ParseGitspaceSort(r *http.Request) enum.GitspaceSort {
return enum.ParseGitspaceSort(
r.URL.Query().Get(QueryParamSort),
)
}
// ParseGitspaceOwner extracts the gitspace owner type from the url.
func ParseGitspaceOwner(r *http.Request) enum.GitspaceOwner {
return enum.ParseGitspaceOwner(
r.URL.Query().Get(QueryParamGitspaceOwner),
)
}
// ParseGitspaceStates extracts the gitspace owner type from the url.
func ParseGitspaceStates(r *http.Request) []enum.GitspaceFilterState {
pTypesRaw := r.URL.Query()[QueryParamGitspaceStates]
m := make(map[enum.GitspaceFilterState]struct{}) // use map to eliminate duplicates
for _, pTypeRaw := range pTypesRaw {
if pType, ok := enum.GitspaceFilterState(pTypeRaw).Sanitize(); ok {
m[pType] = struct{}{}
}
}
res := make([]enum.GitspaceFilterState, 0, len(m))
for t := range m {
res = append(res, t)
}
return res
}
// ParseScopeFilter extracts scope filter from the url.
func ParseScopeFilter(r *http.Request) types.ScopeFilter {
orgsTypesRaw := r.URL.Query()[QueryParamOrgs]
orgs := make([]string, 0, len(orgsTypesRaw))
orgsSet := make(map[string]struct{})
for _, pTypeRaw := range orgsTypesRaw {
if _, ok := orgsSet[pTypeRaw]; ok {
// already added
continue
}
orgs = append(orgs, pTypeRaw)
orgsSet[pTypeRaw] = struct{}{}
}
projectsTypesRaw := r.URL.Query()[QueryParamProjects]
projects := make([]string, 0, len(projectsTypesRaw))
projectsSet := make(map[string]struct{})
for _, pTypeRaw := range projectsTypesRaw {
if _, ok := projectsSet[pTypeRaw]; ok {
// already added
continue
}
projects = append(projects, pTypeRaw)
projectsSet[pTypeRaw] = struct{}{}
}
return types.ScopeFilter{
Orgs: orgs,
Projects: projects,
}
}
// ParseGitspaceFilter extracts the gitspace filter from the url.
func ParseGitspaceFilter(r *http.Request) types.GitspaceFilter {
return types.GitspaceFilter{
QueryFilter: ParseListQueryFilterFromRequest(r),
GitspaceFilterStates: ParseGitspaceStates(r),
Sort: ParseGitspaceSort(r),
Owner: ParseGitspaceOwner(r),
Order: ParseOrder(r),
ScopeFilter: ParseScopeFilter(r),
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/rule.go | app/api/request/rule.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
PathParamRuleIdentifier = "rule_identifier"
QueryParamBypassRules = "bypass_rules"
QueryParamDryRunRules = "dry_run_rules"
)
// ParseRuleFilter extracts the protection rule query parameters from the url.
func ParseRuleFilter(r *http.Request) *types.RuleFilter {
return &types.RuleFilter{
ListQueryFilter: ParseListQueryFilterFromRequest(r),
States: parseRuleStates(r),
Types: parseRuleTypes(r),
Sort: parseRuleSort(r),
Order: ParseOrder(r),
}
}
// parseRuleStates extracts the protection rule states from the url.
func parseRuleStates(r *http.Request) []enum.RuleState {
strStates, _ := QueryParamList(r, QueryParamState)
m := make(map[enum.RuleState]struct{}) // use map to eliminate duplicates
for _, s := range strStates {
if state, ok := enum.RuleState(s).Sanitize(); ok {
m[state] = struct{}{}
}
}
states := make([]enum.RuleState, 0, len(m))
for s := range m {
states = append(states, s)
}
return states
}
// parseRuleTypes extracts the rule types from the url.
func parseRuleTypes(r *http.Request) []enum.RuleType {
strTypes, _ := QueryParamList(r, QueryParamType)
m := make(map[enum.RuleType]struct{}) // use map to eliminate duplicates
for _, s := range strTypes {
if t, ok := enum.RuleType(s).Sanitize(); ok {
m[t] = struct{}{}
}
}
ruleTypes := make([]enum.RuleType, 0, len(m))
for t := range m {
ruleTypes = append(ruleTypes, t)
}
return ruleTypes
}
// GetRuleIdentifierFromPath extracts the protection rule identifier from the URL.
func GetRuleIdentifierFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamRuleIdentifier)
}
// parseRuleSort extracts the protection rule sort parameter from the URL.
func parseRuleSort(r *http.Request) enum.RuleSort {
return enum.ParseRuleSortAttr(
r.URL.Query().Get(QueryParamSort),
)
}
// ParseBypassRulesFromQuery extracts the bypass rules parameter from the URL query.
func ParseBypassRulesFromQuery(r *http.Request) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamBypassRules, false)
}
// ParseDryRunRulesFromQuery extracts the dry run rules parameter from the URL query.
func ParseDryRunRulesFromQuery(r *http.Request) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamDryRunRules, false)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/template.go | app/api/request/template.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
)
const (
PathParamTemplateRef = "template_ref"
PathParamTemplateType = "template_type"
)
func GetTemplateRefFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamTemplateRef)
}
func GetTemplateTypeFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamTemplateType)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/pipeline.go | app/api/request/pipeline.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/types"
)
const (
PathParamPipelineIdentifier = "pipeline_identifier"
PathParamExecutionNumber = "execution_number"
PathParamStageNumber = "stage_number"
PathParamStepNumber = "step_number"
PathParamTriggerIdentifier = "trigger_identifier"
QueryParamLatest = "latest"
QueryParamLastExecutions = "last_executions"
QueryParamBranch = "branch"
)
func GetPipelineIdentifierFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamPipelineIdentifier)
}
func GetBranchFromQuery(r *http.Request) string {
return QueryParamOrDefault(r, QueryParamBranch, "")
}
func GetExecutionNumberFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamExecutionNumber)
}
func GetStageNumberFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamStageNumber)
}
func GetStepNumberFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamStepNumber)
}
func GetLatestFromPath(r *http.Request) bool {
l, _ := QueryParamAsBoolOrDefault(r, QueryParamLatest, false)
return l
}
func GetTriggerIdentifierFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamTriggerIdentifier)
}
func ParseListPipelinesFilterFromRequest(r *http.Request) (types.ListPipelinesFilter, error) {
lastExecs, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamLastExecutions, 10)
if err != nil {
return types.ListPipelinesFilter{}, err
}
return types.ListPipelinesFilter{
ListQueryFilter: types.ListQueryFilter{
Query: ParseQuery(r),
Pagination: ParsePaginationFromRequest(r),
},
Latest: GetLatestFromPath(r),
LastExecutions: lastExecs,
}, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/git_test.go | app/api/request/git_test.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"net/url"
"reflect"
"testing"
"github.com/harness/gitness/git/api"
)
func TestGetFileDiffRequestsFromQuery(t *testing.T) {
type args struct {
r *http.Request
}
tests := []struct {
name string
args args
wantFiles api.FileDiffRequests
}{
{
name: "full range",
args: args{
r: &http.Request{
URL: &url.URL{
Path: "/diff",
RawQuery: "path=file.txt&range=1:20",
},
},
},
wantFiles: api.FileDiffRequests{
{
Path: "file.txt",
StartLine: 1,
EndLine: 20,
},
},
},
{
name: "start range",
args: args{
r: &http.Request{
URL: &url.URL{
Path: "/diff",
RawQuery: "path=file.txt&range=1",
},
},
},
wantFiles: api.FileDiffRequests{
{
Path: "file.txt",
StartLine: 1,
},
},
},
{
name: "end range",
args: args{
r: &http.Request{
URL: &url.URL{
Path: "/diff",
RawQuery: "path=file.txt&range=:20",
},
},
},
wantFiles: api.FileDiffRequests{
{
Path: "file.txt",
EndLine: 20,
},
},
},
{
name: "multi path",
args: args{
r: &http.Request{
URL: &url.URL{
Path: "/diff",
RawQuery: "path=file.txt&range=:20&path=file1.txt&range=&path=file2.txt&range=1:15",
},
},
},
wantFiles: api.FileDiffRequests{
{
Path: "file.txt",
EndLine: 20,
},
{
Path: "file1.txt",
},
{
Path: "file2.txt",
StartLine: 1,
EndLine: 15,
},
},
},
{
name: "multi path without some range",
args: args{
r: &http.Request{
URL: &url.URL{
Path: "/diff",
RawQuery: "path=file.txt&range=:20&path=file1.txt&path=file2.txt&range=1:15",
},
},
},
wantFiles: api.FileDiffRequests{
{
Path: "file.txt",
EndLine: 20,
},
{
Path: "file1.txt",
StartLine: 1,
EndLine: 15,
},
{
Path: "file2.txt",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotFiles := GetFileDiffFromQuery(tt.args.r); !reflect.DeepEqual(gotFiles, tt.wantFiles) {
t.Errorf("GetFileDiffFromQuery() = %v, want %v", gotFiles, tt.wantFiles)
}
})
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/util_test.go | app/api/request/util_test.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/principal.go | app/api/request/principal.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
PathParamPrincipalUID = "principal_uid"
PathParamUserUID = "user_uid"
PathParamUserID = "user_id"
PathParamServiceAccountUID = "sa_uid"
PathParamPrincipalID = "principal_id"
)
// GetUserIDFromPath returns the user id from the request path.
func GetUserIDFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamUserID)
}
// GetPrincipalIDFromPath returns the user id from the request path.
func GetPrincipalIDFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamPrincipalID)
}
func GetPrincipalUIDFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamPrincipalUID)
}
func GetUserUIDFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamUserUID)
}
func GetServiceAccountUIDFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamServiceAccountUID)
}
// ParseSortUser extracts the user sort parameter from the url.
func ParseSortUser(r *http.Request) enum.UserAttr {
return enum.ParseUserAttr(
r.URL.Query().Get(QueryParamSort),
)
}
// ParseUserFilter extracts the user filter from the url.
func ParseUserFilter(r *http.Request) *types.UserFilter {
return &types.UserFilter{
Order: ParseOrder(r),
Page: ParsePage(r),
Sort: ParseSortUser(r),
Size: ParseLimit(r),
}
}
// ParsePrincipalTypes extracts the principal types from the url.
func ParsePrincipalTypes(r *http.Request) []enum.PrincipalType {
pTypesRaw := r.URL.Query()[QueryParamType]
m := make(map[enum.PrincipalType]struct{}) // use map to eliminate duplicates
for _, pTypeRaw := range pTypesRaw {
if pType, ok := enum.PrincipalType(pTypeRaw).Sanitize(); ok {
m[pType] = struct{}{}
}
}
res := make([]enum.PrincipalType, 0, len(m))
for t := range m {
res = append(res, t)
}
return res
}
// ParsePrincipalFilter extracts the principal filter from the url.
func ParsePrincipalFilter(r *http.Request) *types.PrincipalFilter {
return &types.PrincipalFilter{
Query: ParseQuery(r),
Page: ParsePage(r),
Size: ParseLimit(r),
Types: ParsePrincipalTypes(r),
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/common.go | app/api/request/common.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"fmt"
"net/http"
"strconv"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
const (
PathParamRemainder = "*"
QueryParamCreatedBy = "created_by"
QueryParamSort = "sort"
QueryParamOrder = "order"
QueryParamQuery = "query"
QueryParamRecursive = "recursive"
QueryParamLabelID = "label_id"
QueryParamValueID = "value_id"
QueryParamState = "state"
QueryParamKind = "kind"
QueryParamType = "type"
QueryParamAfter = "after"
QueryParamBefore = "before"
QueryParamDeletedBeforeOrAt = "deleted_before_or_at"
QueryParamDeletedAt = "deleted_at"
QueryParamCreatedLt = "created_lt"
QueryParamCreatedGt = "created_gt"
QueryParamUpdatedLt = "updated_lt"
QueryParamUpdatedGt = "updated_gt"
QueryParamEditedLt = "edited_lt"
QueryParamEditedGt = "edited_gt"
QueryParamPage = "page"
QueryParamLimit = "limit"
PerPageDefault = 30
PerPageMax = 100
QueryParamInherited = "inherited"
QueryParamAssignable = "assignable"
QueryParamIncludePullreqCount = "include_pullreq_count"
QueryParamIncludeValues = "include_values"
// TODO: have shared constants across all services?
HeaderRequestID = "X-Request-Id"
HeaderUserAgent = "User-Agent"
HeaderAuthorization = "Authorization"
HeaderContentEncoding = "Content-Encoding"
HeaderIfNoneMatch = "If-None-Match"
HeaderETag = "ETag"
HeaderSignature = "Signature"
)
// GetOptionalRemainderFromPath returns the remainder ("*") from the path or an empty string if it doesn't exist.
func GetOptionalRemainderFromPath(r *http.Request) string {
return PathParamOrEmpty(r, PathParamRemainder)
}
// GetRemainderFromPath returns the remainder ("*") from the path or an error if it doesn't exist.
func GetRemainderFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamRemainder)
}
// ParseQuery extracts the query parameter from the url.
func ParseQuery(r *http.Request) string {
return r.URL.Query().Get(QueryParamQuery)
}
// ParsePage extracts the page parameter from the url.
func ParsePage(r *http.Request) int {
s := r.URL.Query().Get(QueryParamPage)
i, _ := strconv.Atoi(s)
if i <= 0 {
i = 1
}
return i
}
// ParseLimit extracts the limit parameter from the url.
//
//nolint:gosec
func ParseLimit(r *http.Request) int {
return int(ParseLimitOrDefaultWithMax(r, PerPageDefault, PerPageMax))
}
// ParseLimitOrDefaultWithMax extracts the limit parameter from the url and defaults to deflt if not found.
func ParseLimitOrDefaultWithMax(r *http.Request, deflt uint64, mx uint64) uint64 {
s := r.URL.Query().Get(QueryParamLimit)
i, _ := strconv.ParseUint(s, 10, 64)
if i <= 0 {
i = deflt
}
if i > mx {
i = mx
}
return i
}
// ParseOrder extracts the order parameter from the url.
func ParseOrder(r *http.Request) enum.Order {
return enum.ParseOrder(
r.URL.Query().Get(QueryParamOrder),
)
}
// ParseSort extracts the sort parameter from the url.
func ParseSort(r *http.Request) string {
return r.URL.Query().Get(QueryParamSort)
}
// ParsePaginationFromRequest parses pagination related info from the url.
func ParsePaginationFromRequest(r *http.Request) types.Pagination {
return types.Pagination{
Page: ParsePage(r),
Size: ParseLimit(r),
}
}
// ParseListQueryFilterFromRequest parses pagination and query related info from the url.
func ParseListQueryFilterFromRequest(r *http.Request) types.ListQueryFilter {
return types.ListQueryFilter{
Query: ParseQuery(r),
Pagination: ParsePaginationFromRequest(r),
}
}
// ParseCreated extracts the created filter from the url query param.
func ParseCreated(r *http.Request) (types.CreatedFilter, error) {
createdLt, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamCreatedLt, 0)
if err != nil {
return types.CreatedFilter{}, fmt.Errorf("encountered error parsing created lt: %w", err)
}
createdGt, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamCreatedGt, 0)
if err != nil {
return types.CreatedFilter{}, fmt.Errorf("encountered error parsing created gt: %w", err)
}
return types.CreatedFilter{
CreatedGt: createdGt,
CreatedLt: createdLt,
}, nil
}
// ParseUpdated extracts the updated filter from the url query param.
func ParseUpdated(r *http.Request) (types.UpdatedFilter, error) {
updatedLt, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamUpdatedLt, 0)
if err != nil {
return types.UpdatedFilter{}, fmt.Errorf("encountered error parsing updated lt: %w", err)
}
updatedGt, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamUpdatedGt, 0)
if err != nil {
return types.UpdatedFilter{}, fmt.Errorf("encountered error parsing updated gt: %w", err)
}
return types.UpdatedFilter{
UpdatedGt: updatedGt,
UpdatedLt: updatedLt,
}, nil
}
// ParseEdited extracts the edited filter from the url query param.
func ParseEdited(r *http.Request) (types.EditedFilter, error) {
editedLt, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamEditedLt, 0)
if err != nil {
return types.EditedFilter{}, fmt.Errorf("encountered error parsing edited lt: %w", err)
}
editedGt, err := QueryParamAsPositiveInt64OrDefault(r, QueryParamEditedGt, 0)
if err != nil {
return types.EditedFilter{}, fmt.Errorf("encountered error parsing edited gt: %w", err)
}
return types.EditedFilter{
EditedGt: editedGt,
EditedLt: editedLt,
}, nil
}
// GetContentEncodingFromHeadersOrDefault returns the content encoding from the request headers.
func GetContentEncodingFromHeadersOrDefault(r *http.Request, dflt string) string {
return GetHeaderOrDefault(r, HeaderContentEncoding, dflt)
}
// ParseRecursiveFromQuery extracts the recursive option from the URL query.
func ParseRecursiveFromQuery(r *http.Request) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamRecursive, false)
}
// ParseInheritedFromQuery extracts the inherited option from the URL query.
func ParseInheritedFromQuery(r *http.Request) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamInherited, false)
}
// ParseIncludePullreqCountFromQuery extracts the pullreq assignment count option from the URL query.
func ParseIncludePullreqCountFromQuery(r *http.Request) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludePullreqCount, false)
}
// ParseIncludeValuesFromQuery extracts the inclue values option from the URL query.
func ParseIncludeValuesFromQuery(r *http.Request) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamIncludeValues, false)
}
// ParseAssignableFromQuery extracts the assignable option from the URL query.
func ParseAssignableFromQuery(r *http.Request) (bool, error) {
return QueryParamAsBoolOrDefault(r, QueryParamAssignable, false)
}
// GetDeletedAtFromQueryOrError gets the exact resource deletion timestamp from the query.
func GetDeletedAtFromQueryOrError(r *http.Request) (int64, error) {
return QueryParamAsPositiveInt64OrError(r, QueryParamDeletedAt)
}
// GetDeletedBeforeOrAtFromQuery gets the resource deletion timestamp from the query as an optional parameter.
func GetDeletedBeforeOrAtFromQuery(r *http.Request) (int64, bool, error) {
return QueryParamAsPositiveInt64(r, QueryParamDeletedBeforeOrAt)
}
// GetDeletedAtFromQuery gets the exact resource deletion timestamp from the query as an optional parameter.
func GetDeletedAtFromQuery(r *http.Request) (int64, bool, error) {
return QueryParamAsPositiveInt64(r, QueryParamDeletedAt)
}
func GetIfNoneMatchFromHeader(r *http.Request) (string, bool) {
return GetHeader(r, HeaderIfNoneMatch)
}
func GetSignatureFromHeaderOrDefault(r *http.Request, dflt string) string {
return GetHeaderOrDefault(r, HeaderSignature, dflt)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/request/label.go | app/api/request/label.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package request
import (
"net/http"
"github.com/harness/gitness/types"
)
const (
PathParamLabelKey = "label_key"
PathParamLabelValue = "label_value"
PathParamLabelID = "label_id"
)
func GetLabelKeyFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamLabelKey)
}
func GetLabelValueFromPath(r *http.Request) (string, error) {
return PathParamOrError(r, PathParamLabelValue)
}
func GetLabelIDFromPath(r *http.Request) (int64, error) {
return PathParamAsPositiveInt64(r, PathParamLabelID)
}
// ParseLabelFilter extracts the label filter from the url.
func ParseLabelFilter(r *http.Request) (*types.LabelFilter, error) {
// inherited is used to list labels from parent scopes
inherited, err := ParseInheritedFromQuery(r)
if err != nil {
return nil, err
}
includeCount, err := ParseIncludePullreqCountFromQuery(r)
if err != nil {
return nil, err
}
return &types.LabelFilter{
ListQueryFilter: ParseListQueryFilterFromRequest(r),
Inherited: inherited,
IncludePullreqCount: includeCount,
}, nil
}
// ParseAssignableLabelFilter extracts the assignable label filter from the url.
func ParseAssignableLabelFilter(r *http.Request) (*types.AssignableLabelFilter, error) {
// assignable is used to list all labels assignable to pullreq
assignable, err := ParseAssignableFromQuery(r)
if err != nil {
return nil, err
}
return &types.AssignableLabelFilter{
Assignable: assignable,
ListQueryFilter: ParseListQueryFilterFromRequest(r),
}, nil
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/wire.go | app/api/openapi/wire.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"github.com/google/wire"
)
// WireSet provides a wire set for this package.
var WireSet = wire.NewSet(
ProvideOpenAPIService,
)
func ProvideOpenAPIService() Service {
return NewOpenAPIService()
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/infra_provider.go | app/api/openapi/infra_provider.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/infraprovider"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types"
"github.com/swaggest/openapi-go/openapi3"
)
type createInfraProviderConfigRequest struct {
infraprovider.ConfigInput
}
type getInfraProviderRequest struct {
Ref string `path:"infraprovider_identifier"`
}
func infraProviderOperations(reflector *openapi3.Reflector) {
opFind := openapi3.Operation{}
opFind.WithTags("infraproviders")
opFind.WithSummary("Get infraProviderConfig")
opFind.WithMapOfAnything(map[string]any{"operationId": "getInfraProvider"})
_ = reflector.SetRequest(&opFind, new(getInfraProviderRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opFind, new(types.InfraProviderConfig), http.StatusOK)
_ = reflector.SetJSONResponse(&opFind, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opFind, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opFind, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(
http.MethodGet, "/infraproviders/{infraprovider_identifier}", opFind)
opCreate := openapi3.Operation{}
opCreate.WithTags("infraproviders")
opCreate.WithSummary("Create infraProvider config")
opCreate.WithMapOfAnything(map[string]any{"operationId": "createInfraProvider"})
_ = reflector.SetRequest(&opCreate, new(createInfraProviderConfigRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opCreate, new(types.InfraProviderConfig), 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, "/infraproviders", opCreate)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/rules.go | app/api/openapi/rules.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/app/services/protection"
"github.com/harness/gitness/app/services/rules"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
// RuleType is a plugin for types.RuleType to allow using oneof.
type RuleType string
func (RuleType) Enum() []any {
return []any{protection.TypeBranch, protection.TypeTag, protection.TypePush}
}
// RuleDefinition is a plugin for types.Rule Definition to allow using oneof.
type RuleDefinition struct{}
func (RuleDefinition) JSONSchemaOneOf() []any {
return []any{protection.Branch{}, protection.Tag{}, protection.Push{}}
}
type Rule struct {
types.Rule
// overshadow Type and Definition to enable oneof.
Type RuleType `json:"type"`
Definition RuleDefinition `json:"definition"`
// overshadow Pattern to correct the type
Pattern protection.Pattern `json:"pattern"`
// overshadow RepoTarget to correct the type
RepoTarget protection.RepoTarget `json:"repo_target"`
}
var QueryParameterRuleTypes = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamType,
In: openapi3.ParameterInQuery,
Description: ptr.String("The types of rules to include."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Enum: RuleType("").Enum(),
},
},
},
},
Style: ptr.String(string(openapi3.EncodingStyleForm)),
Explode: ptr.Bool(true),
},
}
var queryParameterQueryRuleList = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring by which the repository protection rules are filtered."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterSortRuleList = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The field by which the protection rules are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.RuleSortCreated),
Enum: enum.RuleSort("").Enum(),
},
},
},
}
func rulesOperations(reflector *openapi3.Reflector) {
opSpaceRuleAdd := openapi3.Operation{}
opSpaceRuleAdd.WithTags("space")
opSpaceRuleAdd.WithMapOfAnything(map[string]any{"operationId": "spaceRuleAdd"})
_ = reflector.SetRequest(&opSpaceRuleAdd, struct {
spaceRequest
rules.CreateInput
// overshadow "definition"
Type RuleType `json:"type"`
Definition RuleDefinition `json:"definition"`
}{}, http.MethodPost)
_ = reflector.SetJSONResponse(&opSpaceRuleAdd, Rule{}, http.StatusCreated)
_ = reflector.SetJSONResponse(&opSpaceRuleAdd, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opSpaceRuleAdd, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opSpaceRuleAdd, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opSpaceRuleAdd, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{space_ref}/rules", opSpaceRuleAdd)
opSpaceRuleDelete := openapi3.Operation{}
opSpaceRuleDelete.WithTags("space")
opSpaceRuleDelete.WithMapOfAnything(map[string]any{"operationId": "spaceRuleDelete"})
_ = reflector.SetRequest(&opSpaceRuleDelete, struct {
spaceRequest
RuleIdentifier string `path:"rule_identifier"`
}{}, http.MethodDelete)
_ = reflector.SetJSONResponse(&opSpaceRuleDelete, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&opSpaceRuleDelete, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opSpaceRuleDelete, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opSpaceRuleDelete, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opSpaceRuleDelete, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodDelete, "/spaces/{space_ref}/rules/{rule_identifier}", opSpaceRuleDelete)
opSpaceRuleUpdate := openapi3.Operation{}
opSpaceRuleUpdate.WithTags("space")
opSpaceRuleUpdate.WithMapOfAnything(map[string]any{"operationId": "spaceRuleUpdate"})
_ = reflector.SetRequest(&opSpaceRuleUpdate, &struct {
spaceRequest
Identifier string `path:"rule_identifier"`
rules.UpdateInput
// overshadow Type and Definition to enable oneof.
Type RuleType `json:"type"`
Definition RuleDefinition `json:"definition"`
}{}, http.MethodPatch)
_ = reflector.SetJSONResponse(&opSpaceRuleUpdate, Rule{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opSpaceRuleUpdate, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opSpaceRuleUpdate, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opSpaceRuleUpdate, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opSpaceRuleUpdate, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/spaces/{space_ref}/rules/{rule_identifier}", opSpaceRuleUpdate)
opSpaceRuleList := openapi3.Operation{}
opSpaceRuleList.WithTags("space")
opSpaceRuleList.WithMapOfAnything(map[string]any{"operationId": "spaceRuleList"})
opSpaceRuleList.WithParameters(
queryParameterQueryRuleList, QueryParameterRuleTypes,
queryParameterOrder, queryParameterSortRuleList,
QueryParameterPage, QueryParameterLimit, QueryParameterInherited)
_ = reflector.SetRequest(&opSpaceRuleList, &struct {
spaceRequest
}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&opSpaceRuleList, []Rule{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opSpaceRuleList, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opSpaceRuleList, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opSpaceRuleList, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opSpaceRuleList, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/rules", opSpaceRuleList)
opSpaceRuleGet := openapi3.Operation{}
opSpaceRuleGet.WithTags("space")
opSpaceRuleGet.WithMapOfAnything(map[string]any{"operationId": "spaceRuleGet"})
_ = reflector.SetRequest(&opSpaceRuleGet, &struct {
spaceRequest
Identifier string `path:"rule_identifier"`
}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&opSpaceRuleGet, Rule{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opSpaceRuleGet, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opSpaceRuleGet, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opSpaceRuleGet, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opSpaceRuleGet, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/rules/{rule_identifier}", opSpaceRuleGet)
opRepoRuleAdd := openapi3.Operation{}
opRepoRuleAdd.WithTags("repository")
opRepoRuleAdd.WithMapOfAnything(map[string]any{"operationId": "repoRuleAdd"})
_ = reflector.SetRequest(&opRepoRuleAdd, struct {
repoRequest
rules.CreateInput
// overshadow "definition"
Type RuleType `json:"type"`
Definition RuleDefinition `json:"definition"`
}{}, http.MethodPost)
_ = reflector.SetJSONResponse(&opRepoRuleAdd, Rule{}, http.StatusCreated)
_ = reflector.SetJSONResponse(&opRepoRuleAdd, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opRepoRuleAdd, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opRepoRuleAdd, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opRepoRuleAdd, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{repo_ref}/rules", opRepoRuleAdd)
opRepoRuleDelete := openapi3.Operation{}
opRepoRuleDelete.WithTags("repository")
opRepoRuleDelete.WithMapOfAnything(map[string]any{"operationId": "repoRuleDelete"})
_ = reflector.SetRequest(&opRepoRuleDelete, struct {
repoRequest
RuleIdentifier string `path:"rule_identifier"`
}{}, http.MethodDelete)
_ = reflector.SetJSONResponse(&opRepoRuleDelete, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&opRepoRuleDelete, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opRepoRuleDelete, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opRepoRuleDelete, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opRepoRuleDelete, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodDelete, "/repos/{repo_ref}/rules/{rule_identifier}", opRepoRuleDelete)
opRepoRuleUpdate := openapi3.Operation{}
opRepoRuleUpdate.WithTags("repository")
opRepoRuleUpdate.WithMapOfAnything(map[string]any{"operationId": "repoRuleUpdate"})
_ = reflector.SetRequest(&opRepoRuleUpdate, &struct {
repoRequest
Identifier string `path:"rule_identifier"`
rules.UpdateInput
// overshadow Type and Definition to enable oneof.
Type RuleType `json:"type"`
Definition RuleDefinition `json:"definition"`
}{}, http.MethodPatch)
_ = reflector.SetJSONResponse(&opRepoRuleUpdate, Rule{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opRepoRuleUpdate, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opRepoRuleUpdate, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opRepoRuleUpdate, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opRepoRuleUpdate, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/repos/{repo_ref}/rules/{rule_identifier}", opRepoRuleUpdate)
opRepoRuleList := openapi3.Operation{}
opRepoRuleList.WithTags("repository")
opRepoRuleList.WithMapOfAnything(map[string]any{"operationId": "repoRuleList"})
opRepoRuleList.WithParameters(
queryParameterQueryRuleList, QueryParameterRuleTypes,
queryParameterOrder, queryParameterSortRuleList,
QueryParameterPage, QueryParameterLimit, QueryParameterInherited)
_ = reflector.SetRequest(&opRepoRuleList, &struct {
repoRequest
}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&opRepoRuleList, []Rule{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opRepoRuleList, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opRepoRuleList, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opRepoRuleList, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opRepoRuleList, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/rules", opRepoRuleList)
opRepoRuleGet := openapi3.Operation{}
opRepoRuleGet.WithTags("repository")
opRepoRuleGet.WithMapOfAnything(map[string]any{"operationId": "repoRuleGet"})
_ = reflector.SetRequest(&opRepoRuleGet, &struct {
repoRequest
Identifier string `path:"rule_identifier"`
}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&opRepoRuleGet, Rule{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opRepoRuleGet, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opRepoRuleGet, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opRepoRuleGet, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opRepoRuleGet, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/rules/{rule_identifier}", opRepoRuleGet)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/webhook.go | app/api/openapi/webhook.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
// webhookType is used to add has_secret field.
type webhookType struct {
types.Webhook
HasSecret bool `json:"has_secret"`
}
type createSpaceWebhookRequest struct {
spaceRequest
types.WebhookCreateInput
}
type createRepoWebhookRequest struct {
repoRequest
types.WebhookCreateInput
}
type listSpaceWebhooksRequest struct {
spaceRequest
}
type listRepoWebhooksRequest struct {
repoRequest
}
type spaceWebhookRequest struct {
spaceRequest
ID int64 `path:"webhook_identifier"`
}
type repoWebhookRequest struct {
repoRequest
ID int64 `path:"webhook_identifier"`
}
type getSpaceWebhookRequest struct {
spaceWebhookRequest
}
type getRepoWebhookRequest struct {
repoWebhookRequest
}
type deleteSpaceWebhookRequest struct {
spaceWebhookRequest
}
type deleteRepoWebhookRequest struct {
repoWebhookRequest
}
type updateSpaceWebhookRequest struct {
spaceWebhookRequest
types.WebhookUpdateInput
}
type updateRepoWebhookRequest struct {
repoWebhookRequest
types.WebhookUpdateInput
}
type listSpaceWebhookExecutionsRequest struct {
spaceWebhookRequest
}
type listRepoWebhookExecutionsRequest struct {
repoWebhookRequest
}
type spaceWebhookExecutionRequest struct {
spaceWebhookRequest
ID int64 `path:"webhook_execution_id"`
}
type repoWebhookExecutionRequest struct {
repoWebhookRequest
ID int64 `path:"webhook_execution_id"`
}
type getSpaceWebhookExecutionRequest struct {
spaceWebhookExecutionRequest
}
type getRepoWebhookExecutionRequest struct {
repoWebhookExecutionRequest
}
var queryParameterSortWebhook = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The data by which the webhooks are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.WebhookAttrIdentifier.String()),
Enum: []any{
// TODO [CODE-1364]: Remove once UID/Identifier migration is completed.
ptr.String(enum.WebhookAttrID.String()),
ptr.String(enum.WebhookAttrUID.String()),
// TODO [CODE-1364]: Remove once UID/Identifier migration is completed.
ptr.String(enum.WebhookAttrDisplayName.String()),
ptr.String(enum.WebhookAttrCreated.String()),
ptr.String(enum.WebhookAttrUpdated.String()),
},
},
},
},
}
var queryParameterQueryWebhook = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring which is used to filter the webhooks by their identifier."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
//nolint:funlen
func webhookOperations(reflector *openapi3.Reflector) {
// space
createSpaceWebhook := openapi3.Operation{}
createSpaceWebhook.WithTags("webhook")
createSpaceWebhook.WithMapOfAnything(map[string]any{"operationId": "createSpaceWebhook"})
_ = reflector.SetRequest(&createSpaceWebhook, new(createSpaceWebhookRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&createSpaceWebhook, new(webhookType), http.StatusCreated)
_ = reflector.SetJSONResponse(&createSpaceWebhook, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&createSpaceWebhook, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&createSpaceWebhook, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&createSpaceWebhook, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{space_ref}/webhooks", createSpaceWebhook)
listSpaceWebhooks := openapi3.Operation{}
listSpaceWebhooks.WithTags("webhook")
listSpaceWebhooks.WithMapOfAnything(map[string]any{"operationId": "listSpaceWebhooks"})
listSpaceWebhooks.WithParameters(queryParameterQueryWebhook, queryParameterSortWebhook, queryParameterOrder,
QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&listSpaceWebhooks, new(listSpaceWebhooksRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&listSpaceWebhooks, new([]webhookType), http.StatusOK)
_ = reflector.SetJSONResponse(&listSpaceWebhooks, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&listSpaceWebhooks, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&listSpaceWebhooks, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&listSpaceWebhooks, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/webhooks", listSpaceWebhooks)
getSpaceWebhook := openapi3.Operation{}
getSpaceWebhook.WithTags("webhook")
getSpaceWebhook.WithMapOfAnything(map[string]any{"operationId": "getSpaceWebhook"})
_ = reflector.SetRequest(&getSpaceWebhook, new(getSpaceWebhookRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&getSpaceWebhook, new(webhookType), http.StatusOK)
_ = reflector.SetJSONResponse(&getSpaceWebhook, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&getSpaceWebhook, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&getSpaceWebhook, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&getSpaceWebhook, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/webhooks/{webhook_identifier}", getSpaceWebhook)
updateSpaceWebhook := openapi3.Operation{}
updateSpaceWebhook.WithTags("webhook")
updateSpaceWebhook.WithMapOfAnything(map[string]any{"operationId": "updateWebhook"})
_ = reflector.SetRequest(&updateSpaceWebhook, new(updateSpaceWebhookRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&updateSpaceWebhook, new(webhookType), http.StatusOK)
_ = reflector.SetJSONResponse(&updateSpaceWebhook, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&updateSpaceWebhook, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&updateSpaceWebhook, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&updateSpaceWebhook, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(
http.MethodPatch, "/spaces/{space_ref}/webhooks/{webhook_identifier}", updateSpaceWebhook,
)
deleteSpaceWebhook := openapi3.Operation{}
deleteSpaceWebhook.WithTags("webhook")
deleteSpaceWebhook.WithMapOfAnything(map[string]any{"operationId": "deleteWebhook"})
_ = reflector.SetRequest(&deleteSpaceWebhook, new(deleteSpaceWebhookRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&deleteSpaceWebhook, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&deleteSpaceWebhook, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&deleteSpaceWebhook, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&deleteSpaceWebhook, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&deleteSpaceWebhook, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(
http.MethodDelete, "/spaces/{space_ref}/webhooks/{webhook_identifier}", deleteSpaceWebhook,
)
listSpaceWebhookExecutions := openapi3.Operation{}
listSpaceWebhookExecutions.WithTags("webhook")
listSpaceWebhookExecutions.WithMapOfAnything(map[string]any{"operationId": "listSpaceWebhookExecutions"})
listSpaceWebhookExecutions.WithParameters(QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&listSpaceWebhookExecutions, new(listSpaceWebhookExecutionsRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&listSpaceWebhookExecutions, new([]types.WebhookExecution), http.StatusOK)
_ = reflector.SetJSONResponse(&listSpaceWebhookExecutions, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&listSpaceWebhookExecutions, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&listSpaceWebhookExecutions, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&listSpaceWebhookExecutions, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet,
"/spaces/{space_ref}/webhooks/{webhook_identifier}/executions", listSpaceWebhookExecutions)
getSpaceWebhookExecution := openapi3.Operation{}
getSpaceWebhookExecution.WithTags("webhook")
getSpaceWebhookExecution.WithMapOfAnything(map[string]any{"operationId": "getSpaceWebhookExecution"})
getSpaceWebhookExecution.WithParameters(QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&getSpaceWebhookExecution, new(getSpaceWebhookExecutionRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&getSpaceWebhookExecution, new(types.WebhookExecution), http.StatusOK)
_ = reflector.SetJSONResponse(&getSpaceWebhookExecution, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&getSpaceWebhookExecution, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&getSpaceWebhookExecution, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&getSpaceWebhookExecution, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet,
"/spaces/{space_ref}/webhooks/{webhook_identifier}/executions/{webhook_execution_id}",
getSpaceWebhookExecution,
)
retriggerSpaceWebhookExecution := openapi3.Operation{}
retriggerSpaceWebhookExecution.WithTags("webhook")
retriggerSpaceWebhookExecution.WithMapOfAnything(
map[string]any{"operationId": "retriggerSpaceWebhookExecution"},
)
_ = reflector.SetRequest(&retriggerSpaceWebhookExecution, new(spaceWebhookExecutionRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&retriggerSpaceWebhookExecution, new(types.WebhookExecution), http.StatusOK)
_ = reflector.SetJSONResponse(&retriggerSpaceWebhookExecution, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&retriggerSpaceWebhookExecution, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&retriggerSpaceWebhookExecution, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&retriggerSpaceWebhookExecution, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost,
"/spaces/{space_ref}/webhooks/{webhook_identifier}/executions/{webhook_execution_id}/retrigger",
retriggerSpaceWebhookExecution,
)
// repo
createRepoWebhook := openapi3.Operation{}
createRepoWebhook.WithTags("webhook")
createRepoWebhook.WithMapOfAnything(map[string]any{"operationId": "createRepoWebhook"})
_ = reflector.SetRequest(&createRepoWebhook, new(createRepoWebhookRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&createRepoWebhook, new(webhookType), http.StatusCreated)
_ = reflector.SetJSONResponse(&createRepoWebhook, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&createRepoWebhook, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&createRepoWebhook, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&createRepoWebhook, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{repo_ref}/webhooks", createRepoWebhook)
listRepoWebhooks := openapi3.Operation{}
listRepoWebhooks.WithTags("webhook")
listRepoWebhooks.WithMapOfAnything(map[string]any{"operationId": "listRepoWebhooks"})
listRepoWebhooks.WithParameters(queryParameterQueryWebhook, queryParameterSortWebhook, queryParameterOrder,
QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&listRepoWebhooks, new(listRepoWebhooksRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&listRepoWebhooks, new([]webhookType), http.StatusOK)
_ = reflector.SetJSONResponse(&listRepoWebhooks, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&listRepoWebhooks, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&listRepoWebhooks, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&listRepoWebhooks, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/webhooks", listRepoWebhooks)
getRepoWebhook := openapi3.Operation{}
getRepoWebhook.WithTags("webhook")
getRepoWebhook.WithMapOfAnything(map[string]any{"operationId": "getRepoWebhook"})
_ = reflector.SetRequest(&getRepoWebhook, new(getRepoWebhookRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&getRepoWebhook, new(webhookType), http.StatusOK)
_ = reflector.SetJSONResponse(&getRepoWebhook, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&getRepoWebhook, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&getRepoWebhook, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&getRepoWebhook, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/webhooks/{webhook_identifier}", getRepoWebhook)
updateRepoWebhook := openapi3.Operation{}
updateRepoWebhook.WithTags("webhook")
updateRepoWebhook.WithMapOfAnything(map[string]any{"operationId": "updateRepoWebhook"})
_ = reflector.SetRequest(&updateRepoWebhook, new(updateRepoWebhookRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&updateRepoWebhook, new(webhookType), http.StatusOK)
_ = reflector.SetJSONResponse(&updateRepoWebhook, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&updateRepoWebhook, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&updateRepoWebhook, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&updateRepoWebhook, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/repos/{repo_ref}/webhooks/{webhook_identifier}", updateRepoWebhook)
deleteRepoWebhook := openapi3.Operation{}
deleteRepoWebhook.WithTags("webhook")
deleteRepoWebhook.WithMapOfAnything(map[string]any{"operationId": "deleteRepoWebhook"})
_ = reflector.SetRequest(&deleteRepoWebhook, new(deleteRepoWebhookRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&deleteRepoWebhook, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&deleteRepoWebhook, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&deleteRepoWebhook, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&deleteRepoWebhook, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&deleteRepoWebhook, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(
http.MethodDelete, "/repos/{repo_ref}/webhooks/{webhook_identifier}", deleteRepoWebhook,
)
listRepoWebhookExecutions := openapi3.Operation{}
listRepoWebhookExecutions.WithTags("webhook")
listRepoWebhookExecutions.WithMapOfAnything(map[string]any{"operationId": "listRepoWebhookExecutions"})
listRepoWebhookExecutions.WithParameters(QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&listRepoWebhookExecutions, new(listRepoWebhookExecutionsRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&listRepoWebhookExecutions, new([]types.WebhookExecution), http.StatusOK)
_ = reflector.SetJSONResponse(&listRepoWebhookExecutions, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&listRepoWebhookExecutions, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&listRepoWebhookExecutions, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&listRepoWebhookExecutions, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet,
"/repos/{repo_ref}/webhooks/{webhook_identifier}/executions", listRepoWebhookExecutions)
getRepoWebhookExecution := openapi3.Operation{}
getRepoWebhookExecution.WithTags("webhook")
getRepoWebhookExecution.WithMapOfAnything(map[string]any{"operationId": "getRepoWebhookExecution"})
getRepoWebhookExecution.WithParameters(QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&getRepoWebhookExecution, new(getRepoWebhookExecutionRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&getRepoWebhookExecution, new(types.WebhookExecution), http.StatusOK)
_ = reflector.SetJSONResponse(&getRepoWebhookExecution, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&getRepoWebhookExecution, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&getRepoWebhookExecution, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&getRepoWebhookExecution, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet,
"/repos/{repo_ref}/webhooks/{webhook_identifier}/executions/{webhook_execution_id}", getRepoWebhookExecution)
retriggerRepoWebhookExecution := openapi3.Operation{}
retriggerRepoWebhookExecution.WithTags("webhook")
retriggerRepoWebhookExecution.WithMapOfAnything(map[string]any{"operationId": "retriggerRepoWebhookExecution"})
_ = reflector.SetRequest(&retriggerRepoWebhookExecution, new(repoWebhookExecutionRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&retriggerRepoWebhookExecution, new(types.WebhookExecution), http.StatusOK)
_ = reflector.SetJSONResponse(&retriggerRepoWebhookExecution, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&retriggerRepoWebhookExecution, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&retriggerRepoWebhookExecution, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&retriggerRepoWebhookExecution, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost,
"/repos/{repo_ref}/webhooks/{webhook_identifier}/executions/{webhook_execution_id}/retrigger",
retriggerRepoWebhookExecution)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/openapi_test.go | app/api/openapi/openapi_test.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/service.go | app/api/openapi/service.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import "github.com/swaggest/openapi-go/openapi3"
type Service interface {
Generate() *openapi3.Spec
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/principals.go | app/api/openapi/principals.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
type principalInfoRequest struct {
ID int64 `path:"id"`
}
var QueryParameterQueryPrincipals = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring by which the principals are filtered."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var QueryParameterPrincipalTypes = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamType,
In: openapi3.ParameterInQuery,
Description: ptr.String("The types of principals to include."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Enum: enum.PrincipalType("").Enum(),
},
},
},
},
},
}
// buildPrincipals function that constructs the openapi specification
// for principal resources.
func buildPrincipals(reflector *openapi3.Reflector) {
opList := openapi3.Operation{}
opList.WithTags("principals")
opList.WithMapOfAnything(map[string]any{"operationId": "listPrincipals"})
opList.WithParameters(QueryParameterQueryPrincipals, QueryParameterPage,
QueryParameterLimit, QueryParameterPrincipalTypes)
_ = reflector.SetRequest(&opList, nil, http.MethodGet)
_ = reflector.SetJSONResponse(&opList, new([]types.PrincipalInfo), http.StatusOK)
_ = reflector.SetJSONResponse(&opList, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opList, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opList, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/principals", opList)
getPrincipal := openapi3.Operation{}
getPrincipal.WithTags("principals")
getPrincipal.WithMapOfAnything(map[string]any{"operationId": "getPrincipal"})
_ = reflector.SetRequest(&getPrincipal, new(principalInfoRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&getPrincipal, new(types.PrincipalInfo), http.StatusOK)
_ = reflector.SetJSONResponse(&getPrincipal, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&getPrincipal, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&getPrincipal, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&getPrincipal, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&getPrincipal, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/principals/{id}", getPrincipal)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/openapi.go | app/api/openapi/openapi.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"github.com/harness/gitness/app/config"
"github.com/harness/gitness/version"
"github.com/swaggest/openapi-go/openapi3"
)
type (
paginationRequest struct {
Page int `query:"page" default:"1"`
Size int `query:"limit" default:"30"`
}
)
var _ Service = (*OpenAPI)(nil)
type OpenAPI struct{}
func NewOpenAPIService() *OpenAPI {
return &OpenAPI{}
}
// Generate is a helper function that constructs the
// openapi specification object, which can be marshaled
// to json or yaml, as needed.
func (*OpenAPI) Generate() *openapi3.Spec {
reflector := openapi3.Reflector{}
reflector.Spec = &openapi3.Spec{Openapi: "3.0.0"}
reflector.Spec.Info.
WithTitle("API Specification").
WithVersion(version.Version.String())
reflector.Spec.Servers = []openapi3.Server{{
URL: config.APIURL,
}}
//
// register endpoints
//
buildSystem(&reflector)
buildAccount(&reflector)
buildUser(&reflector)
buildAdmin(&reflector)
buildPrincipals(&reflector)
spaceOperations(&reflector)
pluginOperations(&reflector)
repoOperations(&reflector)
rulesOperations(&reflector)
pipelineOperations(&reflector)
connectorOperations(&reflector)
templateOperations(&reflector)
secretOperations(&reflector)
resourceOperations(&reflector)
pullReqOperations(&reflector)
webhookOperations(&reflector)
checkOperations(&reflector)
uploadOperations(&reflector)
gitspaceOperations(&reflector)
infraProviderOperations(&reflector)
//
// define security scheme
//
scheme := openapi3.SecuritySchemeOrRef{
SecurityScheme: &openapi3.SecurityScheme{
HTTPSecurityScheme: &openapi3.HTTPSecurityScheme{
Scheme: "bearerAuth",
Bearer: &openapi3.Bearer{},
},
},
}
security := openapi3.ComponentsSecuritySchemes{}
security.WithMapOfSecuritySchemeOrRefValuesItem("bearerAuth", scheme)
reflector.Spec.Components.WithSecuritySchemes(security)
//
// enforce security scheme globally
//
reflector.Spec.WithSecurity(map[string][]string{
"bearerAuth": {},
})
return reflector.Spec
}
func panicOnErr(err error) {
if err != nil {
panic(err)
}
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/check.go | app/api/openapi/check.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/check"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
var queryParameterStatusCheckQuery = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring which is used to filter the status checks by their Identifier."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterStatusCheckSince = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSince,
In: openapi3.ParameterInQuery,
Description: ptr.String("The timestamp (in Unix time millis) since the status checks have been run."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
}
func checkOperations(reflector *openapi3.Reflector) {
const tag = "status_checks"
reportStatusCheckResults := openapi3.Operation{}
reportStatusCheckResults.WithTags(tag)
reportStatusCheckResults.WithMapOfAnything(map[string]any{"operationId": "reportStatusCheckResults"})
_ = reflector.SetRequest(&reportStatusCheckResults, struct {
repoRequest
CommitSHA string `path:"commit_sha"`
check.ReportInput
}{}, http.MethodPut)
_ = reflector.SetJSONResponse(&reportStatusCheckResults, new(types.Check), http.StatusOK)
_ = reflector.SetJSONResponse(&reportStatusCheckResults, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&reportStatusCheckResults, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&reportStatusCheckResults, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&reportStatusCheckResults, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPut, "/repos/{repo_ref}/checks/commits/{commit_sha}",
reportStatusCheckResults)
listStatusCheckResults := openapi3.Operation{}
listStatusCheckResults.WithTags(tag)
listStatusCheckResults.WithParameters(
QueryParameterPage, QueryParameterLimit, queryParameterStatusCheckQuery)
listStatusCheckResults.WithMapOfAnything(map[string]any{"operationId": "listStatusCheckResults"})
_ = reflector.SetRequest(&listStatusCheckResults, struct {
repoRequest
CommitSHA string `path:"commit_sha"`
}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&listStatusCheckResults, new([]types.Check), http.StatusOK)
_ = reflector.SetJSONResponse(&listStatusCheckResults, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&listStatusCheckResults, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&listStatusCheckResults, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&listStatusCheckResults, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/checks/commits/{commit_sha}",
listStatusCheckResults)
listStatusCheckRecent := openapi3.Operation{}
listStatusCheckRecent.WithTags(tag)
listStatusCheckRecent.WithParameters(
queryParameterStatusCheckQuery, queryParameterStatusCheckSince)
listStatusCheckRecent.WithMapOfAnything(map[string]any{"operationId": "listStatusCheckRecent"})
_ = reflector.SetRequest(&listStatusCheckRecent, struct {
repoRequest
Since int
}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&listStatusCheckRecent, new([]string), http.StatusOK)
_ = reflector.SetJSONResponse(&listStatusCheckRecent, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&listStatusCheckRecent, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&listStatusCheckRecent, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&listStatusCheckRecent, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/checks/recent",
listStatusCheckRecent)
listStatusCheckRecentSpace := openapi3.Operation{}
listStatusCheckRecentSpace.WithTags(tag)
listStatusCheckRecentSpace.WithParameters(
queryParameterStatusCheckQuery, queryParameterStatusCheckSince, QueryParameterRecursive)
listStatusCheckRecentSpace.WithMapOfAnything(map[string]any{"operationId": "listStatusCheckRecentSpace"})
_ = reflector.SetRequest(&listStatusCheckRecentSpace, struct {
spaceRequest
Since int
}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&listStatusCheckRecentSpace, new([]string), http.StatusOK)
_ = reflector.SetJSONResponse(&listStatusCheckRecentSpace, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&listStatusCheckRecentSpace, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&listStatusCheckRecentSpace, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&listStatusCheckRecentSpace, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/checks/recent",
listStatusCheckRecentSpace)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/system.go | app/api/openapi/system.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/handler/system"
"github.com/harness/gitness/app/api/usererror"
"github.com/swaggest/openapi-go/openapi3"
)
// helper function that constructs the openapi specification
// for the system registration config endpoints.
func buildSystem(reflector *openapi3.Reflector) {
opGetConfig := openapi3.Operation{}
opGetConfig.WithTags("system")
opGetConfig.WithMapOfAnything(map[string]any{"operationId": "getSystemConfig"})
_ = reflector.SetRequest(&opGetConfig, nil, http.MethodGet)
_ = reflector.SetJSONResponse(&opGetConfig, new(system.ConfigOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&opGetConfig, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opGetConfig, new(usererror.Error), http.StatusBadRequest)
_ = reflector.Spec.AddOperation(http.MethodGet, "/system/config", opGetConfig)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/pullreq.go | app/api/openapi/pullreq.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/pullreq"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/git"
gittypes "github.com/harness/gitness/git/api"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
type createPullReqRequest struct {
repoRequest
pullreq.CreateInput
}
type listPullReqRequest struct {
repoRequest
}
type pullReqRequest struct {
repoRequest
ID int64 `path:"pullreq_number"`
}
type getPullReqRequest struct {
pullReqRequest
}
type getPullReqByBranchesRequest struct {
repoRequest
SourceBranch string `path:"source_branch"`
TargetBranch string `path:"target_branch"`
}
type updatePullReqRequest struct {
pullReqRequest
pullreq.UpdateInput
}
type statePullReqRequest struct {
pullReqRequest
pullreq.StateInput
}
type listPullReqActivitiesRequest struct {
pullReqRequest
}
type userGroupReviewerAddRequest struct {
pullReqRequest
pullreq.UserGroupReviewerAddInput
}
type userGroupReviewerDeleteRequest struct {
pullReqRequest
ID int64 `path:"user_group_id"`
}
type mergePullReq struct {
pullReqRequest
pullreq.MergeInput
}
type commentCreatePullReqRequest struct {
pullReqRequest
pullreq.CommentCreateInput
}
type commentApplySuggestionstRequest struct {
pullReqRequest
pullreq.CommentApplySuggestionsInput
}
type pullReqCommentRequest struct {
pullReqRequest
ID int64 `path:"pullreq_comment_id"`
}
type commentUpdatePullReqRequest struct {
pullReqCommentRequest
pullreq.CommentUpdateInput
}
type commentDeletePullReqRequest struct {
pullReqCommentRequest
}
type commentStatusPullReqRequest struct {
pullReqCommentRequest
pullreq.CommentStatusInput
}
type reviewerListPullReqRequest struct {
pullReqRequest
}
type reviewerDeletePullReqRequest struct {
pullReqRequest
PullReqReviewerID int64 `path:"pullreq_reviewer_id"`
}
type reviewerAddPullReqRequest struct {
pullReqRequest
pullreq.ReviewerAddInput
}
type reviewSubmitPullReqRequest struct {
pullreq.ReviewSubmitInput
pullReqRequest
}
type fileViewAddPullReqRequest struct {
pullReqRequest
pullreq.FileViewAddInput
}
type fileViewListPullReqRequest struct {
pullReqRequest
}
type fileViewDeletePullReqRequest struct {
pullReqRequest
Path string `path:"file_path"`
}
type getRawPRDiffRequest struct {
pullReqRequest
Path []string `query:"path" description:"provide path for diff operation"`
IgnoreWhitespace bool `query:"ignore_whitespace" required:"false" default:"false"`
}
type postRawPRDiffRequest struct {
pullReqRequest
gittypes.FileDiffRequests
IgnoreWhitespace bool `query:"ignore_whitespace" required:"false" default:"false"`
}
type getPullReqChecksRequest struct {
pullReqRequest
}
type pullReqAssignLabelInput struct {
pullReqRequest
types.PullReqLabelAssignInput
}
var queryParameterQueryPullRequest = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring by which the pull requests are filtered."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterSourceRepoRefPullRequest = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSourceRepoRef,
In: openapi3.ParameterInQuery,
Description: ptr.String("Source repository ref of the pull requests."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterSourceBranchPullRequest = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSourceBranch,
In: openapi3.ParameterInQuery,
Description: ptr.String("Source branch of the pull requests."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterTargetBranchPullRequest = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamTargetBranch,
In: openapi3.ParameterInQuery,
Description: ptr.String("Target branch of the pull requests."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterCreatedByPullRequest = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamCreatedBy,
In: openapi3.ParameterInQuery,
Description: ptr.String("List of principal IDs who created pull requests."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
},
// making it look like created_by=1&created_by=2
Style: ptr.String(string(openapi3.EncodingStyleForm)),
Explode: ptr.Bool(true),
},
}
var queryParameterStatePullRequest = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamState,
In: openapi3.ParameterInQuery,
Description: ptr.String("The state of the pull requests to include in the result."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(string(enum.PullReqStateOpen)),
Enum: enum.PullReqState("").Enum(),
},
},
},
},
Style: ptr.String(string(openapi3.EncodingStyleForm)),
Explode: ptr.Bool(true),
},
}
var queryParameterSortPullRequest = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The data by which the pull requests are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.PullReqSortNumber),
Enum: enum.PullReqSort("").Enum(),
},
},
},
}
var queryParameterKindPullRequestActivity = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamKind,
In: openapi3.ParameterInQuery,
Description: ptr.String("The kind of the pull request activity to include in the result."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Enum: enum.PullReqActivityKind("").Enum(),
},
},
},
},
},
}
var queryParameterTypePullRequestActivity = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamType,
In: openapi3.ParameterInQuery,
Description: ptr.String("The type of the pull request activity to include in the result."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Enum: enum.PullReqActivityType("").Enum(),
},
},
},
},
},
}
var queryParameterBeforePullRequestActivity = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamBefore,
In: openapi3.ParameterInQuery,
Description: ptr.String("The result should contain only entries created before this timestamp (unix millis)."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
Minimum: ptr.Float64(0),
},
},
},
}
var QueryParameterAssignable = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamAssignable,
In: openapi3.ParameterInQuery,
Description: ptr.String("The result should contain all labels assignable to the pullreq."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var QueryParameterLabelID = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamLabelID,
In: openapi3.ParameterInQuery,
Description: ptr.String("List of label ids used to filter pull requests."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
},
// making it look like label_id=1&label_id=2
Style: ptr.String(string(openapi3.EncodingStyleForm)),
Explode: ptr.Bool(true),
},
}
var QueryParameterValueID = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamValueID,
In: openapi3.ParameterInQuery,
Description: ptr.String("List of label value ids used to filter pull requests."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
},
// making it look like value_id=1&value_id=2
Style: ptr.String(string(openapi3.EncodingStyleForm)),
Explode: ptr.Bool(true),
},
}
var queryParameterExcludeDescription = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamExcludeDescription,
In: openapi3.ParameterInQuery,
Description: ptr.String("By providing this parameter the description would be excluded from the response."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParameterAuthorID = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamAuthorID,
In: openapi3.ParameterInQuery,
Description: ptr.String("Return only pull requests where this user is the author."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
}
var queryParameterCommenterID = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamCommenterID,
In: openapi3.ParameterInQuery,
Description: ptr.String("Return only pull requests where this user has created at least one comment."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
}
var queryParameterReviewerID = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamReviewerID,
In: openapi3.ParameterInQuery,
Description: ptr.String("Return only pull requests where this user has been added as a reviewer."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
}
var queryParameterReviewDecision = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamReviewDecision,
In: openapi3.ParameterInQuery,
Description: ptr.String("Require only this review decision of the reviewer. " +
"Requires " + request.QueryParamReviewerID + " parameter."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Enum: enum.PullReqReviewDecision("").Enum(),
},
},
},
},
Style: ptr.String(string(openapi3.EncodingStyleForm)),
Explode: ptr.Bool(true),
},
}
var queryParameterMentionedID = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamMentionedID,
In: openapi3.ParameterInQuery,
Description: ptr.String("Return only pull requests where this user has been mentioned."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
}
//nolint:funlen
func pullReqOperations(reflector *openapi3.Reflector) {
createPullReq := openapi3.Operation{}
createPullReq.WithTags("pullreq")
createPullReq.WithMapOfAnything(map[string]any{"operationId": "createPullReq"})
_ = reflector.SetRequest(&createPullReq, new(createPullReqRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&createPullReq, new(types.PullReq), http.StatusCreated)
_ = reflector.SetJSONResponse(&createPullReq, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&createPullReq, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&createPullReq, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&createPullReq, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{repo_ref}/pullreq", createPullReq)
listPullReq := openapi3.Operation{}
listPullReq.WithTags("pullreq")
listPullReq.WithMapOfAnything(map[string]any{"operationId": "listPullReq"})
listPullReq.WithParameters(
queryParameterStatePullRequest, queryParameterSourceRepoRefPullRequest,
queryParameterSourceBranchPullRequest, queryParameterTargetBranchPullRequest,
queryParameterQueryPullRequest, queryParameterCreatedByPullRequest,
queryParameterOrder, queryParameterSortPullRequest,
queryParameterCreatedLt, queryParameterCreatedGt, queryParameterUpdatedLt, queryParameterUpdatedGt,
queryParameterExcludeDescription,
QueryParameterPage, QueryParameterLimit,
QueryParameterLabelID, QueryParameterValueID,
queryParameterAuthorID, queryParameterCommenterID, queryParameterMentionedID,
queryParameterReviewerID, queryParameterReviewDecision,
queryParamIncludeGitStats, queryParameterIncludeChecks, queryParameterIncludeRules)
_ = reflector.SetRequest(&listPullReq, new(listPullReqRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&listPullReq, new([]types.PullReq), http.StatusOK)
_ = reflector.SetJSONResponse(&listPullReq, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&listPullReq, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&listPullReq, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&listPullReq, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/pullreq", listPullReq)
getPullReq := openapi3.Operation{}
getPullReq.WithTags("pullreq")
getPullReq.WithMapOfAnything(map[string]any{"operationId": "getPullReq"})
getPullReq.WithParameters(queryParameterIncludeChecks, queryParameterIncludeRules)
_ = reflector.SetRequest(&getPullReq, new(getPullReqRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&getPullReq, new(types.PullReq), http.StatusOK)
_ = reflector.SetJSONResponse(&getPullReq, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&getPullReq, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&getPullReq, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&getPullReq, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/pullreq/{pullreq_number}", getPullReq)
getPullReqByBranches := openapi3.Operation{}
getPullReqByBranches.WithTags("pullreq")
getPullReqByBranches.WithMapOfAnything(map[string]any{"operationId": "getPullReqByBranches"})
getPullReqByBranches.WithParameters(queryParameterSourceRepoRefPullRequest,
queryParameterIncludeChecks, queryParameterIncludeRules)
_ = reflector.SetRequest(&getPullReqByBranches, new(getPullReqByBranchesRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&getPullReqByBranches, new(types.PullReq), http.StatusOK)
_ = reflector.SetJSONResponse(&getPullReqByBranches, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&getPullReqByBranches, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&getPullReqByBranches, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&getPullReqByBranches, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&getPullReqByBranches, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodGet,
"/repos/{repo_ref}/pullreq/{target_branch}...{source_branch}", getPullReqByBranches)
putPullReq := openapi3.Operation{}
putPullReq.WithTags("pullreq")
putPullReq.WithMapOfAnything(map[string]any{"operationId": "updatePullReq"})
_ = reflector.SetRequest(&putPullReq, new(updatePullReqRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&putPullReq, new(types.PullReq), http.StatusOK)
_ = reflector.SetJSONResponse(&putPullReq, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&putPullReq, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&putPullReq, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&putPullReq, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/repos/{repo_ref}/pullreq/{pullreq_number}", putPullReq)
statePullReq := openapi3.Operation{}
statePullReq.WithTags("pullreq")
statePullReq.WithMapOfAnything(map[string]any{"operationId": "statePullReq"})
_ = reflector.SetRequest(&statePullReq, new(statePullReqRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&statePullReq, new(types.PullReq), http.StatusOK)
_ = reflector.SetJSONResponse(&statePullReq, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&statePullReq, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&statePullReq, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&statePullReq, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{repo_ref}/pullreq/{pullreq_number}/state", statePullReq)
listPullReqActivities := openapi3.Operation{}
listPullReqActivities.WithTags("pullreq")
listPullReqActivities.WithMapOfAnything(map[string]any{"operationId": "listPullReqActivities"})
listPullReqActivities.WithParameters(
queryParameterKindPullRequestActivity, queryParameterTypePullRequestActivity,
queryParameterAfter, queryParameterBeforePullRequestActivity, QueryParameterLimit)
_ = reflector.SetRequest(&listPullReqActivities, new(listPullReqActivitiesRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&listPullReqActivities, new([]types.PullReqActivity), http.StatusOK)
_ = reflector.SetJSONResponse(&listPullReqActivities, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&listPullReqActivities, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&listPullReqActivities, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&listPullReqActivities, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet,
"/repos/{repo_ref}/pullreq/{pullreq_number}/activities", listPullReqActivities)
commentCreatePullReq := openapi3.Operation{}
commentCreatePullReq.WithTags("pullreq")
commentCreatePullReq.WithMapOfAnything(map[string]any{"operationId": "commentCreatePullReq"})
_ = reflector.SetRequest(&commentCreatePullReq, new(commentCreatePullReqRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&commentCreatePullReq, new(types.PullReqActivity), http.StatusOK)
_ = reflector.SetJSONResponse(&commentCreatePullReq, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&commentCreatePullReq, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&commentCreatePullReq, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&commentCreatePullReq, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost,
"/repos/{repo_ref}/pullreq/{pullreq_number}/comments", commentCreatePullReq)
commentUpdatePullReq := openapi3.Operation{}
commentUpdatePullReq.WithTags("pullreq")
commentUpdatePullReq.WithMapOfAnything(map[string]any{"operationId": "commentUpdatePullReq"})
_ = reflector.SetRequest(&commentUpdatePullReq, new(commentUpdatePullReqRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&commentUpdatePullReq, new(types.PullReqActivity), http.StatusOK)
_ = reflector.SetJSONResponse(&commentUpdatePullReq, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&commentUpdatePullReq, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&commentUpdatePullReq, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&commentUpdatePullReq, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPatch,
"/repos/{repo_ref}/pullreq/{pullreq_number}/comments/{pullreq_comment_id}", commentUpdatePullReq)
commentDeletePullReq := openapi3.Operation{}
commentDeletePullReq.WithTags("pullreq")
commentDeletePullReq.WithMapOfAnything(map[string]any{"operationId": "commentDeletePullReq"})
_ = reflector.SetRequest(&commentDeletePullReq, new(commentDeletePullReqRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&commentDeletePullReq, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&commentDeletePullReq, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&commentDeletePullReq, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&commentDeletePullReq, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&commentDeletePullReq, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodDelete,
"/repos/{repo_ref}/pullreq/{pullreq_number}/comments/{pullreq_comment_id}", commentDeletePullReq)
commentStatusPullReq := openapi3.Operation{}
commentStatusPullReq.WithTags("pullreq")
commentStatusPullReq.WithMapOfAnything(map[string]any{"operationId": "commentStatusPullReq"})
_ = reflector.SetRequest(&commentStatusPullReq, new(commentStatusPullReqRequest), http.MethodPut)
_ = reflector.SetJSONResponse(&commentStatusPullReq, new(types.PullReqActivity), http.StatusOK)
_ = reflector.SetJSONResponse(&commentStatusPullReq, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&commentStatusPullReq, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&commentStatusPullReq, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&commentStatusPullReq, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPut,
"/repos/{repo_ref}/pullreq/{pullreq_number}/comments/{pullreq_comment_id}/status", commentStatusPullReq)
commentApplySuggestions := openapi3.Operation{}
commentApplySuggestions.WithTags("pullreq")
commentApplySuggestions.WithMapOfAnything(map[string]any{"operationId": "commentApplySuggestions"})
_ = reflector.SetRequest(&commentApplySuggestions, new(commentApplySuggestionstRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&commentApplySuggestions, new(pullreq.CommentApplySuggestionsOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&commentApplySuggestions, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&commentApplySuggestions, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&commentApplySuggestions, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&commentApplySuggestions, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&commentApplySuggestions, new(types.RulesViolations), http.StatusUnprocessableEntity)
_ = reflector.Spec.AddOperation(http.MethodPost,
"/repos/{repo_ref}/pullreq/{pullreq_number}/comments/apply-suggestions", commentApplySuggestions)
reviewerAdd := openapi3.Operation{}
reviewerAdd.WithTags("pullreq")
reviewerAdd.WithMapOfAnything(map[string]any{"operationId": "reviewerAddPullReq"})
_ = reflector.SetRequest(&reviewerAdd, new(reviewerAddPullReqRequest), http.MethodPut)
_ = reflector.SetJSONResponse(&reviewerAdd, new(types.PullReqReviewer), http.StatusOK)
_ = reflector.SetJSONResponse(&reviewerAdd, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&reviewerAdd, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&reviewerAdd, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&reviewerAdd, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPut,
"/repos/{repo_ref}/pullreq/{pullreq_number}/reviewers", reviewerAdd)
reviewerList := openapi3.Operation{}
reviewerList.WithTags("pullreq")
reviewerList.WithMapOfAnything(map[string]any{"operationId": "reviewerListPullReq"})
_ = reflector.SetRequest(&reviewerList, new(reviewerListPullReqRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&reviewerList, new([]*types.PullReqReviewer), http.StatusOK)
_ = reflector.SetJSONResponse(&reviewerList, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&reviewerList, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&reviewerList, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&reviewerList, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet,
"/repos/{repo_ref}/pullreq/{pullreq_number}/reviewers", reviewerList)
reviewerDelete := openapi3.Operation{}
reviewerDelete.WithTags("pullreq")
reviewerDelete.WithMapOfAnything(map[string]any{"operationId": "reviewerDeletePullReq"})
_ = reflector.SetRequest(&reviewerDelete, new(reviewerDeletePullReqRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&reviewerDelete, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodDelete,
"/repos/{repo_ref}/pullreq/{pullreq_number}/reviewers/{pullreq_reviewer_id}", reviewerDelete)
reviewSubmit := openapi3.Operation{}
reviewSubmit.WithTags("pullreq")
reviewSubmit.WithMapOfAnything(map[string]any{"operationId": "reviewSubmitPullReq"})
_ = reflector.SetRequest(&reviewSubmit, new(reviewSubmitPullReqRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&reviewSubmit, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&reviewSubmit, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&reviewSubmit, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&reviewSubmit, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&reviewSubmit, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost,
"/repos/{repo_ref}/pullreq/{pullreq_number}/reviews", reviewSubmit)
userGroupReviewerAdd := openapi3.Operation{}
userGroupReviewerAdd.WithTags("pullreq")
userGroupReviewerAdd.WithMapOfAnything(map[string]any{"operationId": "userGroupReviewerAddPullReq"})
_ = reflector.SetRequest(&userGroupReviewerAdd, new(userGroupReviewerAddRequest), http.MethodPut)
_ = reflector.SetJSONResponse(&userGroupReviewerAdd, new(types.UserGroupReviewer), http.StatusOK)
_ = reflector.SetJSONResponse(&userGroupReviewerAdd, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&userGroupReviewerAdd, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&userGroupReviewerAdd, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&userGroupReviewerAdd, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPut,
"/repos/{repo_ref}/pullreq/{pullreq_number}/reviewers/usergroups", userGroupReviewerAdd)
userGroupReviewerDelete := openapi3.Operation{}
userGroupReviewerDelete.WithTags("pullreq")
userGroupReviewerDelete.WithMapOfAnything(map[string]any{"operationId": "userGroupReviewerDeletePullReq"})
_ = reflector.SetRequest(&userGroupReviewerDelete, new(userGroupReviewerDeleteRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&userGroupReviewerDelete, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&userGroupReviewerDelete, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&userGroupReviewerDelete, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&userGroupReviewerDelete, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&userGroupReviewerDelete, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodDelete,
"/repos/{repo_ref}/pullreq/{pullreq_number}/reviewers/usergroups/{user_group_id}", userGroupReviewerDelete)
combinedReviewerList := openapi3.Operation{}
combinedReviewerList.WithTags("pullreq")
combinedReviewerList.WithMapOfAnything(map[string]any{"operationId": "reviewerCombinedListPullReq"})
_ = reflector.SetRequest(&combinedReviewerList, new(pullReqRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&combinedReviewerList, new(pullreq.CombinedListResponse), http.StatusOK)
_ = reflector.SetJSONResponse(&combinedReviewerList, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&combinedReviewerList, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&combinedReviewerList, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&combinedReviewerList, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet,
"/repos/{repo_ref}/pullreq/{pullreq_number}/reviewers/combined", combinedReviewerList)
mergePullReqOp := openapi3.Operation{}
mergePullReqOp.WithTags("pullreq")
mergePullReqOp.WithMapOfAnything(map[string]any{"operationId": "mergePullReqOp"})
_ = reflector.SetRequest(&mergePullReqOp, new(mergePullReq), http.MethodPost)
_ = reflector.SetJSONResponse(&mergePullReqOp, new(types.MergeResponse), http.StatusOK)
_ = reflector.SetJSONResponse(&mergePullReqOp, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&mergePullReqOp, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&mergePullReqOp, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&mergePullReqOp, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&mergePullReqOp, new(usererror.Error), http.StatusMethodNotAllowed)
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | true |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/space.go | app/api/openapi/space.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/repo"
"github.com/harness/gitness/app/api/controller/space"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
type createSpaceRequest struct {
space.CreateInput
}
type spaceRequest struct {
Ref string `path:"space_ref"`
}
type updateSpaceRequest struct {
spaceRequest
space.UpdateInput
}
type updateSpacePublicAccessRequest struct {
spaceRequest
space.UpdatePublicAccessInput
}
type moveSpaceRequest struct {
spaceRequest
space.MoveInput
}
type exportSpaceRequest struct {
spaceRequest
space.ExportInput
}
type restoreSpaceRequest struct {
spaceRequest
space.RestoreInput
}
type importRepositoriesRequest struct {
spaceRequest
space.ImportRepositoriesInput
}
var queryParameterSortRepo = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The data by which the repositories are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.RepoAttrIdentifier.String()),
Enum: []any{
ptr.String(enum.RepoAttrIdentifier.String()),
ptr.String(enum.RepoAttrCreated.String()),
ptr.String(enum.RepoAttrUpdated.String()),
ptr.String(enum.RepoAttrDeleted.String()),
ptr.String(enum.RepoAttrLastGITPush.String()),
},
},
},
},
}
var queryParameterQueryRepo = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring which is used to filter the repositories by their path name."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterSortSpace = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The data by which the spaces are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.SpaceAttrIdentifier.String()),
Enum: []any{
ptr.String(enum.SpaceAttrIdentifier.String()),
ptr.String(enum.SpaceAttrCreated.String()),
ptr.String(enum.SpaceAttrUpdated.String()),
},
},
},
},
}
var queryParameterQuerySpace = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring which is used to filter the spaces by their path name."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterMembershipUsers = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring by which the space members are filtered."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterSortMembershipUsers = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The field by which the space members are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.MembershipUserSortName),
Enum: enum.MembershipUserSort("").Enum(),
},
},
},
}
var queryParameterQueryExecution = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring which is used to filter the execution by their pipeline names."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterSortExecution = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The data by which the executions are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.ExecutionSortStarted),
Enum: enum.ExecutionSort("").Enum(),
},
},
},
}
var queryParameterPipelineIdentifier = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamPipelineIdentifier,
In: openapi3.ParameterInQuery,
Description: ptr.String("The pipeline identifier whose executions are to be returned"),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterOnlyFavorites = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamOnlyFavorites,
In: openapi3.ParameterInQuery,
Description: ptr.String("The result should contain only the favorite entries for the logged in user."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var QueryParameterQueryUsergroup = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring which is used to filter usergroups by their identifier."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
//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]any{"operationId": "createSpace"})
_ = reflector.SetRequest(&opCreate, new(createSpaceRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opCreate, new(space.SpaceOutput), 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)
opImport := openapi3.Operation{}
opImport.WithTags("space")
opImport.WithMapOfAnything(map[string]any{"operationId": "importSpace"})
_ = reflector.SetRequest(&opImport, new(space.ImportInput), http.MethodPost)
_ = reflector.SetJSONResponse(&opImport, new(space.SpaceOutput), http.StatusCreated)
_ = reflector.SetJSONResponse(&opImport, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opImport, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opImport, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opImport, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/import", opImport)
opImportRepositories := openapi3.Operation{}
opImportRepositories.WithTags("space")
opImportRepositories.WithMapOfAnything(map[string]any{"operationId": "importSpaceRepositories"})
_ = reflector.SetRequest(&opImportRepositories, new(importRepositoriesRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opImportRepositories, new(space.ImportRepositoriesOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&opImportRepositories, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opImportRepositories, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opImportRepositories, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opImportRepositories, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{space_ref}/import", opImportRepositories)
opExport := openapi3.Operation{}
opExport.WithTags("space")
opExport.WithMapOfAnything(map[string]any{"operationId": "exportSpace"})
_ = reflector.SetRequest(&opExport, new(exportSpaceRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opExport, nil, http.StatusAccepted)
_ = reflector.SetJSONResponse(&opExport, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opExport, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opExport, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opExport, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{space_ref}/export", opExport)
opExportProgress := openapi3.Operation{}
opExportProgress.WithTags("space")
opExportProgress.WithMapOfAnything(map[string]any{"operationId": "exportProgressSpace"})
_ = reflector.SetRequest(&opExportProgress, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opExportProgress, new(space.ExportProgressOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&opExportProgress, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opExportProgress, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opExportProgress, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opExportProgress, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/export-progress", opExportProgress)
opGet := openapi3.Operation{}
opGet.WithTags("space")
opGet.WithMapOfAnything(map[string]any{"operationId": "getSpace"})
_ = reflector.SetRequest(&opGet, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opGet, new(space.SpaceOutput), 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/{space_ref}", opGet)
opUpdate := openapi3.Operation{}
opUpdate.WithTags("space")
opUpdate.WithMapOfAnything(map[string]any{"operationId": "updateSpace"})
_ = reflector.SetRequest(&opUpdate, new(updateSpaceRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&opUpdate, new(space.SpaceOutput), 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/{space_ref}", opUpdate)
opUpdatePublicAccess := openapi3.Operation{}
opUpdatePublicAccess.WithTags("space")
opUpdatePublicAccess.WithMapOfAnything(
map[string]any{"operationId": "updateSpacePublicAccess"})
_ = reflector.SetRequest(
&opUpdatePublicAccess, new(updateSpacePublicAccessRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(space.SpaceOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(
http.MethodPost, "/spaces/{space_ref}/public-access", opUpdatePublicAccess)
opDelete := openapi3.Operation{}
opDelete.WithTags("space")
opDelete.WithMapOfAnything(map[string]any{"operationId": "deleteSpace"})
_ = reflector.SetRequest(&opDelete, new(spaceRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&opDelete, new(space.SoftDeleteResponse), http.StatusOK)
_ = 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/{space_ref}", opDelete)
opPurge := openapi3.Operation{}
opPurge.WithTags("space")
opPurge.WithMapOfAnything(map[string]any{"operationId": "purgeSpace"})
opPurge.WithParameters(queryParameterDeletedAt)
_ = reflector.SetRequest(&opPurge, new(spaceRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opPurge, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&opPurge, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opPurge, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opPurge, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opPurge, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{space_ref}/purge", opPurge)
opRestore := openapi3.Operation{}
opRestore.WithTags("space")
opRestore.WithMapOfAnything(map[string]any{"operationId": "restoreSpace"})
opRestore.WithParameters(queryParameterDeletedAt)
_ = reflector.SetRequest(&opRestore, new(restoreSpaceRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opRestore, new(space.SpaceOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{space_ref}/restore", opRestore)
opMove := openapi3.Operation{}
opMove.WithTags("space")
opMove.WithMapOfAnything(map[string]any{"operationId": "moveSpace"})
_ = reflector.SetRequest(&opMove, new(moveSpaceRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opMove, new(space.SpaceOutput), 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/{space_ref}/move", opMove)
opSpaces := openapi3.Operation{}
opSpaces.WithTags("space")
opSpaces.WithMapOfAnything(map[string]any{"operationId": "listSpaces"})
opSpaces.WithParameters(QueryParameterPage, QueryParameterLimit)
opSpaces.WithParameters(queryParameterQuerySpace, queryParameterSortSpace, queryParameterOrder,
QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&opSpaces, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opSpaces, []space.SpaceOutput{}, 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/{space_ref}/spaces", opSpaces)
opRepos := openapi3.Operation{}
opRepos.WithTags("space")
opRepos.WithMapOfAnything(map[string]any{"operationId": "listRepos"})
opRepos.WithParameters(queryParameterQueryRepo, queryParameterSortRepo, queryParameterOrder,
QueryParameterPage, QueryParameterLimit, QueryParameterRecursive, queryParameterOnlyFavorites)
_ = reflector.SetRequest(&opRepos, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opRepos, []repo.RepositoryOutput{}, 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/{space_ref}/repos", opRepos)
opPipelines := openapi3.Operation{}
opPipelines.WithTags("space")
opPipelines.WithMapOfAnything(map[string]any{"operationId": "listSpacePipelines"})
opPipelines.WithParameters(queryParameterQueryPipeline, QueryParameterPage,
QueryParameterLimit, queryParameterLastExecutions)
_ = reflector.SetRequest(&opPipelines, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opPipelines, []types.Pipeline{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opPipelines, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opPipelines, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opPipelines, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&opPipelines, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/pipelines", opPipelines)
opExecutions := openapi3.Operation{}
opExecutions.WithTags("space")
opExecutions.WithMapOfAnything(map[string]any{"operationId": "listSpaceExecutions"})
opExecutions.WithParameters(queryParameterQueryExecution, QueryParameterPage, QueryParameterLimit,
queryParameterSortExecution, queryParameterOrder, queryParameterPipelineIdentifier)
_ = reflector.SetRequest(&opExecutions, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opExecutions, []types.Execution{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opExecutions, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opExecutions, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opExecutions, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&opExecutions, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/executions", opExecutions)
opTemplates := openapi3.Operation{}
opTemplates.WithTags("space")
opTemplates.WithMapOfAnything(map[string]any{"operationId": "listTemplates"})
opTemplates.WithParameters(queryParameterQueryRepo, QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&opTemplates, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opTemplates, []types.Template{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opTemplates, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opTemplates, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opTemplates, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opTemplates, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/templates", opTemplates)
opConnectors := openapi3.Operation{}
opConnectors.WithTags("space")
opConnectors.WithMapOfAnything(map[string]any{"operationId": "listConnectors"})
opConnectors.WithParameters(queryParameterQueryRepo, QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&opConnectors, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opConnectors, []types.Connector{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opConnectors, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opConnectors, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opConnectors, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opConnectors, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/connectors", opConnectors)
opSecrets := openapi3.Operation{}
opSecrets.WithTags("space")
opSecrets.WithMapOfAnything(map[string]any{"operationId": "listSecrets"})
opSecrets.WithParameters(queryParameterQueryRepo, QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&opSecrets, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opSecrets, []types.Secret{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opSecrets, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opSecrets, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opSecrets, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opSecrets, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/secrets", opSecrets)
opServiceAccounts := openapi3.Operation{}
opServiceAccounts.WithTags("space")
opServiceAccounts.WithMapOfAnything(map[string]any{"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/{space_ref}/service-accounts", opServiceAccounts)
opMembershipAdd := openapi3.Operation{}
opMembershipAdd.WithTags("space")
opMembershipAdd.WithMapOfAnything(map[string]any{"operationId": "membershipAdd"})
_ = reflector.SetRequest(&opMembershipAdd, struct {
spaceRequest
space.MembershipAddInput
}{}, http.MethodPost)
_ = reflector.SetJSONResponse(&opMembershipAdd, &types.MembershipUser{}, http.StatusCreated)
_ = reflector.SetJSONResponse(&opMembershipAdd, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opMembershipAdd, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opMembershipAdd, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opMembershipAdd, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{space_ref}/members", opMembershipAdd)
opMembershipDelete := openapi3.Operation{}
opMembershipDelete.WithTags("space")
opMembershipDelete.WithMapOfAnything(map[string]any{"operationId": "membershipDelete"})
_ = reflector.SetRequest(&opMembershipDelete, struct {
spaceRequest
UserUID string `path:"user_uid"`
}{}, http.MethodDelete)
_ = reflector.SetJSONResponse(&opMembershipDelete, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&opMembershipDelete, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opMembershipDelete, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opMembershipDelete, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opMembershipDelete, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodDelete, "/spaces/{space_ref}/members/{user_uid}", opMembershipDelete)
opMembershipUpdate := openapi3.Operation{}
opMembershipUpdate.WithTags("space")
opMembershipUpdate.WithMapOfAnything(map[string]any{"operationId": "membershipUpdate"})
_ = reflector.SetRequest(&opMembershipUpdate, &struct {
spaceRequest
UserUID string `path:"user_uid"`
space.MembershipUpdateInput
}{}, http.MethodPatch)
_ = reflector.SetJSONResponse(&opMembershipUpdate, &types.MembershipUser{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opMembershipUpdate, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opMembershipUpdate, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opMembershipUpdate, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opMembershipUpdate, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/spaces/{space_ref}/members/{user_uid}", opMembershipUpdate)
opMembershipList := openapi3.Operation{}
opMembershipList.WithTags("space")
opMembershipList.WithMapOfAnything(map[string]any{"operationId": "membershipList"})
opMembershipList.WithParameters(
queryParameterMembershipUsers,
queryParameterOrder, queryParameterSortMembershipUsers,
QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&opMembershipList, &struct {
spaceRequest
}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&opMembershipList, []types.MembershipUser{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opMembershipList, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opMembershipList, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opMembershipList, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opMembershipList, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/members", opMembershipList)
opDefineLabel := openapi3.Operation{}
opDefineLabel.WithTags("space")
opDefineLabel.WithMapOfAnything(
map[string]any{"operationId": "defineSpaceLabel"})
_ = reflector.SetRequest(&opDefineLabel, &struct {
spaceRequest
LabelRequest
}{}, http.MethodPost)
_ = reflector.SetJSONResponse(&opDefineLabel, new(types.Label), http.StatusCreated)
_ = reflector.SetJSONResponse(&opDefineLabel, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opDefineLabel, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opDefineLabel, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opDefineLabel, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opDefineLabel, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/spaces/{space_ref}/labels", opDefineLabel)
opSaveLabel := openapi3.Operation{}
opSaveLabel.WithTags("space")
opSaveLabel.WithMapOfAnything(
map[string]any{"operationId": "saveSpaceLabel"})
_ = reflector.SetRequest(&opSaveLabel, &struct {
spaceRequest
types.SaveInput
}{}, http.MethodPut)
_ = reflector.SetJSONResponse(&opSaveLabel, new(types.LabelWithValues), http.StatusOK)
_ = reflector.SetJSONResponse(&opSaveLabel, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opSaveLabel, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opSaveLabel, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opSaveLabel, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opSaveLabel, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPut, "/spaces/{space_ref}/labels", opSaveLabel)
opListLabels := openapi3.Operation{}
opListLabels.WithTags("space")
opListLabels.WithMapOfAnything(
map[string]any{"operationId": "listSpaceLabels"})
opListLabels.WithParameters(
QueryParameterPage, QueryParameterLimit, QueryParameterInherited, QueryParameterQueryLabel)
_ = reflector.SetRequest(&opListLabels, new(spaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opListLabels, new([]*types.Label), http.StatusOK)
_ = reflector.SetJSONResponse(&opListLabels, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opListLabels, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opListLabels, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opListLabels, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opListLabels, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/labels", opListLabels)
opFindLabel := openapi3.Operation{}
opFindLabel.WithTags("space")
opFindLabel.WithMapOfAnything(map[string]any{"operationId": "findSpaceLabel"})
opFindLabel.WithParameters(queryParameterIncludeValues)
_ = reflector.SetRequest(&opFindLabel, &struct {
spaceRequest
Key string `path:"key"`
}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&opFindLabel, new(types.LabelWithValues), http.StatusCreated)
_ = reflector.SetJSONResponse(&opFindLabel, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opFindLabel, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opFindLabel, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opFindLabel, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opFindLabel, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/spaces/{space_ref}/labels/{key}", opFindLabel)
opDeleteLabel := openapi3.Operation{}
opDeleteLabel.WithTags("space")
opDeleteLabel.WithMapOfAnything(
map[string]any{"operationId": "deleteSpaceLabel"})
_ = reflector.SetRequest(&opDeleteLabel, &struct {
spaceRequest
Key string `path:"key"`
}{}, http.MethodDelete)
_ = reflector.SetJSONResponse(&opDeleteLabel, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&opDeleteLabel, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opDeleteLabel, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opDeleteLabel, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opDeleteLabel, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opDeleteLabel, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(
http.MethodDelete, "/spaces/{space_ref}/labels/{key}", opDeleteLabel)
opUpdateLabel := openapi3.Operation{}
opUpdateLabel.WithTags("space")
opUpdateLabel.WithMapOfAnything(
map[string]any{"operationId": "updateSpaceLabel"})
_ = reflector.SetRequest(&opUpdateLabel, &struct {
spaceRequest
LabelRequest
Key string `path:"key"`
}{}, http.MethodPatch)
_ = reflector.SetJSONResponse(&opUpdateLabel, new(types.Label), http.StatusOK)
_ = reflector.SetJSONResponse(&opUpdateLabel, new(usererror.Error), http.StatusBadRequest)
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | true |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/repo.go | app/api/openapi/repo.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/repo"
"github.com/harness/gitness/app/api/controller/reposettings"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/git"
gittypes "github.com/harness/gitness/git/api"
"github.com/harness/gitness/job"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
type createRepositoryRequest struct {
repo.CreateInput
}
type gitignoreRequest struct {
}
type licenseRequest struct {
}
type repoRequest struct {
Ref string `path:"repo_ref"`
}
type updateRepoRequest struct {
repoRequest
repo.UpdateInput
}
type updateDefaultBranchRequest struct {
repoRequest
repo.UpdateDefaultBranchInput
}
type moveRepoRequest struct {
repoRequest
repo.MoveInput
}
type getContentRequest struct {
repoRequest
Path string `path:"path"`
}
type pathsDetailsRequest struct {
repoRequest
repo.PathsDetailsInput
}
type getBlameRequest struct {
repoRequest
Path string `path:"path"`
}
type commitFilesRequest struct {
repoRequest
repo.CommitFilesOptions
}
// contentType is a plugin for repo.ContentType to allow using oneof.
type contentType string
func (contentType) Enum() []any {
return []any{repo.ContentTypeFile, repo.ContentTypeDir, repo.ContentTypeSymlink, repo.ContentTypeSubmodule}
}
// contentInfo is used to overshadow the contentype of repo.ContentInfo.
type contentInfo struct {
repo.ContentInfo
Type contentType `json:"type"`
}
// dirContent is used to overshadow the Entries type of repo.DirContent.
type dirContent struct {
repo.DirContent
Entries []contentInfo `json:"entries"`
}
// content is a plugin for repo.content to allow using oneof.
type content struct{}
func (content) JSONSchemaOneOf() []any {
return []any{repo.FileContent{}, dirContent{}, repo.SymlinkContent{}, repo.SubmoduleContent{}}
}
// getContentOutput is used to overshadow the content and contenttype of repo.GetContentOutput.
type getContentOutput struct {
repo.GetContentOutput
Type contentType `json:"type"`
Content content `json:"content"`
}
type listCommitsRequest struct {
repoRequest
}
type GetCommitRequest struct {
repoRequest
CommitSHA string `path:"commit_sha"`
}
type GetCommitDiffRequest struct {
GetCommitRequest
IgnoreWhitespace bool `query:"ignore_whitespace" required:"false" default:"false"`
}
type calculateCommitDivergenceRequest struct {
repoRequest
repo.GetCommitDivergencesInput
}
type listBranchesRequest struct {
repoRequest
}
type createBranchRequest struct {
repoRequest
repo.CreateBranchInput
}
type getBranchRequest struct {
repoRequest
BranchName string `path:"branch_name"`
}
type deleteBranchRequest struct {
repoRequest
BranchName string `path:"branch_name"`
}
type createTagRequest struct {
repoRequest
repo.CreateCommitTagInput
}
type listTagsRequest struct {
repoRequest
}
type deleteTagRequest struct {
repoRequest
TagName string `path:"tag_name"`
}
type getRawDiffRequest struct {
repoRequest
Range string `path:"range" example:"main..dev"`
Path []string `query:"path" description:"provide path for diff operation"`
IgnoreWhitespace bool `query:"ignore_whitespace" required:"false" default:"false"`
}
type postRawDiffRequest struct {
repoRequest
gittypes.FileDiffRequests
Range string `path:"range" example:"main..dev"`
IgnoreWhitespace bool `query:"ignore_whitespace" required:"false" default:"false"`
}
type codeOwnersValidate struct {
repoRequest
}
type restoreRequest struct {
repoRequest
repo.RestoreInput
}
type updateRepoPublicAccessRequest struct {
repoRequest
repo.UpdatePublicAccessInput
}
type securitySettingsRequest struct {
repoRequest
reposettings.SecuritySettings
}
type generalSettingsRequest struct {
repoRequest
reposettings.GeneralSettings
}
type archiveRequest struct {
repoRequest
GitRef string `path:"git_ref" required:"true"`
Format string `path:"format" required:"true"`
}
type LabelRequest struct {
Key string `json:"key"`
Description string `json:"description"`
Type enum.LabelType `json:"type"`
Color enum.LabelColor `json:"color"`
}
type LabelValueRequest struct {
Value string `json:"value"`
Color enum.LabelColor `json:"color"`
}
var queryParameterGitRef = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamGitRef,
In: openapi3.ParameterInQuery,
Description: ptr.String("The git reference (branch / tag / commitID) that will be used to retrieve the data. " +
"If no value is provided the default branch of the repository is used."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr("{Repository Default Branch}"),
},
},
},
}
var queryParameterPath = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamPath,
In: openapi3.ParameterInQuery,
Description: ptr.String("Path for which commit information should be retrieved"),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(""),
},
},
},
}
var queryParameterSince = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSince,
In: openapi3.ParameterInQuery,
Description: ptr.String("Epoch timestamp since when commit information should be retrieved."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
Example: ptrptr(1728348213),
},
},
},
}
var queryParameterUntil = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamUntil,
In: openapi3.ParameterInQuery,
Description: ptr.String("Epoch timestamp until when commit information should be retrieved."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
Example: ptrptr(1746668446),
},
},
},
}
var queryParameterFlattenDirectories = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamFlattenDirectories,
In: openapi3.ParameterInQuery,
Description: ptr.String("Flatten directories that contain just one subdirectory."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParameterIncludeCommit = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamIncludeCommit,
In: openapi3.ParameterInQuery,
Description: ptr.String("Indicates whether optional commit information should be included in the response."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParamIncludeGitStats = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamIncludeGitStats,
In: openapi3.ParameterInQuery,
Description: ptr.String(
"If true, the git diff stats would be included in the response."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParameterIncludeChecks = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamIncludeChecks,
In: openapi3.ParameterInQuery,
Description: ptr.String(
"If true, the summary of check for the branch commit SHA would be included in the response."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParameterIncludeRules = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamIncludeRules,
In: openapi3.ParameterInQuery,
Description: ptr.String(
"If true, a list of rules that apply to this branch would be included in the response."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParameterIncludePullReqs = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamIncludePullReqs,
In: openapi3.ParameterInQuery,
Description: ptr.String(
"If true, a list of pull requests from the branch would be included in the response."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParameterMaxDivergence = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamMaxDivergence,
In: openapi3.ParameterInQuery,
Description: ptr.String(
"If greater than zero, branch divergence from the default branch will be included in the response. " +
"The divergence would be calculated up the this many commits."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
Default: ptrptr(0),
},
},
},
}
var queryParameterIncludeDirectories = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamIncludeDirectories,
In: openapi3.ParameterInQuery,
Description: ptr.String("Indicates whether directories should be included in the response."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var QueryParamIncludeStats = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamIncludeStats,
In: openapi3.ParameterInQuery,
Description: ptr.String("Indicates whether optional stats should be included in the response."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParameterLineFrom = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamLineFrom,
In: openapi3.ParameterInQuery,
Description: ptr.String("Line number from which the file data is considered"),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
Default: ptrptr(0),
},
},
},
}
var queryParameterLineTo = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamLineTo,
In: openapi3.ParameterInQuery,
Description: ptr.String("Line number to which the file data is considered"),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
Default: ptrptr(0),
},
},
},
}
// TODO: this is technically coming from harness package, but we can't reference that.
var queryParameterSpacePath = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: "space_path",
In: openapi3.ParameterInQuery,
Description: ptr.String("path of parent space (Not needed in standalone)."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(false),
},
},
},
}
var queryParameterSortBranch = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The data by which the branches are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.BranchSortOptionName.String()),
Enum: []any{
ptr.String(enum.BranchSortOptionName.String()),
ptr.String(enum.BranchSortOptionDate.String()),
},
},
},
},
}
var queryParameterQueryBranches = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring by which the branches are filtered."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterSortTags = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The data by which the tags are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.TagSortOptionName.String()),
Enum: []any{
ptr.String(enum.TagSortOptionName.String()),
ptr.String(enum.TagSortOptionDate.String()),
},
},
},
},
}
var queryParameterQueryTags = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring by which the tags are filtered."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterAfterCommits = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamAfter,
In: openapi3.ParameterInQuery,
Description: ptr.String("The result should only contain commits that occurred after the provided reference."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterCommitter = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamCommitter,
In: openapi3.ParameterInQuery,
Description: ptr.String("Committer pattern for which commit information should be retrieved."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterCommitterID = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamCommitterID,
In: openapi3.ParameterInQuery,
Description: ptr.String("Committer principal IDs for which commit information should be retrieved."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
},
Style: ptr.String(string(openapi3.EncodingStyleForm)),
Explode: ptr.Bool(true),
},
}
var queryParameterAuthor = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamAuthor,
In: openapi3.ParameterInQuery,
Description: ptr.String("Author pattern for which commit information should be retrieved."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterAuthoredByID = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamAuthorID,
In: openapi3.ParameterInQuery,
Description: ptr.String("Author principal IDs for which commit information should be retrieved."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
},
Style: ptr.String(string(openapi3.EncodingStyleForm)),
Explode: ptr.Bool(true),
},
}
var queryParameterBypassRules = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamBypassRules,
In: openapi3.ParameterInQuery,
Description: ptr.String("Bypass rule violations if possible."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParameterDryRunRules = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamDryRunRules,
In: openapi3.ParameterInQuery,
Description: ptr.String("Dry run rules for operations"),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var queryParameterDeletedAt = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamDeletedAt,
In: openapi3.ParameterInQuery,
Description: ptr.String("The exact time the resource was delete at in epoch format."),
Required: ptr.Bool(true),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
}
var queryParamArchivePaths = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamArchivePaths,
In: openapi3.ParameterInQuery,
Description: ptr.String("Without an optional path parameter, all files and subdirectories of the " +
"current working directory are included in the archive. If one or more paths are specified," +
" only these are included."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
},
},
}
var queryParamArchivePrefix = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamArchivePrefix,
In: openapi3.ParameterInQuery,
Description: ptr.String("Prepend <prefix>/ to paths in the archive."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParamArchiveAttributes = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamArchiveAttributes,
In: openapi3.ParameterInQuery,
Description: ptr.String("Look for attributes in .gitattributes files in the working tree as well"),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParamArchiveTime = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamArchiveTime,
In: openapi3.ParameterInQuery,
Description: ptr.String("Set modification time of archive entries. Without this option the committer " +
"time is used if <tree-ish> is a commit or tag, and the current time if it is a tree."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParamArchiveCompression = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamArchiveCompression,
In: openapi3.ParameterInQuery,
Description: ptr.String("Specify compression level. Larger values allow the command to spend more" +
" time to compress to smaller size."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
}
var QueryParameterInherited = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamInherited,
In: openapi3.ParameterInQuery,
Description: ptr.String("The result should inherit entities from parent spaces."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
var QueryParameterQueryLabel = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring which is used to filter the labels by their key."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterIncludeValues = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamIncludeValues,
In: openapi3.ParameterInQuery,
Description: ptr.String("The result should include label values."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
Default: ptrptr(false),
},
},
},
}
//nolint:funlen
func repoOperations(reflector *openapi3.Reflector) {
createRepository := openapi3.Operation{}
createRepository.WithTags("repository")
createRepository.WithMapOfAnything(map[string]any{"operationId": "createRepository"})
createRepository.WithParameters(queryParameterSpacePath)
_ = reflector.SetRequest(&createRepository, new(createRepositoryRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&createRepository, new(repo.RepositoryOutput), 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)
importRepository := openapi3.Operation{}
importRepository.WithTags("repository")
importRepository.WithMapOfAnything(map[string]any{"operationId": "importRepository"})
importRepository.WithParameters(queryParameterSpacePath)
_ = reflector.SetRequest(&importRepository, &struct{ repo.ImportInput }{}, http.MethodPost)
_ = reflector.SetJSONResponse(&importRepository, new(repo.RepositoryOutput), http.StatusCreated)
_ = reflector.SetJSONResponse(&importRepository, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&importRepository, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&importRepository, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&importRepository, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/import", importRepository)
opFind := openapi3.Operation{}
opFind.WithTags("repository")
opFind.WithMapOfAnything(map[string]any{"operationId": "findRepository"})
_ = reflector.SetRequest(&opFind, new(repoRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opFind, new(repo.RepositoryOutput), 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/{repo_ref}", opFind)
opUpdate := openapi3.Operation{}
opUpdate.WithTags("repository")
opUpdate.WithMapOfAnything(map[string]any{"operationId": "updateRepository"})
_ = reflector.SetRequest(&opUpdate, new(updateRepoRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&opUpdate, new(repo.RepositoryOutput), 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/{repo_ref}", opUpdate)
opUpdateDefaultBranch := openapi3.Operation{}
opUpdateDefaultBranch.WithTags("repository")
opUpdateDefaultBranch.WithMapOfAnything(map[string]any{"operationId": "updateDefaultBranch"})
_ = reflector.SetRequest(&opUpdateDefaultBranch, new(updateDefaultBranchRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opUpdateDefaultBranch, new(repo.RepositoryOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&opUpdateDefaultBranch, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opUpdateDefaultBranch, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opUpdateDefaultBranch, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opUpdateDefaultBranch, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{repo_ref}/default-branch", opUpdateDefaultBranch)
opDelete := openapi3.Operation{}
opDelete.WithTags("repository")
opDelete.WithMapOfAnything(map[string]any{"operationId": "deleteRepository"})
_ = reflector.SetRequest(&opDelete, new(repoRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&opDelete, new(repo.SoftDeleteResponse), http.StatusOK)
_ = 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/{repo_ref}", opDelete)
opPurge := openapi3.Operation{}
opPurge.WithTags("repository")
opPurge.WithMapOfAnything(map[string]any{"operationId": "purgeRepository"})
opPurge.WithParameters(queryParameterDeletedAt)
_ = reflector.SetRequest(&opPurge, new(repoRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opPurge, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&opPurge, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opPurge, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opPurge, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opPurge, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{repo_ref}/purge", opPurge)
opRestore := openapi3.Operation{}
opRestore.WithTags("repository")
opRestore.WithMapOfAnything(map[string]any{"operationId": "restoreRepository"})
opRestore.WithParameters(queryParameterDeletedAt)
_ = reflector.SetRequest(&opRestore, new(restoreRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opRestore, new(repo.RepositoryOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opRestore, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{repo_ref}/restore", opRestore)
opMove := openapi3.Operation{}
opMove.WithTags("repository")
opMove.WithMapOfAnything(map[string]any{"operationId": "moveRepository"})
_ = reflector.SetRequest(&opMove, new(moveRepoRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opMove, new(repo.RepositoryOutput), 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/{repo_ref}/move", opMove)
opUpdatePublicAccess := openapi3.Operation{}
opUpdatePublicAccess.WithTags("repository")
opUpdatePublicAccess.WithMapOfAnything(
map[string]any{"operationId": "updatePublicAccess"})
_ = reflector.SetRequest(
&opUpdatePublicAccess, new(updateRepoPublicAccessRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(repo.RepositoryOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opUpdatePublicAccess, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(
http.MethodPost, "/repos/{repo_ref}/public-access", opUpdatePublicAccess)
opServiceAccounts := openapi3.Operation{}
opServiceAccounts.WithTags("repository")
opServiceAccounts.WithMapOfAnything(map[string]any{"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/{repo_ref}/service-accounts", opServiceAccounts)
opGetContent := openapi3.Operation{}
opGetContent.WithTags("repository")
opGetContent.WithMapOfAnything(map[string]any{"operationId": "getContent"})
opGetContent.WithParameters(queryParameterGitRef, queryParameterIncludeCommit, queryParameterFlattenDirectories)
_ = reflector.SetRequest(&opGetContent, new(getContentRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opGetContent, new(getContentOutput), http.StatusOK)
_ = reflector.SetJSONResponse(&opGetContent, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opGetContent, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opGetContent, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opGetContent, new(usererror.Error), http.StatusNotFound)
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | true |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/secret.go | app/api/openapi/secret.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/secret"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types"
"github.com/swaggest/openapi-go/openapi3"
)
type createSecretRequest struct {
secret.CreateInput
}
type secretRequest struct {
Ref string `path:"secret_ref"`
}
type getSecretRequest struct {
secretRequest
}
type updateSecretRequest struct {
secretRequest
secret.UpdateInput
}
func secretOperations(reflector *openapi3.Reflector) {
opCreate := openapi3.Operation{}
opCreate.WithTags("secret")
opCreate.WithMapOfAnything(map[string]any{"operationId": "createSecret"})
_ = reflector.SetRequest(&opCreate, new(createSecretRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opCreate, new(types.Secret), 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, "/secrets", opCreate)
opFind := openapi3.Operation{}
opFind.WithTags("secret")
opFind.WithMapOfAnything(map[string]any{"operationId": "findSecret"})
_ = reflector.SetRequest(&opFind, new(getSecretRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opFind, new(types.Secret), 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, "/secrets/{secret_ref}", opFind)
opDelete := openapi3.Operation{}
opDelete.WithTags("secret")
opDelete.WithMapOfAnything(map[string]any{"operationId": "deleteSecret"})
_ = reflector.SetRequest(&opDelete, new(getSecretRequest), 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, "/secrets/{secret_ref}", opDelete)
opUpdate := openapi3.Operation{}
opUpdate.WithTags("secret")
opUpdate.WithMapOfAnything(map[string]any{"operationId": "updateSecret"})
_ = reflector.SetRequest(&opUpdate, new(updateSecretRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&opUpdate, new(types.Secret), 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, "/secrets/{secret_ref}", opUpdate)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/resource.go | app/api/openapi/resource.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/usererror"
"github.com/swaggest/openapi-go/openapi3"
)
func resourceOperations(reflector *openapi3.Reflector) {
opListGitignore := openapi3.Operation{}
opListGitignore.WithTags("resource")
opListGitignore.WithMapOfAnything(map[string]any{"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, "/resources/gitignore", opListGitignore)
opListLicenses := openapi3.Operation{}
opListLicenses.WithTags("resource")
opListLicenses.WithMapOfAnything(map[string]any{"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, "/resources/license", opListLicenses)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/upload.go | app/api/openapi/upload.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/upload"
"github.com/harness/gitness/app/api/usererror"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
func uploadOperations(reflector *openapi3.Reflector) {
opUpload := openapi3.Operation{}
opUpload.WithTags("upload")
opUpload.WithMapOfAnything(map[string]any{"operationId": "repoArtifactUpload"})
opUpload.WithRequestBody(openapi3.RequestBodyOrRef{
RequestBody: &openapi3.RequestBody{
Description: ptr.String("Binary file to upload"),
Content: map[string]openapi3.MediaType{
"application/octet-stream": {Schema: &openapi3.SchemaOrRef{}},
},
Required: ptr.Bool(true),
},
})
_ = reflector.SetRequest(&opUpload, repoRequest{}, http.MethodPost)
_ = reflector.SetJSONResponse(&opUpload, new(upload.Result), http.StatusCreated)
_ = reflector.SetJSONResponse(&opUpload, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opUpload, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&opUpload, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opUpload, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opUpload, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/repos/{repo_ref}/uploads", opUpload)
downloadOp := openapi3.Operation{}
downloadOp.WithTags("upload")
downloadOp.WithMapOfAnything(map[string]any{"operationId": "repoArtifactDownload"})
_ = reflector.SetRequest(&downloadOp, struct {
repoRequest
FilePathRef string `path:"file_ref"`
}{}, http.MethodGet)
_ = reflector.SetupResponse(openapi3.OperationContext{
Operation: &downloadOp,
HTTPStatus: http.StatusOK,
})
_ = reflector.SetJSONResponse(&downloadOp, nil, http.StatusTemporaryRedirect)
_ = reflector.SetJSONResponse(&downloadOp, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&downloadOp, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&downloadOp, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&downloadOp, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&downloadOp, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/uploads/{file_ref}", downloadOp)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/connector.go | app/api/openapi/connector.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/connector"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types"
"github.com/swaggest/openapi-go/openapi3"
)
type createConnectorRequest struct {
connector.CreateInput
}
type connectorRequest struct {
Ref string `path:"connector_ref"`
}
type getConnectorRequest struct {
connectorRequest
}
type updateConnectorRequest struct {
connectorRequest
connector.UpdateInput
}
func connectorOperations(reflector *openapi3.Reflector) {
opCreate := openapi3.Operation{}
opCreate.WithTags("connector")
opCreate.WithMapOfAnything(map[string]any{"operationId": "createConnector"})
_ = reflector.SetRequest(&opCreate, new(createConnectorRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opCreate, new(types.Connector), 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, "/connectors", opCreate)
opFind := openapi3.Operation{}
opFind.WithTags("connector")
opFind.WithMapOfAnything(map[string]any{"operationId": "findConnector"})
_ = reflector.SetRequest(&opFind, new(getConnectorRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opFind, new(types.Connector), 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, "/connectors/{connector_ref}", opFind)
opDelete := openapi3.Operation{}
opDelete.WithTags("connector")
opDelete.WithMapOfAnything(map[string]any{"operationId": "deleteConnector"})
_ = reflector.SetRequest(&opDelete, new(getConnectorRequest), 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, "/connectors/{connector_ref}", opDelete)
opUpdate := openapi3.Operation{}
opUpdate.WithTags("connector")
opUpdate.WithMapOfAnything(map[string]any{"operationId": "updateConnector"})
_ = reflector.SetRequest(&opUpdate, new(updateConnectorRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&opUpdate, new(types.Connector), 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, "/connectors/{connector_ref}", opUpdate)
opTest := openapi3.Operation{}
opTest.WithTags("connector")
opTest.WithMapOfAnything(map[string]any{"operationId": "testConnector"})
_ = reflector.SetRequest(&opTest, nil, http.MethodPost)
_ = reflector.SetJSONResponse(&opTest, new(types.ConnectorTestResponse), http.StatusOK)
_ = reflector.SetJSONResponse(&opTest, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opTest, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opTest, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opTest, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opTest, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/connectors/{connector_ref}/test", opTest)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/gitspace.go | app/api/openapi/gitspace.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/gitspace"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/app/gitspace/scm"
"github.com/harness/gitness/livelog"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
type createGitspaceRequest struct {
gitspace.CreateInput
}
type lookupRepoGitspaceRequest struct {
gitspace.LookupRepoInput
}
type actionGitspaceRequest struct {
gitspaceRequest
gitspace.ActionInput
}
type updateGitspaceRequest struct {
}
type gitspaceRequest struct {
Ref string `path:"gitspace_identifier"`
}
type getGitspaceRequest struct {
gitspaceRequest
}
type gitspacesListRequest struct {
Sort enum.GitspaceSort `query:"sort"`
Order string `query:"order" enum:"asc,desc"`
GitspaceOwner enum.GitspaceOwner `query:"gitspace_owner"`
GitspaceStates []enum.GitspaceFilterState `query:"gitspace_states"`
// include pagination request
paginationRequest
}
type gitspaceEventsListRequest struct {
Ref string `path:"gitspace_identifier"`
paginationRequest
}
type gitspacesListAllRequest struct {
}
var QueryParameterQueryGitspace = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring which is used to filter the gitspaces by their name or idenitifer."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
func gitspaceOperations(reflector *openapi3.Reflector) {
opCreate := openapi3.Operation{}
opCreate.WithTags("gitspaces")
opCreate.WithSummary("Create gitspace config")
opCreate.WithMapOfAnything(map[string]any{"operationId": "createGitspace"})
_ = reflector.SetRequest(&opCreate, new(createGitspaceRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opCreate, new(types.GitspaceConfig), 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, "/gitspaces", opCreate)
opUpdate := openapi3.Operation{}
opUpdate.WithTags("gitspaces")
opUpdate.WithSummary("Update gitspace config")
opUpdate.WithMapOfAnything(map[string]any{"operationId": "updateGitspace"})
_ = reflector.SetRequest(&opUpdate, new(updateGitspaceRequest), http.MethodPut)
_ = reflector.SetJSONResponse(&opUpdate, new(types.GitspaceConfig), 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, "/gitspaces/{gitspace_identifier}", opUpdate)
opFind := openapi3.Operation{}
opFind.WithTags("gitspaces")
opFind.WithSummary("Get gitspace")
opFind.WithMapOfAnything(map[string]any{"operationId": "findGitspace"})
_ = reflector.SetRequest(&opFind, new(getGitspaceRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opFind, new(types.GitspaceConfig), 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, "/gitspaces/{gitspace_identifier}", opFind)
opDelete := openapi3.Operation{}
opDelete.WithTags("gitspaces")
opDelete.WithSummary("Delete gitspace config")
opDelete.WithMapOfAnything(map[string]any{"operationId": "deleteGitspace"})
_ = reflector.SetRequest(&opDelete, new(getGitspaceRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&opDelete, nil, http.StatusNoContent)
_ = 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, "/gitspaces/{gitspace_identifier}", opDelete)
opList := openapi3.Operation{}
opList.WithTags("gitspaces")
opList.WithSummary("List gitspaces")
opList.WithMapOfAnything(map[string]any{"operationId": "listGitspaces"})
opList.WithParameters(QueryParameterQueryGitspace)
_ = reflector.SetRequest(&opList, new(gitspacesListRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opList, new([]*types.GitspaceConfig), http.StatusOK)
_ = reflector.SetJSONResponse(&opList, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opList, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opList, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/gitspaces", opList)
opEventList := openapi3.Operation{}
opEventList.WithTags("gitspaces")
opEventList.WithSummary("List gitspace events")
opEventList.WithMapOfAnything(map[string]any{"operationId": "listGitspaceEvents"})
_ = reflector.SetRequest(&opEventList, new(gitspaceEventsListRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opEventList, new([]*types.GitspaceEventResponse), http.StatusOK)
_ = reflector.SetJSONResponse(&opEventList, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opEventList, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opEventList, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/gitspaces/{gitspace_identifier}/events", opEventList)
opStreamLogs := openapi3.Operation{}
opStreamLogs.WithTags("gitspaces")
opStreamLogs.WithSummary("Stream gitspace logs")
opStreamLogs.WithMapOfAnything(map[string]any{"operationId": "opStreamLogs"})
_ = reflector.SetRequest(&opStreamLogs, new(gitspaceRequest), http.MethodGet)
_ = reflector.SetStringResponse(&opStreamLogs, http.StatusOK, "text/event-stream")
_ = reflector.SetJSONResponse(&opStreamLogs, []*livelog.Line{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opStreamLogs, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opStreamLogs, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opStreamLogs, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/gitspaces/{gitspace_identifier}/logs/stream", opStreamLogs)
opRepoLookup := openapi3.Operation{}
opRepoLookup.WithTags("gitspaces")
opRepoLookup.WithSummary("Validate git repo for gitspaces")
opRepoLookup.WithMapOfAnything(map[string]any{"operationId": "repoLookupForGitspace"})
_ = reflector.SetRequest(&opRepoLookup, new(lookupRepoGitspaceRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opRepoLookup, new(scm.CodeRepositoryResponse), http.StatusCreated)
_ = reflector.SetJSONResponse(&opRepoLookup, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opRepoLookup, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opRepoLookup, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opRepoLookup, new(usererror.Error), http.StatusForbidden)
_ = reflector.Spec.AddOperation(http.MethodPost, "/gitspaces/lookup-repo", opRepoLookup)
opListAll := openapi3.Operation{}
opListAll.WithTags("gitspaces")
opListAll.WithSummary("List all gitspaces")
opListAll.WithMapOfAnything(map[string]any{"operationId": "listAllGitspaces"})
_ = reflector.SetRequest(&opListAll, new(gitspacesListAllRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opListAll, new([]*types.GitspaceConfig), http.StatusOK)
_ = reflector.SetJSONResponse(&opListAll, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opListAll, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opListAll, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/gitspaces", opListAll)
opAction := openapi3.Operation{}
opAction.WithTags("gitspaces")
opAction.WithSummary("Perform action on a gitspace")
opAction.WithMapOfAnything(map[string]any{"operationId": "actionOnGitspace"})
_ = reflector.SetRequest(&opAction, new(actionGitspaceRequest), http.MethodPost)
_ = reflector.SetJSONResponse(&opAction, new(types.GitspaceConfig), http.StatusOK)
_ = reflector.SetJSONResponse(&opAction, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opAction, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opAction, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPost, "/gitspaces/{gitspace_identifier}/action", opAction)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
harness/harness | https://github.com/harness/harness/blob/a087eef054a8fc8317f4fda02d3c7ee599b71fec/app/api/openapi/user.go | app/api/openapi/user.go | // Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openapi
import (
"net/http"
"github.com/harness/gitness/app/api/controller/user"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/gotidy/ptr"
"github.com/swaggest/openapi-go/openapi3"
)
type tokensRequest struct {
Identifier string `path:"token_identifier"`
}
type favoriteRequest struct {
ResourceID int64 `path:"resource_id"`
ResourceType string `query:"resource_type"`
}
var queryParameterMembershipSpaces = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring by which the spaces the users is a member of are filtered."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterSortMembershipSpaces = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The field by which the spaces the user is a member of are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.MembershipSpaceSortIdentifier),
Enum: enum.MembershipSpaceSort("").Enum(),
},
},
},
}
var queryParameterQueryPublicKey = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamQuery,
In: openapi3.ParameterInQuery,
Description: ptr.String("The substring which is used to filter the public keys by their path identifier."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
},
},
},
}
var queryParameterSortPublicKey = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamSort,
In: openapi3.ParameterInQuery,
Description: ptr.String("The data by which the public keys are sorted."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Default: ptrptr(enum.PublicKeySortCreated),
Enum: enum.PublicKeySort("").Enum(),
},
},
},
}
var queryParameterUsagePublicKey = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamPublicKeyUsage,
In: openapi3.ParameterInQuery,
Description: ptr.String("The public key usage."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Enum: enum.PublicKeyUsage("").Enum(),
},
},
},
},
},
}
var queryParameterSchemePublicKey = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamPublicKeyScheme,
In: openapi3.ParameterInQuery,
Description: ptr.String("The public key scheme."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeArray),
Items: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Enum: enum.PublicKeyScheme("").Enum(),
},
},
},
},
},
}
var QueryParameterResourceType = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamResourceType,
In: openapi3.ParameterInQuery,
Description: ptr.String("The type of the resource to be unfavorited."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeString),
Enum: enum.ResourceType("").Enum(),
},
},
},
}
// helper function that constructs the openapi specification
// for user account resources.
func buildUser(reflector *openapi3.Reflector) {
opFind := openapi3.Operation{}
opFind.WithTags("user")
opFind.WithMapOfAnything(map[string]any{"operationId": "getUser"})
_ = reflector.SetRequest(&opFind, nil, http.MethodGet)
_ = reflector.SetJSONResponse(&opFind, new(types.User), http.StatusOK)
_ = reflector.SetJSONResponse(&opFind, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodGet, "/user", opFind)
opUpdate := openapi3.Operation{}
opUpdate.WithTags("user")
opUpdate.WithMapOfAnything(map[string]any{"operationId": "updateUser"})
_ = reflector.SetRequest(&opUpdate, new(user.UpdateInput), http.MethodPatch)
_ = reflector.SetJSONResponse(&opUpdate, new(types.User), http.StatusOK)
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/user", opUpdate)
opMemberSpaces := openapi3.Operation{}
opMemberSpaces.WithTags("user")
opMemberSpaces.WithMapOfAnything(map[string]any{"operationId": "membershipSpaces"})
opMemberSpaces.WithParameters(
queryParameterMembershipSpaces,
queryParameterOrder, queryParameterSortMembershipSpaces,
QueryParameterPage, QueryParameterLimit)
_ = reflector.SetRequest(&opMemberSpaces, struct{}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&opMemberSpaces, new([]types.MembershipSpace), http.StatusOK)
_ = reflector.SetJSONResponse(&opMemberSpaces, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodGet, "/user/memberships", opMemberSpaces)
opKeyCreate := openapi3.Operation{}
opKeyCreate.WithTags("user")
opKeyCreate.WithMapOfAnything(map[string]any{"operationId": "createPublicKey"})
_ = reflector.SetRequest(&opKeyCreate, new(user.CreatePublicKeyInput), http.MethodPost)
_ = reflector.SetJSONResponse(&opKeyCreate, new(types.PublicKey), http.StatusCreated)
_ = reflector.SetJSONResponse(&opKeyCreate, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opKeyCreate, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodPost, "/user/keys", opKeyCreate)
opKeyDelete := openapi3.Operation{}
opKeyDelete.WithTags("user")
opKeyDelete.WithMapOfAnything(map[string]any{"operationId": "deletePublicKey"})
_ = reflector.SetRequest(&opKeyDelete, struct {
ID string `path:"public_key_identifier"`
}{}, http.MethodDelete)
_ = reflector.SetJSONResponse(&opKeyDelete, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&opKeyDelete, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&opKeyDelete, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodDelete, "/user/keys/{public_key_identifier}", opKeyDelete)
opKeyUpdate := openapi3.Operation{}
opKeyUpdate.WithTags("user")
opKeyUpdate.WithMapOfAnything(map[string]any{"operationId": "updatePublicKey"})
_ = reflector.SetRequest(&opKeyUpdate, struct {
ID string `path:"public_key_identifier"`
}{}, http.MethodPatch)
_ = reflector.SetJSONResponse(&opKeyUpdate, &types.PublicKey{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opKeyUpdate, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opKeyUpdate, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&opKeyUpdate, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/user/keys/{public_key_identifier}", opKeyUpdate)
opKeyList := openapi3.Operation{}
opKeyList.WithTags("user")
opKeyList.WithMapOfAnything(map[string]any{"operationId": "listPublicKey"})
opKeyList.WithParameters(QueryParameterPage, QueryParameterLimit,
queryParameterQueryPublicKey, queryParameterSortPublicKey, queryParameterOrder,
queryParameterUsagePublicKey, queryParameterSchemePublicKey,
)
_ = reflector.SetRequest(&opKeyList, struct{}{}, http.MethodGet)
_ = reflector.SetJSONResponse(&opKeyList, new([]types.PublicKey), http.StatusOK)
_ = reflector.SetJSONResponse(&opKeyList, new(usererror.Error), http.StatusBadRequest)
_ = reflector.SetJSONResponse(&opKeyList, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodGet, "/user/keys", opKeyList)
opListTokens := openapi3.Operation{}
opListTokens.WithTags("user")
opListTokens.WithMapOfAnything(map[string]any{"operationId": "listTokens"})
_ = reflector.SetRequest(&opListTokens, nil, http.MethodGet)
_ = reflector.SetJSONResponse(&opListTokens, new([]types.Token), http.StatusOK)
_ = reflector.SetJSONResponse(&opListTokens, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opListTokens, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opListTokens, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodGet, "/user/tokens", opListTokens)
opCreateToken := openapi3.Operation{}
opCreateToken.WithTags("user")
opCreateToken.WithMapOfAnything(map[string]any{"operationId": "createToken"})
_ = reflector.SetRequest(&opCreateToken, new(user.CreateTokenInput), http.MethodPost)
_ = reflector.SetJSONResponse(&opCreateToken, new(types.TokenResponse), http.StatusCreated)
_ = reflector.SetJSONResponse(&opCreateToken, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opCreateToken, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opCreateToken, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodPost, "/user/tokens", opCreateToken)
opDeleteToken := openapi3.Operation{}
opDeleteToken.WithTags("user")
opDeleteToken.WithMapOfAnything(map[string]any{"operationId": "deleteToken"})
_ = reflector.SetRequest(&opDeleteToken, new(tokensRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&opDeleteToken, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&opDeleteToken, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&opDeleteToken, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opDeleteToken, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opDeleteToken, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodDelete, "/user/tokens/{token_identifier}", opDeleteToken)
opCreateFavorite := openapi3.Operation{}
opCreateFavorite.WithTags("user")
opCreateFavorite.WithMapOfAnything(map[string]any{"operationId": "createFavorite"})
_ = reflector.SetRequest(&opCreateFavorite, new(types.FavoriteResource), http.MethodPost)
_ = reflector.SetJSONResponse(&opCreateFavorite, new(types.FavoriteResource), http.StatusCreated)
_ = reflector.SetJSONResponse(&opCreateFavorite, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opCreateFavorite, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opCreateFavorite, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodPost, "/user/favorite", opCreateFavorite)
opDeleteFavorite := openapi3.Operation{}
opDeleteFavorite.WithTags("user")
opDeleteFavorite.WithMapOfAnything(map[string]any{"operationId": "deleteFavorite"})
opDeleteFavorite.WithParameters(QueryParameterResourceType)
_ = reflector.SetRequest(&opDeleteFavorite, new(favoriteRequest), http.MethodDelete)
_ = reflector.SetJSONResponse(&opDeleteFavorite, nil, http.StatusNoContent)
_ = reflector.SetJSONResponse(&opDeleteFavorite, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opDeleteFavorite, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opDeleteFavorite, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&opDeleteFavorite, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodDelete, "/user/favorite/{resource_id}", opDeleteFavorite)
}
| go | Apache-2.0 | a087eef054a8fc8317f4fda02d3c7ee599b71fec | 2026-01-07T08:36:08.091982Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.