Skip to content

Commit

Permalink
Merge pull request #1028 from npamudika/2.x.x
Browse files Browse the repository at this point in the history
Add changes to support ignoreSwaggerDefinition flag
  • Loading branch information
npamudika authored Dec 11, 2023
2 parents 13354a6 + 7c63cc7 commit bb357fa
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion import-export-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Command Line tool for importing and exporting APIs/Applications between differen
- ### Building
`cd` into `product-apim-tooling/import-export-cli`

Execute `./build.sh -t apimcli.go -v 1.0.0 -f` to build for all platforms.
Execute `./build.sh -t apimcli.go -v 2.0.0 -f` to build for all platforms.

Created packages will be available at `build/target` directory

Expand Down
10 changes: 7 additions & 3 deletions import-export-cli/cmd/exportAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var exportAPIName string
var exportAPIVersion string
var exportProvider string
var exportAPIPreserveStatus bool
var ignoreSwaggerDefinition bool
var exportAPIFormat string
var runnigExportApiCommand bool

Expand Down Expand Up @@ -77,7 +78,7 @@ func executeExportAPICmd(credential credentials.Credential, exportDirectory stri

apiImportExportEndpoint := utils.GetApiImportExportEndpointOfEnv(cmdExportEnvironment, utils.MainConfigFilePath)
resp, err := getExportApiResponse(exportAPIName, exportAPIVersion, exportProvider, exportAPIFormat, apiImportExportEndpoint,
b64encodedCredentials, exportAPIPreserveStatus)
b64encodedCredentials, exportAPIPreserveStatus, ignoreSwaggerDefinition)
if err != nil {
utils.HandleErrorAndExit("Error while exporting", err)
}
Expand Down Expand Up @@ -129,10 +130,11 @@ func WriteToZip(exportAPIName, exportAPIVersion, zipLocationPath string, resp *r
// @param apiImportExportEndpoint : API Import Export Endpoint for the environment
// @param b64encodedCredentials: Base64 Encoded 'username:password'
// @return response Response in the form of *resty.Response
func getExportApiResponse(name, version, provider, format, apiImportExportEndpoint, b64encodedCredentials string, preserveStatus bool) (*resty.Response, error) {
func getExportApiResponse(name, version, provider, format, apiImportExportEndpoint, b64encodedCredentials string, preserveStatus bool, ignoreSwagger bool) (*resty.Response, error) {
apiImportExportEndpoint = utils.AppendSlashToString(apiImportExportEndpoint)
query := "export-api?name=" + name + "&version=" + version + "&provider=" + provider +
"&preserveStatus=" + strconv.FormatBool(preserveStatus)
"&preserveStatus=" + strconv.FormatBool(preserveStatus) +
"&ignoreSwagger=" + strconv.FormatBool(ignoreSwagger)
if format != "" {
query += "&format=" + format
}
Expand Down Expand Up @@ -165,6 +167,8 @@ func init() {
"", "Environment to which the API should be exported")
ExportAPICmd.Flags().BoolVarP(&exportAPIPreserveStatus, "preserveStatus", "", true,
"Preserve API status when exporting. Otherwise API will be exported in CREATED status")
ExportAPICmd.Flags().BoolVarP(&ignoreSwaggerDefinition, "ignore-swagger-definition", "", false,
"Ignore swagger definition when exporting. Otherwise API will be exported with the swagger file by default.")
ExportAPICmd.Flags().StringVarP(&exportAPIFormat, "format", "", "", "File format of exported archive(json or yaml)")
_ = ExportAPICmd.MarkFlagRequired("environment")
}
2 changes: 1 addition & 1 deletion import-export-cli/cmd/exportAPI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestExportAPI(t *testing.T) {
}))
defer server.Close()

resp, err := getExportApiResponse("test", "1.0", "admin", "json", server.URL, "", false)
resp, err := getExportApiResponse("test", "1.0", "admin", "json", server.URL, "", false, false)
assert.Nil(t, err, "Error should be nil")
assert.Equal(t, 200, resp.StatusCode())
}
Expand Down
7 changes: 4 additions & 3 deletions import-export-cli/cmd/exportAPIs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ var apis []utils.API
var exportRelatedFilesPath string
var exportAPIsFormat string

//e.g. /home/samithac/.wso2apimcli/exported/migration/production-2.5/wso2-dot-org
var startFromBeginning bool
var isProcessCompleted bool
var startingApiIndexFromList int
Expand Down Expand Up @@ -115,7 +114,7 @@ func exportAPIs() {
exportApiProvider := apis[i].Provider
apiImportExportEndpoint := utils.GetApiImportExportEndpointOfEnv(cmdExportEnvironment, utils.MainConfigFilePath)
resp, err := getExportApiResponse(exportAPIName, exportAPIVersion, exportApiProvider, exportAPIsFormat, apiImportExportEndpoint,
b64encodedCredentials, exportAPIPreserveStatus)
b64encodedCredentials, exportAPIPreserveStatus, ignoreSwaggerDefinition)
if err != nil {
utils.HandleErrorAndExit("Error exporting", err)
}
Expand Down Expand Up @@ -147,7 +146,7 @@ func exportAPIs() {
}
}

