Skip to content

Commit

Permalink
Merge pull request #977 from lakshithagunasekara/throttle-policy-fix
Browse files Browse the repository at this point in the history
Group exported rate limiting policies by env name and import with relative path
  • Loading branch information
Lakshitha Gunasekara authored Mar 10, 2023
2 parents 8ea296f + bbd02d7 commit 142b07d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 4 additions & 2 deletions import-export-cli/cmd/exportThrottlePolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ package cmd

import (
"fmt"
"github.com/wso2/product-apim-tooling/import-export-cli/impl"
"net/http"

"github.com/wso2/product-apim-tooling/import-export-cli/impl"

"github.com/wso2/product-apim-tooling/import-export-cli/credentials"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -77,8 +78,9 @@ func executeExportThrottlePolicyCmd(credential credentials.Credential, exportDir
}
// Print info on response
utils.Logf(utils.LogPrefixInfo+"ResponseStatus: %v\n", resp.Status())
throttlePolicyZipLocationPath := filepath.Join(exportDirectory, CmdExportEnvironment)
if resp.StatusCode() == http.StatusOK {
impl.WriteThrottlePolicyToFile(exportDirectory, resp, exportThrottlePolicyFormat, runningExportThrottlePolicyCommand)
impl.WriteThrottlePolicyToFile(throttlePolicyZipLocationPath, resp, exportThrottlePolicyFormat, runningExportThrottlePolicyCommand)
} else if resp.StatusCode() == http.StatusInternalServerError {
// 500 Internal Server Error
fmt.Println(string(resp.Body()))
Expand Down
16 changes: 13 additions & 3 deletions import-export-cli/impl/importThrottlePolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ package impl
import (
"errors"
"fmt"
"github.com/go-resty/resty/v2"
"github.com/wso2/product-apim-tooling/import-export-cli/utils"
"net/http"
"os"
"path/filepath"
"strconv"

"github.com/go-resty/resty/v2"
"github.com/wso2/product-apim-tooling/import-export-cli/utils"
)

func ImportThrottlingPolicyToEnv(accessOAuthToken, importEnvironment, importPath string, importThrottlePolicyUpdate bool) error {
Expand All @@ -41,7 +43,15 @@ func ImportThrottlingPolicyToEnv(accessOAuthToken, importEnvironment, importPath
}

func importThrottlingPolicy(endpoint string, importPath string, accessToken string, isOauth bool, ThrottlePolicyUpdate bool) error {
resp, err := executeThrottlingPolicyUploadRequest(endpoint, importPath, ThrottlePolicyUpdate, accessToken, isOauth)
exportDirectory := filepath.Join(utils.ExportDirectory, utils.ExportedPoliciesDirName, utils.ExportedThrottlePoliciesDirName)
resolvedPolicyFilePath, err := resolvePolicyImportFilePath(importPath, exportDirectory)
if err != nil {
return err
}

utils.Logln(utils.LogPrefixInfo + "Policy Location: ", resolvedPolicyFilePath)

resp, err := executeThrottlingPolicyUploadRequest(endpoint, resolvedPolicyFilePath, ThrottlePolicyUpdate, accessToken, isOauth)
utils.Logf("Response : %v", resp)
if err != nil {
utils.Logln(utils.LogPrefixError, err)
Expand Down

0 comments on commit 142b07d

Please sign in to comment.