Skip to content
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
469 changes: 382 additions & 87 deletions platform-api/api/generated.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions platform-api/internal/dto/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type SecretSummary struct {

// SecretListResponse wraps the paginated list of secrets.
type SecretListResponse struct {
Count int `json:"count"`
List []*SecretSummary `json:"list"`
Pagination Pagination `json:"pagination"`
}
Expand Down
14 changes: 9 additions & 5 deletions platform-api/internal/handler/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ func (h *APIHandler) ListAPIs(w http.ResponseWriter, r *http.Request) error {
return apperror.ValidationFailed.New("projectId query parameter is required")
}

apis, err := h.apiService.GetAPIsByOrganization(orgId, projectId)
opts := parseListOptions(r)

apis, total, err := h.apiService.GetAPIsByOrganization(orgId, projectId, opts)
if err != nil {
if errors.Is(err, constants.ErrProjectNotFound) {
return apperror.ProjectNotFound.Wrap(err).
Expand All @@ -197,9 +199,9 @@ func (h *APIHandler) ListAPIs(w http.ResponseWriter, r *http.Request) error {
Count: len(apis),
List: apis,
Pagination: api.Pagination{
Total: len(apis),
Offset: 0,
Limit: len(apis),
Total: total,
Offset: opts.Offset,
Limit: opts.Limit,
},
}

Expand Down Expand Up @@ -366,7 +368,9 @@ func (h *APIHandler) GetAPIGateways(w http.ResponseWriter, r *http.Request) erro
return apperror.ValidationFailed.New("API ID is required")
}

gatewaysResponse, err := h.apiService.GetAPIGatewaysByHandle(apiId, orgId)
limit, offset := parsePagination(r)

gatewaysResponse, err := h.apiService.GetAPIGatewaysByHandle(apiId, orgId, limit, offset)
if err != nil {
if errors.Is(err, constants.ErrAPINotFound) {
return apperror.RESTAPINotFound.Wrap(err).
Expand Down
3 changes: 3 additions & 0 deletions platform-api/internal/handler/api_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ func (h *DeploymentHandler) GetDeployments(w http.ResponseWriter, r *http.Reques
status = string(*params.Status)
}

limit, offset := parsePagination(r)

deployments, err := h.deploymentService.GetDeploymentsByHandle(apiId, gatewayId, status, orgId)
if err != nil {
if errors.Is(err, constants.ErrAPINotFound) {
Expand All @@ -354,6 +356,7 @@ func (h *DeploymentHandler) GetDeployments(w http.ResponseWriter, r *http.Reques
WithLogMessage(fmt.Sprintf("failed to get deployments for API %s", apiId))
}

paginateDeploymentList(deployments, limit, offset)
httputil.WriteJSON(w, http.StatusOK, deployments)
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion platform-api/internal/handler/apikey_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (h *APIKeyUserHandler) ListUserAPIKeys(w http.ResponseWriter, r *http.Reque
types = strings.Split(typeParam, ",")
}

response, err := h.apiKeyUserService.ListAPIKeysByUser(r.Context(), orgID, callerUserID, types)
limit, offset := parsePagination(r)

response, err := h.apiKeyUserService.ListAPIKeysByUser(r.Context(), orgID, callerUserID, types, limit, offset)
if err != nil {
return apperror.Internal.Wrap(err).
WithLogMessage("failed to list API keys for user in org " + orgID)
Expand Down
86 changes: 5 additions & 81 deletions platform-api/internal/handler/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"log/slog"
"net/http"
"strconv"
"strings"

"github.com/wso2/api-platform/platform-api/api"
Expand Down Expand Up @@ -116,33 +115,9 @@ func (h *ApplicationHandler) ListApplications(w http.ResponseWriter, r *http.Req
return apperror.ValidationFailed.New("Project ID is required")
}

var limitStr string
if v := r.URL.Query().Get("limit"); v != "" {
limitStr = v
} else {
limitStr = "20"
}
var offsetStr string
if v := r.URL.Query().Get("offset"); v != "" {
offsetStr = v
} else {
offsetStr = "0"
}

limit, err := strconv.Atoi(limitStr)
if err != nil || limit <= 0 {
limit = 20
}
if limit > 100 {
limit = 100
}

offset, err := strconv.Atoi(offsetStr)
if err != nil || offset < 0 {
offset = 0
}
opts := parseListOptions(r)

apps, err := h.applicationService.GetApplicationsByOrganization(orgID, projectID, limit, offset)
apps, err := h.applicationService.GetApplicationsByOrganization(orgID, projectID, opts)
if err != nil {
return h.mapApplicationError(err).
WithLogMessage(fmt.Sprintf("failed to list applications for project %s in org %s", projectID, orgID))
Expand Down Expand Up @@ -220,24 +195,7 @@ func (h *ApplicationHandler) ListApplicationAssociations(w http.ResponseWriter,
return apperror.ValidationFailed.New("Application ID is required")
}

limit := 20
if limitStr := strings.TrimSpace(r.URL.Query().Get("limit")); limitStr != "" {
parsedLimit, err := strconv.Atoi(limitStr)
if err == nil && parsedLimit > 0 {
if parsedLimit > 100 {
parsedLimit = 100
}
limit = parsedLimit
}
}

offset := 0
if offsetStr := strings.TrimSpace(r.URL.Query().Get("offset")); offsetStr != "" {
parsedOffset, err := strconv.Atoi(offsetStr)
if err == nil && parsedOffset >= 0 {
offset = parsedOffset
}
}
limit, offset := parsePagination(r)

associations, err := h.applicationService.ListApplicationAssociations(appID, orgID, limit, offset)
if err != nil {
Expand Down Expand Up @@ -316,24 +274,7 @@ func (h *ApplicationHandler) ListApplicationAPIKeys(w http.ResponseWriter, r *ht
return apperror.ValidationFailed.New("Application ID is required")
}

limit := 20
if limitStr := strings.TrimSpace(r.URL.Query().Get("limit")); limitStr != "" {
parsedLimit, err := strconv.Atoi(limitStr)
if err == nil && parsedLimit > 0 {
if parsedLimit > 100 {
parsedLimit = 100
}
limit = parsedLimit
}
}

offset := 0
if offsetStr := strings.TrimSpace(r.URL.Query().Get("offset")); offsetStr != "" {
parsedOffset, err := strconv.Atoi(offsetStr)
if err == nil && parsedOffset >= 0 {
offset = parsedOffset
}
}
limit, offset := parsePagination(r)

keys, err := h.applicationService.ListMappedAPIKeys(appID, orgID, limit, offset)
if err != nil {
Expand Down Expand Up @@ -361,24 +302,7 @@ func (h *ApplicationHandler) ListApplicationAssociationAPIKeys(w http.ResponseWr
return apperror.ValidationFailed.New("Association ID is required")
}

limit := 20
if limitStr := strings.TrimSpace(r.URL.Query().Get("limit")); limitStr != "" {
parsedLimit, err := strconv.Atoi(limitStr)
if err == nil && parsedLimit > 0 {
if parsedLimit > 100 {
parsedLimit = 100
}
limit = parsedLimit
}
}

offset := 0
if offsetStr := strings.TrimSpace(r.URL.Query().Get("offset")); offsetStr != "" {
parsedOffset, err := strconv.Atoi(offsetStr)
if err == nil && parsedOffset >= 0 {
offset = parsedOffset
}
}
limit, offset := parsePagination(r)

keys, err := h.applicationService.ListMappedAPIKeysForAssociation(appID, associationID, orgID, limit, offset)
if err != nil {
Expand Down
22 changes: 18 additions & 4 deletions platform-api/internal/handler/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ func (h *GatewayHandler) ListGateways(w http.ResponseWriter, r *http.Request) er
return apperror.Unauthorized.New().WithLogMessage("organization claim not found in token")
}

gateways, err := h.gatewayService.ListGateways(&organizationID)
opts := parseListOptions(r)

gateways, err := h.gatewayService.ListGateways(&organizationID, opts)
if err != nil {
return apperror.Internal.Wrap(err).WithLogMessage("failed to list gateways")
}
Expand Down Expand Up @@ -293,7 +295,9 @@ func (h *GatewayHandler) ListTokens(w http.ResponseWriter, r *http.Request) erro
return apperror.ValidationFailed.New("Gateway ID is required")
}

tokens, err := h.gatewayService.ListTokens(gatewayId, orgId)
limit, offset := parsePagination(r)

tokens, err := h.gatewayService.ListTokens(gatewayId, orgId, limit, offset)
if err != nil {
var appErr *apperror.Error
if errors.As(err, &appErr) {
Expand Down Expand Up @@ -500,12 +504,22 @@ func (h *GatewayHandler) ListCustomPolicies(w http.ResponseWriter, r *http.Reque
return apperror.Unauthorized.New().WithLogMessage("organization claim not found in token")
}

policies, err := h.gatewayService.ListCustomPolicies(orgId)
limit, offset := parsePagination(r)

policies, total, err := h.gatewayService.ListCustomPolicies(orgId, limit, offset)
if err != nil {
return apperror.Internal.Wrap(err).WithLogMessage(fmt.Sprintf("failed to list custom policies, orgID=%s", orgId))
}

httputil.WriteJSON(w, http.StatusOK, policies)
httputil.WriteJSON(w, http.StatusOK, map[string]any{
"count": len(policies),
"list": policies,
"pagination": api.Pagination{
Total: total,
Offset: offset,
Limit: limit,
},
})
return nil
}

Expand Down
89 changes: 4 additions & 85 deletions platform-api/internal/handler/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"io"
"log/slog"
"net/http"
"strconv"
"strings"

"github.com/wso2/api-platform/platform-api/api"
Expand Down Expand Up @@ -208,27 +207,7 @@ func (h *LLMHandler) ListLLMProviderTemplates(w http.ResponseWriter, r *http.Req
WithLogMessage("organization claim not found in token")
}

limitStr := r.URL.Query().Get("limit")
if limitStr == "" {
limitStr = "20"
}
offsetStr := r.URL.Query().Get("offset")
if offsetStr == "" {
offsetStr = "0"
}

limit, err := strconv.Atoi(limitStr)
if err != nil || limit <= 0 {
limit = 20
}
if limit > 100 {
limit = 100
}

offset, err := strconv.Atoi(offsetStr)
if err != nil || offset < 0 {
offset = 0
}
limit, offset := parsePagination(r)

q, familyScoped := parseTemplateQuery(r.URL.Query().Get("query"))
if familyScoped {
Expand Down Expand Up @@ -464,27 +443,7 @@ func (h *LLMHandler) ListLLMProviders(w http.ResponseWriter, r *http.Request) er
WithLogMessage("organization claim not found in token")
}

limitStr := r.URL.Query().Get("limit")
if limitStr == "" {
limitStr = "20"
}
offsetStr := r.URL.Query().Get("offset")
if offsetStr == "" {
offsetStr = "0"
}

limit, err := strconv.Atoi(limitStr)
if err != nil || limit <= 0 {
limit = 20
}
if limit > 100 {
limit = 100
}

offset, err := strconv.Atoi(offsetStr)
if err != nil || offset < 0 {
offset = 0
}
limit, offset := parsePagination(r)

resp, err := h.providerService.List(orgID, limit, offset)
if err != nil {
Expand Down Expand Up @@ -654,27 +613,7 @@ func (h *LLMHandler) ListLLMProxies(w http.ResponseWriter, r *http.Request) erro
return apperror.ValidationFailed.New("projectId query parameter is required")
}

limitStr := r.URL.Query().Get("limit")
if limitStr == "" {
limitStr = "20"
}
offsetStr := r.URL.Query().Get("offset")
if offsetStr == "" {
offsetStr = "0"
}

limit, err := strconv.Atoi(limitStr)
if err != nil || limit <= 0 {
limit = 20
}
if limit > 100 {
limit = 100
}

offset, err := strconv.Atoi(offsetStr)
if err != nil || offset < 0 {
offset = 0
}
limit, offset := parsePagination(r)

resp, err := h.proxyService.List(orgID, &projectID, limit, offset)
if err != nil {
Expand All @@ -696,27 +635,7 @@ func (h *LLMHandler) ListLLMProxiesByProvider(w http.ResponseWriter, r *http.Req
}
providerID := r.PathValue("llmProviderId")

limitStr := r.URL.Query().Get("limit")
if limitStr == "" {
limitStr = "20"
}
offsetStr := r.URL.Query().Get("offset")
if offsetStr == "" {
offsetStr = "0"
}

limit, err := strconv.Atoi(limitStr)
if err != nil || limit <= 0 {
limit = 20
}
if limit > 100 {
limit = 100
}

offset, err := strconv.Atoi(offsetStr)
if err != nil || offset < 0 {
offset = 0
}
limit, offset := parsePagination(r)

resp, err := h.proxyService.ListByProvider(orgID, providerID, limit, offset)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion platform-api/internal/handler/llm_apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ func (h *LLMProviderAPIKeyHandler) ListAPIKeys(w http.ResponseWriter, r *http.Re
return err
}

response, err := h.apiKeyService.ListLLMProviderAPIKeys(r.Context(), providerID, orgID, callerUserID)
limit, offset := parsePagination(r)

response, err := h.apiKeyService.ListLLMProviderAPIKeys(r.Context(), providerID, orgID, callerUserID, limit, offset)
if err != nil {
var appErr *apperror.Error
if errors.As(err, &appErr) {
Expand Down
Loading
Loading