Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add get method for application search #561

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 76 additions & 2 deletions api/applications/applications_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package applications
import (
"encoding/json"
"net/http"
"strconv"
"strings"

applicationModels "github.com/equinor/radix-api/api/applications/models"
Expand Down Expand Up @@ -68,6 +69,15 @@ func (ac *applicationController) GetRoutes() models.Routes {
Burst: 100,
},
},
models.Route{
Path: rootPath + "/applications/_search",
Method: "GET",
HandlerFunc: ac.SearchApplications,
KubeApiConfig: models.KubeApiConfig{
QPS: 100,
Burst: 100,
},
},
models.Route{
Path: appPath,
Method: "GET",
Expand Down Expand Up @@ -180,11 +190,61 @@ func (ac *applicationController) ShowApplications(accounts models.Accounts, w ht
radixhttp.JSONResponse(w, r, appRegistrations)
}

// SearchApplications Gets applications by list of application names
func (ac *applicationController) SearchApplications(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /applications/_search platform getSearchApplications
//
// ---
// summary: Get applications by name. NOTE - doesn't get applicationSummary.latestJob.Environments
// parameters:
// - name: apps
// in: query
// description: Comma separated list of application names to search for
// required: true
// type: string
// - name: includeLatestJobSummary
// in: query
// description: true to include LatestJobSummary
// required: false
// type: string
// - name: includeEnvironmentActiveComponents
// in: query
// description: true to include ActiveComponents in Environments
// required: false
// type: string
// - name: Impersonate-User
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set)
// type: string
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
// description: "Successful operation"
// schema:
// type: "array"
// items:
// "$ref": "#/definitions/ApplicationSummary"
// "401":
// description: "Unauthorized"
// "403":
// description: "Forbidden"
// "404":
// description: "Not found"
// "409":
// description: "Conflict"
// "500":
// description: "Internal server error"

// swagger:operation POST /applications/_search platform searchApplications
//
// ---
// summary: Get applications by name. NOTE - doesn't get applicationSummary.latestJob.Environments
// deprecated: true
// parameters:
// - name: applicationSearch
// in: body
Expand Down Expand Up @@ -221,8 +281,22 @@ func (ac *applicationController) SearchApplications(accounts models.Accounts, w
// description: "Internal server error"

var appNamesRequest applicationModels.ApplicationsSearchRequest
if err := json.NewDecoder(r.Body).Decode(&appNamesRequest); err != nil {
radixhttp.ErrorResponse(w, r, err)
switch r.Method {
case http.MethodGet:
appNamesRequest.Names = strings.Split(r.FormValue("apps"), ",")
if includeLatestJobSummary, _ := strconv.ParseBool(r.FormValue("includeLatestJobSummary")); includeLatestJobSummary {
appNamesRequest.IncludeFields.LatestJobSummary = true
}
if includeEnvActiveComponents, _ := strconv.ParseBool(r.FormValue("includeEnvironmentActiveComponents")); includeEnvActiveComponents {
appNamesRequest.IncludeFields.EnvironmentActiveComponents = true
}
case http.MethodPost:
if err := json.NewDecoder(r.Body).Decode(&appNamesRequest); err != nil {
radixhttp.ErrorResponse(w, r, err)
return
}
default:
w.WriteHeader(http.StatusNotFound)
return
}

Expand Down
Loading