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 basePath validation and assign servers URL's context as basePath [In Progress] #1954

Closed
wants to merge 12 commits into from
Closed
30 changes: 22 additions & 8 deletions adapter/internal/api/apis_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func extractAPIProject(payload []byte) (apiProject ProjectAPI, err error) {
upstreamCerts = append(upstreamCerts, unzippedFileBytes...)
upstreamCerts = append(upstreamCerts, newLineByteArray...)
} else if (strings.Contains(file.Name, apiYAMLFile) || strings.Contains(file.Name, apiJSONFile)) &&
!strings.Contains(file.Name, openAPIDir){
!strings.Contains(file.Name, openAPIDir) {
loggers.LoggerAPI.Debugf("fileName : %v", file.Name)
unzippedFileBytes, err := readZipFile(file)
if err != nil {
Expand Down Expand Up @@ -257,7 +257,13 @@ func ApplyAPIProjectFromAPIM(payload []byte, vhostToEnvsMap map[string][]string)
}
}
// first update the API for vhost
updateAPI(vhost, apiInfo, apiProject, environments)
apiContent := generateAPIContent(vhost, apiInfo, apiProject, environments)
// In APIM mode, it is required to skip rather than rejecting the whole API deployment.
// IN APIM scenario, APIM does the validation. Hence the override remains true.
if xds.ValidateAPI(apiContent, true) != nil {
continue
}
xds.UpdateAPI(apiContent)
}

// undeploy APIs with other vhosts in the same gateway environment
Expand Down Expand Up @@ -315,17 +321,25 @@ func ApplyAPIProjectInStandaloneMode(payload []byte, override *bool) error {
append(vhostToEnvsMap[environment.DeploymentVhost], environment.DeploymentEnvironment)
}

// From this all the APIs would be validated prior to update Xds Caches.
// TODO: (renuka) optimize to update cache only once when all internal memory maps are updated
for vhost, environments := range vhostToEnvsMap {
updateAPI(vhost, apiInfo, apiProject, environments)
apiContent := generateAPIContent(vhost, apiInfo, apiProject, environments)
err := xds.ValidateAPI(apiContent, overrideValue)
if err != nil {
return errors.New(mgw.ValidationFailure + " : " + err.Error())
}
}

// After the API is validated against all the vhosts, update xds cache.
for vhost, environments := range vhostToEnvsMap {
apiContent := generateAPIContent(vhost, apiInfo, apiProject, environments)
xds.UpdateAPI(apiContent)
}
return nil
}

func updateAPI(vhost string, apiInfo ApictlProjectInfo, apiProject ProjectAPI, environments []string) {
if len(environments) == 0 {
environments = append(environments, config.DefaultGatewayName)
}
func generateAPIContent(vhost string, apiInfo ApictlProjectInfo, apiProject ProjectAPI, environments []string) config.APIContent {
var apiContent config.APIContent
apiContent.UUID = apiInfo.ID
apiContent.VHost = vhost
Expand All @@ -350,7 +364,7 @@ func updateAPI(vhost string, apiInfo ApictlProjectInfo, apiProject ProjectAPI, e
} else if apiProject.APIType == mgw.WS {
apiContent.APIDefinition = apiProject.APIJsn
}
xds.UpdateAPI(apiContent)
return apiContent
}

func extractAPIInformation(apiProject *ProjectAPI, apiObject config.APIJsonData) {
Expand Down
15 changes: 0 additions & 15 deletions adapter/internal/api/models/api_meta.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions adapter/internal/api/models/api_meta_list_item.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions adapter/internal/api/models/credentials.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions adapter/internal/api/models/deploy_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions adapter/internal/api/models/error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions adapter/internal/api/models/error_list_item.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions adapter/internal/api/models/principal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion adapter/internal/api/restserver/config_restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ package restserver

import (
"crypto/tls"
"github.com/wso2/adapter/internal/discovery/xds"
"io/ioutil"
"net/http"
"strconv"
"strings"

"github.com/wso2/adapter/internal/discovery/xds"

"github.com/go-openapi/errors"
"github.com/go-openapi/loads"
"github.com/go-openapi/runtime"
Expand Down Expand Up @@ -145,6 +146,14 @@ func configureAPI(api *operations.RestapiAPI) http.Handler {
jsonByteArray, _ := ioutil.ReadAll(params.File)
err := apiServer.ApplyAPIProjectInStandaloneMode(jsonByteArray, params.Override)
if err != nil {
if strings.Contains(err.Error(), constants.ValidationFailure) {
errorResp := api_individual.NewPostApisBadRequest()
payload := &models.Error{
Description: err.Error(),
}
errorResp.Payload = payload
return errorResp
}
switch err.Error() {
case constants.AlreadyExists:
return api_individual.NewPostApisConflict()
Expand Down
14 changes: 0 additions & 14 deletions adapter/internal/api/restserver/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 12 additions & 17 deletions adapter/internal/api/restserver/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading