Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: commands to use machinery and clean up unused functions #321

Merged
merged 39 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b5e7ac6
First pass for deploy & list
CGoodwin90 Feb 29, 2024
ebd6518
Additional refactors & cleanup
CGoodwin90 Feb 29, 2024
3af6fe7
Additional refactors & cleanup
CGoodwin90 Mar 1, 2024
f4afad2
Updated deleteEnv to use machinery + legacy cleanup
CGoodwin90 Mar 4, 2024
a40bf92
Additional updates
CGoodwin90 Mar 5, 2024
0153e40
Committing notification progress
CGoodwin90 Mar 5, 2024
c8dff56
Additional refactors
CGoodwin90 Mar 14, 2024
9076804
Committing group progress
CGoodwin90 Mar 20, 2024
6bb4baa
Merged main & updated to use machinery
CGoodwin90 Mar 20, 2024
527564d
Merged main
CGoodwin90 Mar 20, 2024
ee386a9
Pointed to machinery
CGoodwin90 Mar 20, 2024
7e46651
Upated to fix test failure
CGoodwin90 Mar 20, 2024
6afe2e0
Updated go.sum
CGoodwin90 Mar 20, 2024
6b23dcc
Refactored addProjectToGroupCmd & addUserToGroupCmd
CGoodwin90 Mar 21, 2024
c9b5463
Updated group commands to use machinery
CGoodwin90 Mar 22, 2024
afc5e73
Updated & refactored all list commands
CGoodwin90 Mar 28, 2024
ff6ca5b
Merged main
CGoodwin90 Mar 28, 2024
2742303
Removed legacy test
CGoodwin90 Mar 28, 2024
0de92f8
Updated project commands
CGoodwin90 Apr 5, 2024
7a817d5
Refactored notifications + minor updates
CGoodwin90 Apr 9, 2024
ce0ad1b
Updated to machinery & refactored variables, tasks & users
CGoodwin90 Apr 10, 2024
2e7899f
Task refactor progress
CGoodwin90 Apr 12, 2024
ff369f5
Resolved conflicts
CGoodwin90 Apr 15, 2024
d828540
Includes input checks
CGoodwin90 Apr 19, 2024
4911690
Removed legacy funcs + cleanup
CGoodwin90 Apr 24, 2024
9a42ce5
Updated password reset to use machinery
CGoodwin90 May 2, 2024
a2c1905
Resolved conflicts
CGoodwin90 May 2, 2024
cd323a5
Updated to latest machinery
CGoodwin90 May 13, 2024
14ca824
Updated to accomodate null buildImage
CGoodwin90 May 13, 2024
3a4f8e7
Reverted error handling
CGoodwin90 May 21, 2024
2fe91c7
Merged main
CGoodwin90 Jun 11, 2024
8424baf
Cleaned up addProjec
CGoodwin90 Jun 11, 2024
0ef1975
Updated docs
CGoodwin90 Jun 11, 2024
7f6a57b
fix: render an empty data structure instead of a half populated one, …
shreddedbacon Jun 13, 2024
82f897e
chore: merge main and fix conflicts
shreddedbacon Jun 14, 2024
8eab507
chore: remove short import references for machinery
shreddedbacon Jun 14, 2024
cd4e346
chore: remove additional unused code and fix up some error handling
shreddedbacon Jun 17, 2024
f794793
chore: remove remaining legacy client and update tasks to use machinery
shreddedbacon Jun 17, 2024
1362e67
chore: remove more unused code
shreddedbacon Jun 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package cmd
import (
"context"
"fmt"
"strconv"

lclient "github.com/uselagoon/machinery/api/lagoon/client"

"github.com/spf13/cobra"
"github.com/uselagoon/lagoon-cli/internal/lagoon"
"github.com/uselagoon/lagoon-cli/internal/lagoon/client"
"github.com/uselagoon/lagoon-cli/internal/schema"
"github.com/uselagoon/machinery/api/lagoon"
"github.com/uselagoon/machinery/api/schema"
)

