Skip to content

Commit 064647a

Browse files
authored
Merge pull request #1261 from AnuGayan/master
Add dryRun property for API Import action
2 parents 15748dd + 70ed119 commit 064647a

File tree

15 files changed

+193
-38
lines changed

15 files changed

+193
-38
lines changed

import-export-cli/box/resources/sample/sample_config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ environments:
1515
devportal: https://localhost:9443
1616
registration: https://localhost:9443
1717
admin: https://localhost:9443
18-
token: https://localhost:8243/token
18+
token: https://localhost:9443/oauth2/token
1919
mi: https://localhost:9164
2020
sample-env2:
2121
apim: https://wso2am:9443
@@ -31,5 +31,5 @@ environments:
3131
devportal: https://localhost:9443
3232
registration: https://localhost:9443
3333
admin: https://localhost:9443
34-
token: https://localhost:8243/token
34+
token: https://localhost:9443/oauth2/token
3535
mi: ""

import-export-cli/cmd/add.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ const addCmdExamples = utils.ProjectName + ` ` + AddCmdLiteral + ` ` + AddEnvCmd
4040
--publisher https://apim.com:9443 \
4141
--devportal https://apps.com:9443 \
4242
--admin https://apim.com:9443 \
43-
--token https://gw.com:8243/token \
43+
--token https://gw.com:9443/oauth2/token \
4444
--mi https://localhost:9164
4545
4646
` + utils.ProjectName + ` ` + AddCmdLiteral + ` ` + AddEnvCmdLiteralTrimmed + ` dev \
4747
--apim https://apim.com:9443 \
4848
--registration https://idp.com:9443 \
49-
--token https://gw.com:8243/token
49+
--token https://gw.com:9443/oauth2/token
5050
5151
NOTE: The flag --environment (-e) is mandatory.
5252
You can either provide only the flag --apim , or all the other 4 flags (--registration --publisher --devportal --admin) without providing --apim flag.

import-export-cli/cmd/addEnv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ const addEnvCmdExamples = utils.ProjectName + ` ` + AddCmdLiteral + ` ` + AddEnv
5454
--publisher https://apim.com:9443 \
5555
--devportal https://apps.com:9443 \
5656
--admin https://apim.com:9443 \
57-
--token https://gw.com:8243/token \
57+
--token https://gw.com:9443/oauth2/token \
5858
--mi https://localhost:9164
5959
6060
` + utils.ProjectName + ` ` + AddCmdLiteral + ` ` + AddEnvCmdLiteralTrimmed + ` dev \
6161
--apim https://apim.com:9443 \
6262
--registration https://idp.com:9443 \
63-
--token https://gw.com:8243/token
63+
--token https://gw.com:9443/oauth2/token
6464
6565
You can either provide only the flag --apim , or all the other 4 flags (--registration --publisher --devportal --admin) without providing --apim flag.
6666
If you are omitting any of --registration --publisher --devportal --admin flags, you need to specify --apim flag with the API Manager endpoint. In both of the

