这是indexloc提供的服务,不要输入任何密码
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
25 changes: 19 additions & 6 deletions bundlegen/generateapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,11 @@ func GetEndpoint(doc *openapi3.T) (u *url.URL, err error) {
func GenerateAPIProxyDefFromGQL(name string,
gqlDocName string,
basePath string,
targetUrlRef string,
apiKeyLocation string,
skipPolicy bool,
addCORS bool) (err error) {
addCORS bool,
targetUrlRef string,
targetUrl string) (err error) {

apiproxy.SetDisplayName(name)
apiproxy.SetCreatedAt()
Expand All @@ -315,17 +316,29 @@ func GenerateAPIProxyDefFromGQL(name string,
apiproxy.AddPolicy("Validate-" + name + "-Schema")
}

targets.NewTargetEndpoint("https://api.example.com", "", "", "")

proxies.NewProxyEndpoint(basePath)

if addCORS {
proxies.AddStepToPreFlowRequest("Add-CORS")
apiproxy.AddPolicy("Add-CORS")
}

targets.AddStepToPreFlowRequest("Set-Target-1")
apiproxy.AddPolicy("Set-Target-1")
//set a dynamic target url
if targetUrlRef != "" {
targets.AddStepToPreFlowRequest("Set-Target-1")
apiproxy.AddPolicy("Set-Target-1")
generateSetTarget = true
}

//if target is not set, derive it from the OAS file
if targetUrl == "" {
targets.NewTargetEndpoint("https://api.example.com", "", "", "")
} else { //an explicit target url is set
if _, err = url.Parse(targetUrl); err != nil {
return fmt.Errorf("Invalid target url: ", err)
}
targets.NewTargetEndpoint(targetUrl, "", "", "")
}

if !skipPolicy {
proxies.AddStepToPreFlowRequest("Validate-" + name + "-Schema")
Expand Down
11 changes: 7 additions & 4 deletions bundlegen/proxybundle/proxybundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ func GenerateAPIProxyBundleFromGQL(name string,
keyName string,
skipPolicy bool,
addCORS bool,
targetUrlRef string) (err error) {
targetUrlRef string,
targetUrl string) (err error) {

var apiProxyData, proxyEndpointData, targetEndpointData string
const resourceType = "graphql"
Expand Down Expand Up @@ -245,9 +246,11 @@ func GenerateAPIProxyBundleFromGQL(name string,
return err
}

if err = writeXMLData(policiesDirPath+string(os.PathSeparator)+"Set-Target-1.xml",
policies.AddSetTargetEndpoint(targetUrlRef)); err != nil {
return err
if targetUrlRef != "" {
if err = writeXMLData(policiesDirPath+string(os.PathSeparator)+"Set-Target-1.xml",
policies.AddSetTargetEndpoint(targetUrlRef)); err != nil {
return err
}
}

if !skipPolicy {
Expand Down
18 changes: 12 additions & 6 deletions cmd/apis/gqlcrtapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ var GqlCreateCmd = &cobra.Command{
if gqlFile == "" && gqlURI == "" {
return fmt.Errorf("Either gqlfile or gqlurl must be passed")
}
if targetUrl != "" && targetUrlRef != "" {
return fmt.Errorf("Either target-url or target-url-ref must be passed, not both")
}
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -62,10 +65,11 @@ var GqlCreateCmd = &cobra.Command{
err = bundle.GenerateAPIProxyDefFromGQL(name,
gqlDocName,
basePath,
targetUrlRef,
apiKeyLocation,
skipPolicy,
addCORS)
addCORS,
targetUrlRef,
targetUrl)

if err != nil {
return err
Expand All @@ -80,7 +84,8 @@ var GqlCreateCmd = &cobra.Command{
keyName,
skipPolicy,
addCORS,
targetUrlRef)
targetUrlRef,
targetUrl)

if err != nil {
return err
Expand Down Expand Up @@ -108,8 +113,10 @@ func init() {
GqlCreateCmd.Flags().StringVarP(&action, "action", "",
"verify", "GraphQL policy action, must be oneOf parse, verify or parse_verify. Default is verify")
GqlCreateCmd.Flags().StringVarP(&targetUrlRef, "target-url-ref", "",
"", "Set a reference variable containing the target endpoint")
GqlCreateCmd.Flags().StringVarP(&targetUrlRef, "apikey-location", "",
"", "Set target.url variable from a reference variable containing the target endpoint")
GqlCreateCmd.Flags().StringVarP(&targetUrl, "target-url", "",
"", "Set a target URL for the target endpoint")
GqlCreateCmd.Flags().StringVarP(&apiKeyLocation, "apikey-location", "",
"", "Set the location of the API key, ex: request.header.x-api-key")
GqlCreateCmd.Flags().BoolVarP(&importProxy, "import", "",
true, "Import API Proxy after generation from spec")
Expand All @@ -119,7 +126,6 @@ func init() {
false, "Add a CORS policy")

_ = GqlCreateCmd.MarkFlagRequired("name")
_ = GqlCreateCmd.MarkFlagRequired("target-url-ref")
_ = GqlCreateCmd.MarkFlagRequired("basepath")
}

Expand Down