-
Notifications
You must be signed in to change notification settings - Fork 4
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 #49 from seungkyua/20230426_rollback
add rollback
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package commands | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
_apiClient "github.com/openinfradev/tks-api/pkg/api-client" | ||
"github.com/openinfradev/tks-client/internal/helper" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type rollback struct { | ||
TaskId string `yaml:"task_id" json:"taskId"` | ||
} | ||
|
||
func NewAppserveRollbackCmd(globalOpts *GlobalOptions) *cobra.Command { | ||
var ( | ||
organizationId string | ||
appId string | ||
) | ||
var command = &cobra.Command{ | ||
Use: "rollback", | ||
Short: "Rollback an app to revision", | ||
Long: `Rollback an app to revision. | ||
Example: | ||
tks appserve rollback <TASK_ID> --organization-id <ORG_ID> --app-id <APP_ID>`, | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
taskId := args[0] | ||
if len(taskId) < 1 { | ||
return errors.New("TASK_ID is mandatory! Run 'tks appserve rollback --help'") | ||
} | ||
|
||
if organizationId == "" { | ||
return errors.New("--organization-id is mandatory param") | ||
} | ||
if appId == "" { | ||
return errors.New("--app-id is mandatory param") | ||
} | ||
|
||
apiClient, err := _apiClient.New(globalOpts.ServerAddr, globalOpts.AuthToken) | ||
helper.CheckError(err) | ||
|
||
url := fmt.Sprintf("organizations/%v/app-serve-apps/%v/rollback", organizationId, appId) | ||
params := rollback{TaskId: taskId} | ||
|
||
body, err := apiClient.Post(url, params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Response: %T Type\n %v\n", body, fmt.Sprintf("%v", body)) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
command.Flags().StringVar(&organizationId, "organization-id", "", "a organizationId") | ||
command.Flags().StringVar(&appId, "app-id", "", "a appId") | ||
|
||
return command | ||
} |
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