// Prepare resumption of previous-halted export-apis operation
// Prepare resumption of previous-halted export-apis operation
func prepareResumption() {
var lastSuceededAPI utils.API
lastSuceededAPI = utils.ReadLastSucceededAPIFileData(exportRelatedFilesPath)
Expand Down Expand Up @@ -283,6 +282,8 @@ func init() {
"any, and to export APIs from beginning")
ExportAPIsCmd.Flags().BoolVarP(&exportAPIPreserveStatus, "preserveStatus", "", true,
"Preserve API status when exporting. Otherwise API will be exported in CREATED status")
ExportAPIsCmd.Flags().BoolVarP(&ignoreSwaggerDefinition, "ignore-swagger-definition", "", false,
"Ignore swagger definition when exporting. Otherwise API will be exported with the swagger file by default.")
ExportAPIsCmd.Flags().StringVarP(&exportAPIsFormat, "format", "", "", "File format of exported archives(json or yaml)")
_ = ExportAPIsCmd.MarkFlagRequired("environment")
}
15 changes: 8 additions & 7 deletions import-export-cli/docs/apimcli_export-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ NOTE: all three flags (--name (-n), --version (-v), --provider (-r)) are mandato
### Options

```
-e, --environment string Environment to which the API should be exported
--format string File format of exported archive(json or yaml)
-h, --help help for export-api
-n, --name string Name of the API to be exported
--preserveStatus Preserve API status when exporting. Otherwise API will be exported in CREATED status (default true)
-r, --provider string Provider of the API
-v, --version string Version of the API to be exported
-e, --environment string Environment to which the API should be exported
--format string File format of exported archive(json or yaml)
-h, --help help for export-api
--ignore-swagger-definition Ignore swagger definition when exporting. Otherwise API will be exported with the swagger file by default.
-n, --name string Name of the API to be exported
--preserveStatus Preserve API status when exporting. Otherwise API will be exported in CREATED status (default true)
-r, --provider string Provider of the API
-v, --version string Version of the API to be exported
```

### Options inherited from parent commands
Expand Down
13 changes: 7 additions & 6 deletions import-export-cli/docs/apimcli_export-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ apimcli export-apis -e production-2.6.0 -u wso2admin@wso2.org -p 12345 -t wso2.o
### Options

```
-e, --environment string Environment to which the API should be exported
--force Clean all the previously exported APIs of the given target tenant, in the given environment if any, and to export APIs from beginning
--format string File format of exported archives(json or yaml)
-h, --help help for export-apis
--preserveStatus Preserve API status when exporting. Otherwise API will be exported in CREATED status (default true)
-t, --tenant string Tenant domain of the resources to be exported
-e, --environment string Environment to which the API should be exported
--force Clean all the previously exported APIs of the given target tenant, in the given environment if any, and to export APIs from beginning
--format string File format of exported archives(json or yaml)
-h, --help help for export-apis
--ignore-swagger-definition Ignore swagger definition when exporting. Otherwise API will be exported with the swagger file by default.
--preserveStatus Preserve API status when exporting. Otherwise API will be exported in CREATED status (default true)
-t, --tenant string Tenant domain of the resources to be exported
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion import-export-cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/spf13/jwalterweatherman v0.0.0-20170901151539-12bd96e66386 // indirect
github.com/spf13/pflag v0.0.0-20171016164048-1f33b80956cd // indirect
github.com/spf13/viper v1.0.0 // indirect
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8
gopkg.in/yaml.v2 v2.2.2
)
13 changes: 13 additions & 0 deletions import-export-cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v0.0.0-20170329110642-4da3e2cfbabc/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/getkin/kin-openapi v0.2.0 h1:PbHHtYZpjKwZtGlIyELgA2DploRrsaXztoNNx9HjwNY=
Expand Down Expand Up @@ -70,9 +72,11 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v0.0.0-20171001224747-2009e44b6f18/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/renstrom/dedent v1.0.0 h1:MKUQ4Nr+V8f9ax+9wYAx5GhspvFzs47vK0oXePaVoWk=
github.com/renstrom/dedent v1.0.0/go.mod h1:M3t8jnE/HlAaLf3m0P158lCmrc8ZErlRB4/cN6V5TXY=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/spf13/afero v0.0.0-20171008182726-e67d870304c4/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.1.0 h1:0Rhw4d6C8J9VPu6cjZLIhZ8+aAOHcDvGeKn+cq5Aq3k=
Expand All @@ -85,8 +89,14 @@ github.com/spf13/pflag v0.0.0-20171016164048-1f33b80956cd/go.mod h1:DYY7MBk1bdzu
github.com/spf13/viper v1.0.0/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -117,3 +127,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ _apimcli_export-api()
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--ignore-swagger-definition")
local_nonpersistent_flags+=("--ignore-swagger-definition")
flags+=("--name=")
two_word_flags+=("-n")
local_nonpersistent_flags+=("--name=")
Expand Down Expand Up @@ -327,6 +329,8 @@ _apimcli_export-apis()
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--ignore-swagger-definition")
local_nonpersistent_flags+=("--ignore-swagger-definition")
flags+=("--preserveStatus")
local_nonpersistent_flags+=("--preserveStatus")
flags+=("--tenant=")
Expand Down

0 comments on commit bb357fa

Please sign in to comment.