var deployCmd = &cobra.Command{
Expand Down Expand Up @@ -43,8 +45,8 @@ use 'lagoon deploy latest' instead`,
if err != nil {
return err
}
if cmdProjectName == "" || branch == "" {
return fmt.Errorf("missing arguments: Project name or branch name is not defined")
if err := requiredInputCheck("Project name", cmdProjectName, "Branch name", branch); err != nil {
return err
}

buildVarStrings, err := cmd.Flags().GetStringArray("buildvar")
Expand All @@ -58,11 +60,12 @@ use 'lagoon deploy latest' instead`,

if yesNo(fmt.Sprintf("You are attempting to deploy branch '%s' for project '%s', are you sure?", branch, cmdProjectName)) {
current := lagoonCLIConfig.Current
lc := client.New(
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[current].Version,
&token,
debug)
depBranch := &schema.DeployEnvironmentBranchInput{
Branch: branch,
Expand Down Expand Up @@ -108,8 +111,8 @@ var deployPromoteCmd = &cobra.Command{
if err != nil {
return err
}
if cmdProjectName == "" || sourceEnvironment == "" || destinationEnvironment == "" {
return fmt.Errorf("missing arguments: Project name, source environment, or destination environment is not defined")
if err := requiredInputCheck("Project name", cmdProjectName, "Source environment", sourceEnvironment, "Destination environment", destinationEnvironment); err != nil {
return err
}

buildVarStrings, err := cmd.Flags().GetStringArray("buildvar")
Expand All @@ -123,11 +126,12 @@ var deployPromoteCmd = &cobra.Command{

if yesNo(fmt.Sprintf("You are attempting to promote environment '%s' to '%s' for project '%s', are you sure?", sourceEnvironment, destinationEnvironment, cmdProjectName)) {
current := lagoonCLIConfig.Current
lc := client.New(
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[current].Version,
&token,
debug)
result, err := lagoon.DeployPromote(context.TODO(), &schema.DeployEnvironmentPromoteInput{
SourceEnvironment: sourceEnvironment,
Expand Down Expand Up @@ -170,21 +174,22 @@ This environment should already exist in lagoon. It is analogous with the 'Deplo
if err != nil {
return err
}
if err := requiredInputCheck("Project name", cmdProjectName, "Environment name", cmdProjectEnvironment); err != nil {
return err
}
buildVarMap, err := buildVarsToMap(buildVarStrings)
if err != nil {
return err
}

if cmdProjectName == "" || cmdProjectEnvironment == "" {
return fmt.Errorf("missing arguments: Project name or environment name is not defined")
}
if yesNo(fmt.Sprintf("You are attempting to deploy the latest environment '%s' for project '%s', are you sure?", cmdProjectEnvironment, cmdProjectName)) {
current := lagoonCLIConfig.Current
lc := client.New(
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[current].Version,
&token,
debug)
result, err := lagoon.DeployLatest(context.TODO(), &schema.DeployEnvironmentLatestInput{
Environment: schema.EnvironmentInput{
Expand Down Expand Up @@ -244,9 +249,8 @@ This pullrequest may not already exist as an environment in lagoon.`,
if err != nil {
return err
}
if cmdProjectName == "" || prTitle == "" || prNumber == 0 || baseBranchName == "" ||
baseBranchRef == "" || headBranchName == "" || headBranchRef == "" {
return fmt.Errorf("missing arguments: Project name, title, number, baseBranchName, baseBranchRef, headBranchName, or headBranchRef is not defined")
if err := requiredInputCheck("Project name", cmdProjectName, "Pullrequest title", prTitle, "Pullrequest number", strconv.Itoa(int(prNumber)), "baseBranchName", baseBranchName, "baseBranchRef", baseBranchRef, "headBranchName", headBranchName, "headBranchRef", headBranchRef); err != nil {
return err
}
buildVarStrings, err := cmd.Flags().GetStringArray("buildvar")
if err != nil {
Expand All @@ -263,11 +267,12 @@ This pullrequest may not already exist as an environment in lagoon.`,
}
if yesNo(fmt.Sprintf("You are attempting to deploy pull request '%v' for project '%s', are you sure?", prNumber, cmdProjectName)) {
current := lagoonCLIConfig.Current
lc := client.New(
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[current].Version,
&token,
debug)

result, err := lagoon.DeployPullRequest(context.TODO(), &schema.DeployEnvironmentPullrequestInput{
Expand Down
82 changes: 42 additions & 40 deletions cmd/deploytarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import (
"strconv"

"github.com/spf13/cobra"
"github.com/uselagoon/lagoon-cli/internal/lagoon"
"github.com/uselagoon/lagoon-cli/internal/lagoon/client"
"github.com/uselagoon/lagoon-cli/internal/schema"
"github.com/uselagoon/lagoon-cli/pkg/output"
l "github.com/uselagoon/machinery/api/lagoon"
"github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
s "github.com/uselagoon/machinery/api/schema"
"github.com/uselagoon/machinery/api/schema"
)

var addDeployTargetCmd = &cobra.Command{
Expand Down Expand Up @@ -65,14 +62,8 @@ var addDeployTargetCmd = &cobra.Command{
return err
}

if name == "" {
return fmt.Errorf("missing arguments: name is not defined")
}
if token == "" {
return fmt.Errorf("missing arguments: token is not defined")
}
if consoleURL == "" {
return fmt.Errorf("missing arguments: console-url is not defined")
if err := requiredInputCheck("Name", name, "Token", token, "Console-url", consoleURL); err != nil {
return err
}

addDeployTarget := &schema.AddDeployTargetInput{
Expand All @@ -96,20 +87,21 @@ var addDeployTargetCmd = &cobra.Command{
}
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
handleError(err)
return err
}
current := lagoonCLIConfig.Current
lc := client.New(
lagoonToken := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[current].Version,
&lagoonToken,
debug)

if yesNo(fmt.Sprintf("You are attempting to add '%s' DeployTarget, are you sure?", addDeployTarget.Name)) {
addDeployTargetResponse, err := lagoon.AddDeployTarget(context.TODO(), addDeployTarget, lc)
if err != nil {
handleError(err)
return err
}

data := []output.Data{}
Expand Down Expand Up @@ -208,16 +200,22 @@ var updateDeployTargetCmd = &cobra.Command{

debug, err := cmd.Flags().GetBool("debug")
if err != nil {
handleError(err)
return err
}

if err := requiredInputCheck("Deploytarget ID", strconv.Itoa(int(id))); err != nil {
return err
}

current := lagoonCLIConfig.Current
lc := client.New(
lagoonToken := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
debug,
)
lagoonCLIConfig.Lagoons[current].Version,
&lagoonToken,
debug)

updateDeployTarget := &schema.UpdateDeployTargetInput{
AddDeployTargetInput: schema.AddDeployTargetInput{
ID: id,
Expand All @@ -235,7 +233,7 @@ var updateDeployTargetCmd = &cobra.Command{
if yesNo(fmt.Sprintf("You are attempting to update '%d' DeployTarget, are you sure?", updateDeployTarget.ID)) {
updateDeployTargetResponse, err := lagoon.UpdateDeployTarget(context.TODO(), updateDeployTarget, lc)
if err != nil {
handleError(err)
return err
}

data := []output.Data{}
Expand Down Expand Up @@ -293,27 +291,31 @@ var deleteDeployTargetCmd = &cobra.Command{

debug, err := cmd.Flags().GetBool("debug")
if err != nil {
handleError(err)
return err
}

if err := requiredInputCheck("Deploytarget name", name); err != nil {
return err
}

current := lagoonCLIConfig.Current
lc := client.New(
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
debug,
)
lagoonCLIConfig.Lagoons[current].Version,
&token,
debug)

deleteDeployTarget := &schema.DeleteDeployTargetInput{
Name: name,
}
if yesNo(fmt.Sprintf("You are attempting to delete DeployTarget '%s', are you sure?", deleteDeployTarget.Name)) {
deleteDeployTargetResponse, err := lagoon.DeleteDeployTarget(context.TODO(), deleteDeployTarget, lc)
if err != nil {
handleError(err)
return err
}

handleError(err)
resultData := output.Result{
Result: deleteDeployTargetResponse.DeleteDeployTarget,
}
Expand Down Expand Up @@ -347,7 +349,6 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{
if err := requiredInputCheck("Organization name", organizationName, "Deploy Target", strconv.Itoa(int(deploytarget))); err != nil {
return err
}

current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
Expand All @@ -357,23 +358,24 @@ var addDeployTargetToOrganizationCmd = &cobra.Command{
&token,
debug)

organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
organization, err := lagoon.GetOrganizationByName(context.TODO(), organizationName, lc)
if err != nil {
return err
}
if organization.Name == "" {
return fmt.Errorf("error querying organization by name")
}

deployTargetInput := s.AddDeployTargetToOrganizationInput{
deployTargetInput := schema.AddDeployTargetToOrganizationInput{
DeployTarget: deploytarget,
Organization: organization.ID,
}

deployTargetResponse, err := l.AddDeployTargetToOrganization(context.TODO(), &deployTargetInput, lc)
deployTargetResponse, err := lagoon.AddDeployTargetToOrganization(context.TODO(), &deployTargetInput, lc)
if err != nil {
return err
}

resultData := output.Result{
Result: "success",
ResultData: map[string]interface{}{
Expand Down Expand Up @@ -420,21 +422,21 @@ var removeDeployTargetFromOrganizationCmd = &cobra.Command{
&token,
debug)

organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
organization, err := lagoon.GetOrganizationByName(context.TODO(), organizationName, lc)
if err != nil {
return err
}
if organization.Name == "" {
return fmt.Errorf("error querying organization by name")
}

deployTargetInput := s.RemoveDeployTargetFromOrganizationInput{
deployTargetInput := schema.RemoveDeployTargetFromOrganizationInput{
DeployTarget: deploytarget,
Organization: organization.ID,
}

if yesNo(fmt.Sprintf("You are attempting to remove deploy target '%d' from organization '%s', are you sure?", deploytarget, organization.Name)) {
_, err := l.RemoveDeployTargetFromOrganization(context.TODO(), &deployTargetInput, lc)
_, err := lagoon.RemoveDeployTargetFromOrganization(context.TODO(), &deployTargetInput, lc)
if err != nil {
return err
}
Expand Down
Loading
Loading