import-export-cli/cmd/deprecated/addEnv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ const addEnvCmdExamples = utils.ProjectName + ` ` + addEnvCmdLiteral + ` -e prod
4545
--publisher https://apim.com:9443 \
4646
--devportal https://apps.com:9443 \
4747
--admin https://apim.com:9443 \
48-
--token https://gw.com:8243/token
48+
--token https://gw.com:9443/oauth2/token
4949
5050
` + utils.ProjectName + ` ` + addEnvCmdLiteral + ` -e dev \
5151
--apim https://apim.com:9443 \
5252
--registration https://idp.com:9443 \
53-
--token https://gw.com:8243/token
53+
--token https://gw.com:9443/oauth2/token
5454
5555
NOTE: The flag --environment (-e) is mandatory.
5656
You can either provide only the flag --apim , or all the other 4 flags (--registration --publisher --devportal --admin) without providing --apim flag.

import-export-cli/cmd/deprecated/importAPI.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var ImportAPICmdDeprecated = &cobra.Command{
6767
utils.HandleErrorAndExit("Error while getting an access token for importing API", err)
6868
}
6969
err = impl.ImportAPIToEnv(accessOAuthToken, importEnvironment, importAPIFile, importAPIParamsFile, importAPIUpdate,
70-
importAPICmdPreserveProvider, importAPISkipCleanup, false, false)
70+
importAPICmdPreserveProvider, importAPISkipCleanup, false, false, false, "")
7171
if err != nil {
7272
utils.HandleErrorAndExit("Error importing API", err)
7373
return

import-export-cli/cmd/importAPI.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ var (
3434
importAPISkipCleanup bool
3535
importAPIRotateRevision bool
3636
importAPISkipDeployments bool
37+
dryRun bool
38+
apiLoggingCmdFormat string
3739
)
3840

3941
const (
@@ -67,7 +69,8 @@ var ImportAPICmd = &cobra.Command{
6769
utils.HandleErrorAndExit("Error while getting an access token for importing API", err)
6870
}
6971
err = impl.ImportAPIToEnv(accessOAuthToken, importEnvironment, importAPIFile, importAPIParamsFile, importAPIUpdate,
70-
importAPICmdPreserveProvider, importAPISkipCleanup, importAPIRotateRevision, importAPISkipDeployments)
72+
importAPICmdPreserveProvider, importAPISkipCleanup, importAPIRotateRevision, importAPISkipDeployments, dryRun,
73+
apiLoggingCmdFormat)
7174
if err != nil {
7275
utils.HandleErrorAndExit("Error importing API", err)
7376
return
@@ -94,6 +97,10 @@ func init() {
9497
"or a directory generated using \"gen deployment-dir\" command")
9598
ImportAPICmd.Flags().BoolVarP(&importAPISkipCleanup, "skip-cleanup", "", false, "Leave "+
9699
"all temporary files created during import process")
100+
ImportAPICmd.Flags().BoolVarP(&dryRun, "dry-run", "", false, "Get "+
101+
"verification of the governance compliance of the API without importing it")
102+
ImportAPICmd.Flags().StringVarP(&apiLoggingCmdFormat, "format", "", "", "Output format of violation results in "+
103+
"dry-run mode. Supported formats: [table, json, list]. If not provided, the default format is table.")
97104
// Mark required flags
98105
_ = ImportAPICmd.MarkFlagRequired("environment")
99106
_ = ImportAPICmd.MarkFlagRequired("file")

import-export-cli/docs/apictl_add-env.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ apictl add-env -e test \
2121
--publisher https://apim.com:9443 \
2222
--devportal https://apps.com:9443 \
2323
--admin https://apim.com:9443 \
24-
--token https://gw.com:8243/token
24+
--token https://gw.com:9443/oauth2/token
2525
2626
apictl add-env -e dev \
2727
--apim https://apim.com:9443 \
2828
--registration https://idp.com:9443 \
29-
--token https://gw.com:8243/token
29+
--token https://gw.com:9443/oauth2/token
3030
3131
NOTE: The flag --environment (-e) is mandatory.
3232
You can either provide only the flag --apim , or all the other 4 flags (--registration --publisher --devportal --admin) without providing --apim flag.

import-export-cli/docs/apictl_add.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ apictl add env test \
2424
--publisher https://apim.com:9443 \
2525
--devportal https://apps.com:9443 \
2626
--admin https://apim.com:9443 \
27-
--token https://gw.com:8243/token \
27+
--token https://gw.com:9443/oauth2/token \
2828
--mi https://localhost:9164
2929
3030
apictl add env dev \
3131
--apim https://apim.com:9443 \
3232
--registration https://idp.com:9443 \
33-
--token https://gw.com:8243/token
33+
--token https://gw.com:9443/oauth2/token
3434
3535
NOTE: The flag --environment (-e) is mandatory.
3636
You can either provide only the flag --apim , or all the other 4 flags (--registration --publisher --devportal --admin) without providing --apim flag.

import-export-cli/docs/apictl_add_env.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ apictl add env test \
2828
--publisher https://apim.com:9443 \
2929
--devportal https://apps.com:9443 \
3030
--admin https://apim.com:9443 \
31-
--token https://gw.com:8243/token \
31+
--token https://gw.com:9443/oauth2/token \
3232
--mi https://localhost:9164
3333
3434
apictl add env dev \
3535
--apim https://apim.com:9443 \
3636
--registration https://idp.com:9443 \
37-
--token https://gw.com:8243/token
37+
--token https://gw.com:9443/oauth2/token
3838
3939
You can either provide only the flag --apim , or all the other 4 flags (--registration --publisher --devportal --admin) without providing --apim flag.
4040
If you are omitting any of --registration --publisher --devportal --admin flags, you need to specify --apim flag with the API Manager endpoint. In both of the

import-export-cli/git/gitUtils.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,12 @@ func handleIfError(err error, failedProjects map[string][]*params.ProjectParams,
388388
// updatedProjectsPerType is a map of string -> ProjectParams which consists of updated projects per each type (API, App..)
389389
// Returns bool, true if any deleted projects exists so the process should continue with project deletion path
390390
// Returns map[string][]*params.ProjectParams, a map of project type (API, App.. ) to each project detail which are
391-
// deleted projects
391+
//
392+
// deleted projects
393+
//
392394
// Returns map[string][]*params.ProjectParams, a map of project type (API, App.. ) to each project detail which are
393-
// failed during the deployment
395+
//
396+
// failed during the deployment
394397
func deployUpdatedProjects(accessToken, sourceRepoId, deploymentRepoId, environment string, totalProjectsToUpdate int,
395398
updatedProjectsPerType map[string][]*params.ProjectParams) (bool, map[string][]*params.ProjectParams,
396399
map[string][]*params.ProjectParams) {
@@ -432,7 +435,7 @@ func deployUpdatedProjects(accessToken, sourceRepoId, deploymentRepoId, environm
432435
importParams := projectParam.MetaData.DeployConfig.Import
433436
fmt.Println(strconv.Itoa(i+1) + ": " + projectParam.NickName + ": (" + projectParam.RelativePath + ")")
434437
err := impl.ImportAPIToEnv(accessToken, environment, generateSourceProjectPath(mainConfig, projectParam),
435-
projectDeploymentParamsDirLocation, importParams.Update, importParams.PreserveProvider, false, importParams.RotateRevision, false)
438+
projectDeploymentParamsDirLocation, importParams.Update, importParams.PreserveProvider, false, importParams.RotateRevision, false, false, "")
436439
if err != nil {
437440
fmt.Println("Error... ", err)
438441
failedProjects[projectParam.Type] = append(failedProjects[projectParam.Type], projectParam)
@@ -629,8 +632,9 @@ func DeployChangedFiles(accessToken, environment string) map[string][]*params.Pr
629632
}
630633

631634
// Create 'vcs.yaml' in the repository root folder with a unique id (uuid) for the repository.
632-
// If the value of force is false, and the file is already created, gives an error.
633-
// If the value of force is true, It will reinitialize the file even if it already exists.
635+
//
636+
// If the value of force is false, and the file is already created, gives an error.
637+
// If the value of force is true, It will reinitialize the file even if it already exists.
634638
func InitializeRepo(force bool) error {
635639
vcsInfoPath, err := getVcsYamlPath()
636640
if err != nil {
@@ -700,7 +704,9 @@ func logChangedFiles(changedFileList []string) {
700704
}
701705

702706
// subPath denotes a single changed file retrieved from "git diff" command. This path is scanned and then identifies the
703-
// project type (API, App,.. ) from this method.
707+
//
708+
// project type (API, App,.. ) from this method.
709+
//
704710
// envVCSConfig is the environment related VCS configuration
705711
// repoBasePath is the basepath of the git repository
706712
// pathInfoMap is a map of path (string) to project info. This is used for caching and avoid repetitive checking

0 commit comments

Comments
 (0)