-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #402 from malinthaprasan/gitint
APICTL + Git integration
- Loading branch information
Showing
31 changed files
with
1,405 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wso2/product-apim-tooling/import-export-cli/utils" | ||
) | ||
|
||
// vcs command related usage Info | ||
const vcsCmdLiteral = "vcs" | ||
const vcsCmdShortDesc = "Checks status and deploys projects" | ||
const vcsCmdLongDesc = `Checks status and deploys projects to the specified environment. In order to | ||
use this command, 'git' must be installed in the system.'` | ||
const vcsCmdExamples = utils.ProjectName + ` ` + vcsStatusCmdLiteral + ` ` + ` -e dev | ||
` + utils.ProjectName + ` ` + deployCmdLiteral + ` -e dev` | ||
|
||
// vcsCmd represents the vcs command | ||
var VCSCmd = &cobra.Command{ | ||
Use: vcsCmdLiteral, | ||
Short: vcsCmdShortDesc, | ||
Long: vcsCmdLongDesc, | ||
Example: vcsCmdExamples, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
utils.Logln(utils.LogPrefixInfo + vcsCmdLiteral + " called") | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(VCSCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/wso2/product-apim-tooling/import-export-cli/credentials" | ||
"github.com/wso2/product-apim-tooling/import-export-cli/git" | ||
"github.com/wso2/product-apim-tooling/import-export-cli/utils" | ||
) | ||
|
||
var flagVCSDeployEnvName string // name of the environment the project changes need to be deployed | ||
var flagVCSDeploySkipRollback bool // specifies whether rolling back on error needs to be avoided | ||
|
||
// deploy command related usage Info | ||
const deployCmdLiteral = "deploy" | ||
const deployCmdShortDesc = "Deploys projects to the specified environment" | ||
const deployCmdLongDesc = `Deploys projects to the specified environment specified by --environment(-e). | ||
Only the changed projects compared to the revision at the last successful deployment will be deployed. | ||
If any project(s) got failed during the deployment, by default, the operation will rollback the environment to the last successful state. If this needs to be avoided, use --skipRollback=true | ||
NOTE: --environment (-e) flag is mandatory` | ||
|
||
const deployCmdExamples = utils.ProjectName + ` ` + deployCmdLiteral + ` -e dev | ||
` + utils.ProjectName + ` ` + deployCmdLiteral + ` -e dev --skipRollback=true` | ||
|
||
// deployCmd represents the deploy command | ||
var DeployCmd = &cobra.Command{ | ||
Use: deployCmdLiteral, | ||
Short: deployCmdShortDesc, | ||
Long: deployCmdLongDesc, | ||
Example: deployCmdExamples, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
utils.Logln(utils.LogPrefixInfo + deployCmdLiteral + " called") | ||
credential, err := getCredentials(flagVCSDeployEnvName) | ||
if err != nil { | ||
utils.HandleErrorAndExit("Error getting credentials", err) | ||
} | ||
accessOAuthToken, err := credentials.GetOAuthAccessToken(credential, flagVCSDeployEnvName) | ||
if err != nil { | ||
utils.HandleErrorAndExit("Error while getting an access token for deploying the project(s)", err) | ||
} | ||
failedProjects := git.DeployChangedFiles(accessOAuthToken, flagVCSDeployEnvName) | ||
if failedProjects != nil && len(failedProjects) > 0 && flagVCSDeploySkipRollback == false { | ||
fmt.Println("\nRolling back to the last successful revision as there are failures..") | ||
git.Rollback(accessOAuthToken, flagVCSDeployEnvName) | ||
utils.HandleErrorAndExit("There are project deployment failures. Rolled back to the last successful revision.", err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
VCSCmd.AddCommand(DeployCmd) | ||
|
||
DeployCmd.Flags().StringVarP(&flagVCSDeployEnvName, "environment", "e", "", "Name of the " + | ||
"environment to deploy the project(s)") | ||
DeployCmd.Flags().BoolVarP(&flagVCSDeploySkipRollback, "skipRollback", "", false, | ||
"Specifies whether rolling back to the last successful revision during an error situation should be skipped") | ||
|
||
_ = DeployCmd.MarkFlagRequired("environment") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/wso2/product-apim-tooling/import-export-cli/git" | ||
"github.com/wso2/product-apim-tooling/import-export-cli/specs/params" | ||
"github.com/wso2/product-apim-tooling/import-export-cli/utils" | ||
"strconv" | ||
) | ||
|
||
var flagVCSStatusEnvName string // name of the environment to be added | ||
|
||
// push command related usage Info | ||
const vcsStatusCmdLiteral = "status" | ||
const vcsStatusCmdShortDesc = "Shows the list of projects that are ready to deploy" | ||
const vcsStatusCmdLongDesc = `Shows the list of projects that are ready to deploy to the specified environment by --environment(-e) | ||
NOTE: --environment (-e) flag is mandatory` | ||
|
||
const vcsStatusCmdCmdExamples = utils.ProjectName + ` ` + vcsStatusCmdLiteral + ` ` + ` -e dev` | ||
|
||
// pushCmd represents the push command | ||
var VCSStatusCmd = &cobra.Command{ | ||
Use: vcsStatusCmdLiteral, | ||
Short: vcsStatusCmdShortDesc, | ||
Long: vcsStatusCmdLongDesc, | ||
Example: vcsStatusCmdCmdExamples, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
utils.Logln(utils.LogPrefixInfo + vcsStatusCmdLiteral + " called") | ||
totalProjectsToUpdate, updatedProjectsPerType := git.GetStatus(flagVCSStatusEnvName, git.FromRevTypeLastAttempted) | ||
|
||
if totalProjectsToUpdate == 0 { | ||
fmt.Println("Everything is up-to-date") | ||
return | ||
} | ||
|
||
fmt.Println("Projects to Update (" + strconv.Itoa(totalProjectsToUpdate) + ")"); | ||
printProjectsToUpdate(utils.ProjectTypeApi, updatedProjectsPerType[utils.ProjectTypeApi]) | ||
printProjectsToUpdate(utils.ProjectTypeApiProduct, updatedProjectsPerType[utils.ProjectTypeApiProduct]) | ||
printProjectsToUpdate(utils.ProjectTypeApplication, updatedProjectsPerType[utils.ProjectTypeApplication]) | ||
}, | ||
} | ||
|
||
func printProjectsToUpdate(projectType string, projects []*params.ProjectParams) { | ||
if len(projects) != 0 { | ||
fmt.Println("\n" + projectType + "s (" + strconv.Itoa(len(projects)) + ") ...") | ||
for i, projectParam := range projects { | ||
var operation string | ||
var failed string | ||
if projectParam.Deleted { | ||
operation = "[delete]" | ||
} else { | ||
operation = "[save]" | ||
} | ||
if projectParam.FailedDuringPreviousDeploy { | ||
failed = "[failed]" | ||
} | ||
fmt.Println(strconv.Itoa(i+1) + ": " + operation + "\t" + failed + "\t" + projectParam.NickName + | ||
": (" + projectParam.RelativePath + ")") | ||
} | ||
} | ||
} | ||
|
||
func init() { | ||
VCSCmd.AddCommand(VCSStatusCmd) | ||
|
||
VCSStatusCmd.Flags().StringVarP(&flagVCSStatusEnvName, "environment", "e", "", "Name of the " + | ||
"environment to check the project(s) status") | ||
|
||
_ = VCSStatusCmd.MarkFlagRequired("environment") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
## apictl remove | ||
|
||
Remove an environmnet | ||
Remove an environment | ||
|
||
### Synopsis | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.