Skip to content

Commit

Permalink
add get method for searching apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Pespiri committed Nov 28, 2023
1 parent 681adb9 commit ca9c57e
Show file tree
Hide file tree
Showing 3 changed files with 343 additions and 49 deletions.
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

0 comments on commit ca9c57e

Please sign in to comment.