Skip to content

Commit

Permalink
Additional verification & output updates
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 authored and shreddedbacon committed Aug 11, 2024
1 parent 6516e2b commit 720c63a
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 123 deletions.
11 changes: 3 additions & 8 deletions cmd/deploytargetconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ var deleteDeployTargetConfigCmd = &cobra.Command{
return err
}
if project.Name == "" {
outputOptions.Error = fmt.Sprintf("No details for project '%s'\n", cmdProjectName)
output.RenderError(outputOptions.Error, outputOptions)
return nil
return handleNilResults("Project '%s' not found\n", cmd, cmdProjectName)
}

if yesNo(fmt.Sprintf("You are attempting to delete deploytarget configuration with id '%d' from project '%s', are you sure?", id, cmdProjectName)) {
Expand Down Expand Up @@ -291,17 +289,14 @@ var listDeployTargetConfigsCmd = &cobra.Command{
return err
}
if project.Name == "" {
outputOptions.Error = fmt.Sprintf("No details for project '%s'\n", cmdProjectName)
output.RenderError(outputOptions.Error, outputOptions)
return nil
return handleNilResults("Project '%s' not found\n", cmd, cmdProjectName)
}
deployTargetConfigs, err := lagoon.GetDeployTargetConfigs(context.TODO(), int(project.ID), lc)
if err != nil {
return err
}
if len(*deployTargetConfigs) == 0 {
handleNilResults("No deploytarget-configs for project '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("No deploytarget-configs for project '%s'\n", cmd, cmdProjectName)
}
data := []output.Data{}
for _, deployTargetConfig := range *deployTargetConfigs {
Expand Down
3 changes: 1 addition & 2 deletions cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ var listBackupsCmd = &cobra.Command{
return err
}
if project.Name == "" {
handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
}
backupsResult, err := lagoon.GetBackupsForEnvironmentByName(context.TODO(), cmdProjectEnvironment, project.ID, lc)
if err != nil {
Expand Down
20 changes: 8 additions & 12 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ var getProjectCmd = &cobra.Command{
}

if project.Name == "" {
handleNilResults("No details for project '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("No details for project '%s'\n", cmd, cmdProjectName)
}

devEnvironments := 0
Expand Down Expand Up @@ -251,11 +250,10 @@ var getEnvironmentCmd = &cobra.Command{

if project.Name == "" || environment.Name == "" {
if project.Name == "" {
handleNilResults("Project '%s' not found\n", cmd, cmdProjectName)
return handleNilResults("Project '%s' not found\n", cmd, cmdProjectName)
} else {
handleNilResults("Environment '%s' not found in project '%s'\n", cmd, cmdProjectEnvironment, cmdProjectName)
return handleNilResults("Environment '%s' not found in project '%s'\n", cmd, cmdProjectEnvironment, cmdProjectName)
}
return nil
}

data := []output.Data{}
Expand Down Expand Up @@ -329,17 +327,15 @@ var getProjectKeyCmd = &cobra.Command{
return err
}
if project.Name == "" {
handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
}

projectKey, err := lagoon.GetProjectKeyByName(context.TODO(), cmdProjectName, revealValue, lc)
if err != nil {
return err
}
if projectKey.PublicKey == "" && projectKey.PrivateKey == "" {
handleNilResults("No project-key for project '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("No project-key for project '%s'\n", cmd, cmdProjectName)
}

projectKeys := []string{projectKey.PublicKey}
Expand Down Expand Up @@ -420,9 +416,9 @@ var getOrganizationCmd = &cobra.Command{
strconv.Itoa(int(organization.ID)),
organization.Name,
organization.Description,
strconv.Itoa(int(organization.QuotaProject)),
strconv.Itoa(int(organization.QuotaGroup)),
strconv.Itoa(int(organization.QuotaNotification)),
strconv.Itoa(organization.QuotaProject),
strconv.Itoa(organization.QuotaGroup),
strconv.Itoa(organization.QuotaNotification),
})

dataMain := output.Table{
Expand Down
8 changes: 2 additions & 6 deletions cmd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ var addProjectToGroupCmd = &cobra.Command{
return err
}
if len(project.Name) == 0 {
outputOptions.Error = fmt.Sprintf("Project '%s' not found\n", cmdProjectName)
output.RenderError(outputOptions.Error, outputOptions)
return nil
return handleNilResults("Project '%s' not found\n", cmd, cmdProjectName)
}
_, err = lagoon.AddProjectToGroup(context.TODO(), projectGroup, lc)
if err != nil {
Expand Down Expand Up @@ -335,9 +333,7 @@ var deleteProjectFromGroupCmd = &cobra.Command{
return err
}
if len(project.Name) == 0 {
outputOptions.Error = fmt.Sprintf("Project '%s' not found\n", cmdProjectName)
output.RenderError(outputOptions.Error, outputOptions)
return nil
return handleNilResults("Project '%s' not found\n", cmd, cmdProjectName)
}

if yesNo(fmt.Sprintf("You are attempting to delete project '%s' from group '%s', are you sure?", projectGroup.Project.Name, projectGroup.Groups[0].Name)) {
Expand Down
50 changes: 18 additions & 32 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var listProjectsCmd = &cobra.Command{
data = append(data, projData)
}
if len(data) == 0 {
outputOptions.Error = "No access to any projects in Lagoon\n"
return handleNilResults("No access to any projects in Lagoon\n", cmd)
}
projHeader := []string{"ID", "ProjectName", "GitUrl", "ProductionEnvironment", "ProductionRoute", "DevEnvironments"}
// if wide {
Expand Down Expand Up @@ -234,7 +234,7 @@ var listGroupsCmd = &cobra.Command{
})
}
if len(data) == 0 {
outputOptions.Error = "This account is not in any groups\n"
return handleNilResults("This account is not in any groups\n", cmd)
}
dataMain := output.Table{
Header: []string{"ID", "Name"},
Expand Down Expand Up @@ -311,11 +311,10 @@ var listGroupProjectsCmd = &cobra.Command{
}
if len(data) == 0 {
if !listAllProjects {
handleNilResults("There are no projects in group '%s'\n", cmd, groupName)
return handleNilResults("There are no projects in group '%s'\n", cmd, groupName)
} else {
handleNilResults("There are no projects in any groups\n", cmd)
return handleNilResults("There are no projects in any groups\n", cmd)
}
return nil
}

dataMain := output.Table{
Expand Down Expand Up @@ -361,8 +360,7 @@ var listEnvironmentsCmd = &cobra.Command{
}

if len(*environments) == 0 {
handleNilResults("No environments found for project '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("No environments found for project '%s'\n", cmd, cmdProjectName)
}

data := []output.Data{}
Expand Down Expand Up @@ -457,11 +455,10 @@ var listVariablesCmd = &cobra.Command{
}
if len(data) == 0 {
if cmdProjectEnvironment != "" {
handleNilResults("There are no variables for environment '%s' in project '%s'\n", cmd, cmdProjectEnvironment, cmdProjectName)
return handleNilResults("There are no variables for environment '%s' in project '%s'\n", cmd, cmdProjectEnvironment, cmdProjectName)
} else {
handleNilResults("There are no variables for project '%s'\n", cmd, cmdProjectName)
return handleNilResults("There are no variables for project '%s'\n", cmd, cmdProjectName)
}
return nil
}
r := output.RenderOutput(output.Table{
Header: header,
Expand Down Expand Up @@ -502,8 +499,7 @@ var listDeploymentsCmd = &cobra.Command{
return err
}
if project.Name == "" {
handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
}

deployments, err := lagoon.GetDeploymentsByEnvironment(context.TODO(), project.ID, cmdProjectEnvironment, lc)
Expand All @@ -525,8 +521,7 @@ var listDeploymentsCmd = &cobra.Command{
}

if len(data) == 0 {
handleNilResults("There are no deployments for environment '%s' in project '%s'\n", cmd, cmdProjectEnvironment, cmdProjectName)
return nil
return handleNilResults("There are no deployments for environment '%s' in project '%s'\n", cmd, cmdProjectEnvironment, cmdProjectName)
}
dataMain := output.Table{
Header: []string{"ID", "RemoteID", "Name", "Status", "Created", "Started", "Completed"},
Expand Down Expand Up @@ -568,8 +563,7 @@ var listTasksCmd = &cobra.Command{
return err
}
if project.Name == "" {
handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
}

tasks, err := lagoon.GetTasksByEnvironment(context.TODO(), project.ID, cmdProjectEnvironment, lc)
Expand All @@ -592,8 +586,7 @@ var listTasksCmd = &cobra.Command{
}

if len(data) == 0 {
handleNilResults("There are no tasks for environment '%s' in project '%s'\n", cmd, cmdProjectEnvironment, cmdProjectName)
return nil
return handleNilResults("There are no tasks for environment '%s' in project '%s'\n", cmd, cmdProjectEnvironment, cmdProjectName)
}
dataMain := output.Table{
Header: []string{"ID", "RemoteID", "Name", "Status", "Created", "Started", "Completed", "Service"},
Expand Down Expand Up @@ -808,8 +801,7 @@ var listInvokableTasks = &cobra.Command{
return err
}
if project.Name == "" {
handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
}
tasks, err := lagoon.GetInvokableAdvancedTaskDefinitionsByEnvironment(context.TODO(), project.ID, cmdProjectEnvironment, lc)
if err != nil {
Expand All @@ -825,8 +817,7 @@ var listInvokableTasks = &cobra.Command{
}

if len(data) == 0 {
handleNilResults("There are no user defined tasks for environment %s\n", cmd, cmdProjectEnvironment)
return nil
return handleNilResults("There are no user defined tasks for environment %s\n", cmd, cmdProjectEnvironment)
}
dataMain := output.Table{
Header: []string{"Task Name", "Description"},
Expand Down Expand Up @@ -877,8 +868,7 @@ var listProjectGroupsCmd = &cobra.Command{
}

if len(projectGroups.Groups) == 0 {
handleNilResults("There are no groups for project '%s'\n", cmd, cmdProjectName)
return nil
return handleNilResults("There are no groups for project '%s'\n", cmd, cmdProjectName)
}

data := []output.Data{}
Expand Down Expand Up @@ -945,8 +935,7 @@ var listOrganizationProjectsCmd = &cobra.Command{
}

if len(*orgProjects) == 0 {
handleNilResults("No associated projects found for organization '%s'\n", cmd, organizationName)
return nil
return handleNilResults("No associated projects found for organization '%s'\n", cmd, organizationName)
}

data := []output.Data{}
Expand Down Expand Up @@ -1008,8 +997,7 @@ var listOrganizationGroupsCmd = &cobra.Command{
return err
}
if len(*orgGroups) == 0 {
handleNilResults("No associated groups found for organization '%s'\n", cmd, organizationName)
return nil
return handleNilResults("No associated groups found for organization '%s'\n", cmd, organizationName)
}

data := []output.Data{}
Expand Down Expand Up @@ -1068,8 +1056,7 @@ var listOrganizationDeployTargetsCmd = &cobra.Command{
return err
}
if len(*deployTargets) == 0 {
handleNilResults("No associated deploy targets found for organization '%s'\n", cmd, organizationName)
return nil
return handleNilResults("No associated deploy targets found for organization '%s'\n", cmd, organizationName)
}

data := []output.Data{}
Expand Down Expand Up @@ -1180,8 +1167,7 @@ var listOrganizationAdminsCmd = &cobra.Command{
return err
}
if len(*users) == 0 {
handleNilResults("No associated users found for organization '%s'\n", cmd, organizationName)
return nil
return handleNilResults("No associated users found for organization '%s'\n", cmd, organizationName)
}
data := []output.Data{}
for _, user := range *users {
Expand Down
30 changes: 20 additions & 10 deletions cmd/notificationsemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ var listProjectEmailsCmd = &cobra.Command{
return err
}
if len(result.Name) == 0 {
outputOptions.Error = fmt.Sprintf("No project found for '%s'\n", cmdProjectName)
return handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
} else if len(result.Notifications.Email) == 0 {
outputOptions.Error = fmt.Sprintf("No email notificatons found for project: '%s'\n", cmdProjectName)
return handleNilResults("No email notificatons found for project: '%s'\n", cmd, cmdProjectName)
}

data := []output.Data{}
Expand Down Expand Up @@ -268,15 +268,24 @@ var deleteProjectEmailNotificationCmd = &cobra.Command{
if err := requiredInputCheck("Project name", cmdProjectName, "Notification name", name); err != nil {
return err
}

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

project, err := lagoon.GetProjectByName(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
if project.Name == "" {
return handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
}
if yesNo(fmt.Sprintf("You are attempting to delete email notification '%s' from project '%s', are you sure?", name, cmdProjectName)) {
current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[current].Version,
&token,
debug)
notification := &schema.RemoveNotificationFromProjectInput{
NotificationType: schema.EmailNotification,
NotificationName: name,
Expand Down Expand Up @@ -315,6 +324,7 @@ var deleteEmailNotificationCmd = &cobra.Command{
if err := requiredInputCheck("Notification name", name); err != nil {
return err
}
// Todo: Verify notifcation name exists - requires #PR https://github.com/uselagoon/lagoon/pull/3740
if yesNo(fmt.Sprintf("You are attempting to delete email notification '%s', are you sure?", name)) {
current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
Expand Down
31 changes: 21 additions & 10 deletions cmd/notificationsrocketchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ var listProjectRocketChatsCmd = &cobra.Command{
return err
}
if len(result.Name) == 0 {
outputOptions.Error = fmt.Sprintf("No project found for '%s'\n", cmdProjectName)
return handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
} else if len(result.Notifications.RocketChat) == 0 {
outputOptions.Error = fmt.Sprintf("No rocketchat notificatons found for project: '%s'\n", cmdProjectName)
return handleNilResults("No RocketChat notifications found for project '%s'\n", cmd, cmdProjectName)
}

data := []output.Data{}
Expand Down Expand Up @@ -281,15 +281,25 @@ var deleteProjectRocketChatNotificationCmd = &cobra.Command{
if err := requiredInputCheck("Project name", cmdProjectName, "Notification name", name); err != nil {
return err
}

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

project, err := lagoon.GetProjectByName(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
if project.Name == "" {
return handleNilResults("No project found for '%s'\n", cmd, cmdProjectName)
}

if yesNo(fmt.Sprintf("You are attempting to delete RocketChat notification '%s' from project '%s', are you sure?", name, cmdProjectName)) {
current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[current].Version,
&token,
debug)
notification := &schema.RemoveNotificationFromProjectInput{
NotificationType: schema.RocketChatNotification,
NotificationName: name,
Expand Down Expand Up @@ -328,6 +338,7 @@ var deleteRocketChatNotificationCmd = &cobra.Command{
if err := requiredInputCheck("Notification name", name); err != nil {
return err
}
// Todo: Verify notifcation name exists - requires #PR https://github.com/uselagoon/lagoon/pull/3740
if yesNo(fmt.Sprintf("You are attempting to delete RocketChat notification '%s', are you sure?", name)) {
current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
Expand Down
Loading

0 comments on commit 720c63a

Please sign in to comment.