From 103bc025dd243e64ef443676909f1ff983a3470f Mon Sep 17 00:00:00 2001 From: Pierre Gerbelot Date: Mon, 11 Dec 2023 14:57:21 +0100 Subject: [PATCH] feat: adapt to last qovery api (job response and clone request) --- cmd/application_clone.go | 4 +- cmd/container_clone.go | 4 +- cmd/cronjob.go | 5 +- cmd/cronjob_cancel.go | 4 +- cmd/cronjob_clone.go | 10 +- cmd/cronjob_delete.go | 4 +- cmd/cronjob_deploy.go | 14 +- cmd/cronjob_env_alias_create.go | 4 +- cmd/cronjob_env_create.go | 6 +- cmd/cronjob_env_delete.go | 4 +- cmd/cronjob_env_list.go | 6 +- cmd/cronjob_env_override_create.go | 4 +- cmd/cronjob_list.go | 16 ++- cmd/cronjob_redeploy.go | 4 +- cmd/cronjob_stop.go | 6 +- cmd/cronjob_update.go | 14 +- cmd/environment_clone.go | 4 +- cmd/environment_stage_move.go | 2 +- cmd/lifecycle.go | 11 +- cmd/lifecycle_cancel.go | 4 +- cmd/lifecycle_clone.go | 10 +- cmd/lifecycle_delete.go | 6 +- cmd/lifecycle_deploy.go | 14 +- cmd/lifecycle_env_alias_create.go | 4 +- cmd/lifecycle_env_create.go | 6 +- cmd/lifecycle_env_delete.go | 4 +- cmd/lifecycle_env_list.go | 6 +- cmd/lifecycle_env_override_create.go | 4 +- cmd/lifecycle_list.go | 16 ++- cmd/lifecycle_redeploy.go | 4 +- cmd/lifecycle_stop.go | 6 +- cmd/lifecycle_update.go | 14 +- cmd/service_list.go | 18 +-- go.mod | 2 +- go.sum | 2 + utils/qovery.go | 196 ++++++++++++++++++--------- 36 files changed, 253 insertions(+), 189 deletions(-) diff --git a/cmd/application_clone.go b/cmd/application_clone.go index 8042c4ed..64b1330f 100644 --- a/cmd/application_clone.go +++ b/cmd/application_clone.go @@ -73,12 +73,12 @@ var applicationCloneCmd = &cobra.Command{ targetApplicationName = application.Name } - req := qovery.CloneApplicationRequest{ + req := qovery.CloneServiceRequest{ Name: targetApplicationName, EnvironmentId: targetEnvironmentId, } - clonedService, res, err := client.ApplicationsAPI.CloneApplication(context.Background(), application.Id).CloneApplicationRequest(req).Execute() + clonedService, res, err := client.ApplicationsAPI.CloneApplication(context.Background(), application.Id).CloneServiceRequest(req).Execute() if err != nil { // print http body error message diff --git a/cmd/container_clone.go b/cmd/container_clone.go index 93d3b618..5e050f17 100644 --- a/cmd/container_clone.go +++ b/cmd/container_clone.go @@ -73,12 +73,12 @@ var containerCloneCmd = &cobra.Command{ targetContainerName = container.Name } - req := qovery.CloneContainerRequest{ + req := qovery.CloneServiceRequest{ Name: targetContainerName, EnvironmentId: targetEnvironmentId, } - clonedService, res, err := client.ContainersAPI.CloneContainer(context.Background(), container.Id).CloneContainerRequest(req).Execute() + clonedService, res, err := client.ContainersAPI.CloneContainer(context.Background(), container.Id).CloneServiceRequest(req).Execute() if err != nil { // print http body error message diff --git a/cmd/cronjob.go b/cmd/cronjob.go index fe916894..6253f8dd 100644 --- a/cmd/cronjob.go +++ b/cmd/cronjob.go @@ -45,10 +45,7 @@ func ListCronjobs(envId string, client *qovery.APIClient) ([]qovery.JobResponse, cronjobs := make([]qovery.JobResponse, 0) for _, job := range jobs.GetResults() { - schedule := job.GetSchedule() - cronjob, _ := schedule.GetCronjobOk() - - if cronjob != nil && cronjob.ScheduledAt != "" { + if job.CronJobResponse != nil { cronjobs = append(cronjobs, job) } } diff --git a/cmd/cronjob_cancel.go b/cmd/cronjob_cancel.go index e8fb1682..2d89e585 100644 --- a/cmd/cronjob_cancel.go +++ b/cmd/cronjob_cancel.go @@ -41,14 +41,14 @@ var cronjobCancelCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs.GetResults(), cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - msg, err := utils.CancelServiceDeployment(client, envId, cronjob.Id, utils.JobType, watchFlag) + msg, err := utils.CancelServiceDeployment(client, envId, cronjob.CronJobResponse.Id , utils.JobType, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/cronjob_clone.go b/cmd/cronjob_clone.go index 6126af1f..59d99ac7 100644 --- a/cmd/cronjob_clone.go +++ b/cmd/cronjob_clone.go @@ -37,7 +37,7 @@ var cronjobCloneCmd = &cobra.Command{ job, err := getJobContextResource(client, cronjobName, envId) - if err != nil { + if err != nil || job == nil || job.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjobName %s not found", cronjobName)) utils.PrintlnInfo("You can list all jobs with: qovery job list") os.Exit(1) @@ -70,15 +70,15 @@ var cronjobCloneCmd = &cobra.Command{ if targetCronjobName == "" { // use same job name as the source job - targetCronjobName = job.Name + targetCronjobName = job.CronJobResponse.Name } - req := qovery.CloneJobRequest{ + req := qovery.CloneServiceRequest{ Name: targetCronjobName, EnvironmentId: targetEnvironmentId, } - clonedService, res, err := client.JobsAPI.CloneJob(context.Background(), job.Id).CloneJobRequest(req).Execute() + clonedService, res, err := client.JobsAPI.CloneJob(context.Background(), job.CronJobResponse.Id).CloneServiceRequest(req).Execute() if err != nil { // print http body error message @@ -94,7 +94,7 @@ var cronjobCloneCmd = &cobra.Command{ name := "" if clonedService != nil { - name = clonedService.Name + name = clonedService.CronJobResponse.Name } utils.Println(fmt.Sprintf("Job %s cloned!", pterm.FgBlue.Sprintf(name))) diff --git a/cmd/cronjob_delete.go b/cmd/cronjob_delete.go index 518424f6..61bdf97c 100644 --- a/cmd/cronjob_delete.go +++ b/cmd/cronjob_delete.go @@ -69,7 +69,7 @@ var cronjobDeleteCmd = &cobra.Command{ var serviceIds []string for _, cronjobName := range strings.Split(cronjobNames, ",") { trimmedCronjobName := strings.TrimSpace(cronjobName) - serviceIds = append(serviceIds, utils.FindByJobName(cronjobs, trimmedCronjobName).Id) + serviceIds = append(serviceIds, utils.GetJobId(utils.FindByJobName(cronjobs, trimmedCronjobName))) } _, err = utils.DeleteServices(client, envId, serviceIds, utils.JobType) @@ -106,7 +106,7 @@ var cronjobDeleteCmd = &cobra.Command{ panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - msg, err := utils.DeleteService(client, envId, job.Id, utils.JobType, watchFlag) + msg, err := utils.DeleteService(client, envId, utils.GetJobId(job), utils.JobType, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/cronjob_deploy.go b/cmd/cronjob_deploy.go index a38897a1..c9ba903b 100644 --- a/cmd/cronjob_deploy.go +++ b/cmd/cronjob_deploy.go @@ -92,21 +92,21 @@ var cronjobDeployCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs, cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - var docker *qovery.JobResponseAllOfSourceOneOf1Docker = nil - if cronjob.Source.JobResponseAllOfSourceOneOf1 != nil { - docker = cronjob.Source.JobResponseAllOfSourceOneOf1.Docker + var docker *qovery.BaseJobResponseAllOfSourceOneOf1Docker = nil + if cronjob.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf1 != nil { + docker = cronjob.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf1.Docker } var image *qovery.ContainerSource = nil - if cronjob.Source.JobResponseAllOfSourceOneOf != nil { - image = cronjob.Source.JobResponseAllOfSourceOneOf.Image + if cronjob.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf != nil { + image = cronjob.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf.Image } var req qovery.JobDeployRequest @@ -129,7 +129,7 @@ var cronjobDeployCmd = &cobra.Command{ } } - msg, err := utils.DeployService(client, envId, cronjob.Id, utils.JobType, req, watchFlag) + msg, err := utils.DeployService(client, envId, cronjob.CronJobResponse.Id, utils.JobType, req, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/cronjob_env_alias_create.go b/cmd/cronjob_env_alias_create.go index 711a662c..6cd9050a 100644 --- a/cmd/cronjob_env_alias_create.go +++ b/cmd/cronjob_env_alias_create.go @@ -42,14 +42,14 @@ var cronjobEnvAliasCreateCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs.GetResults(), cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - err = utils.CreateAlias(client, projectId, envId, cronjob.Id, utils.JobType, utils.Key, utils.Alias, utils.JobScope) + err = utils.CreateAlias(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobType, utils.Key, utils.Alias, utils.JobScope) if err != nil { utils.PrintlnError(err) diff --git a/cmd/cronjob_env_create.go b/cmd/cronjob_env_create.go index 4fbfdff0..9e5bd334 100644 --- a/cmd/cronjob_env_create.go +++ b/cmd/cronjob_env_create.go @@ -42,7 +42,7 @@ var cronjobEnvCreateCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs.GetResults(), cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) @@ -50,7 +50,7 @@ var cronjobEnvCreateCmd = &cobra.Command{ } if utils.IsSecret { - err = utils.CreateSecret(client, projectId, envId, cronjob.Id, utils.Key, utils.Value, utils.JobScope) + err = utils.CreateSecret(client, projectId, envId, cronjob.CronJobResponse.Id, utils.Key, utils.Value, utils.JobScope) if err != nil { utils.PrintlnError(err) @@ -62,7 +62,7 @@ var cronjobEnvCreateCmd = &cobra.Command{ return } - err = utils.CreateEnvironmentVariable(client, projectId, envId, cronjob.Id, utils.Key, utils.Value, utils.JobScope) + err = utils.CreateEnvironmentVariable(client, projectId, envId, cronjob.CronJobResponse.Id, utils.Key, utils.Value, utils.JobScope) if err != nil { utils.PrintlnError(err) diff --git a/cmd/cronjob_env_delete.go b/cmd/cronjob_env_delete.go index 5d6f33b0..268e049a 100644 --- a/cmd/cronjob_env_delete.go +++ b/cmd/cronjob_env_delete.go @@ -42,14 +42,14 @@ var cronjobEnvDeleteCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs.GetResults(), cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - err = utils.DeleteByKey(client, projectId, envId, cronjob.Id, utils.JobType, utils.Key) + err = utils.DeleteByKey(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobType, utils.Key) if err != nil { utils.PrintlnError(err) diff --git a/cmd/cronjob_env_list.go b/cmd/cronjob_env_list.go index 772a6309..3c5c69dd 100644 --- a/cmd/cronjob_env_list.go +++ b/cmd/cronjob_env_list.go @@ -42,7 +42,7 @@ var cronjobEnvListCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs.GetResults(), cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) @@ -51,7 +51,7 @@ var cronjobEnvListCmd = &cobra.Command{ envVars, _, err := client.JobEnvironmentVariableAPI.ListJobEnvironmentVariable( context.Background(), - cronjob.Id, + cronjob.CronJobResponse.Id, ).Execute() if err != nil { @@ -62,7 +62,7 @@ var cronjobEnvListCmd = &cobra.Command{ secrets, _, err := client.JobSecretAPI.ListJobSecrets( context.Background(), - cronjob.Id, + cronjob.CronJobResponse.Id, ).Execute() if err != nil { diff --git a/cmd/cronjob_env_override_create.go b/cmd/cronjob_env_override_create.go index 0c466904..f8cdcc2f 100644 --- a/cmd/cronjob_env_override_create.go +++ b/cmd/cronjob_env_override_create.go @@ -42,14 +42,14 @@ var cronjobEnvOverrideCreateCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs.GetResults(), cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - err = utils.CreateOverride(client, projectId, envId, cronjob.Id, utils.JobType, utils.Key, &utils.Value, utils.JobScope) + err = utils.CreateOverride(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobType, utils.Key, &utils.Value, utils.JobScope) if err != nil { utils.PrintlnError(err) diff --git a/cmd/cronjob_list.go b/cmd/cronjob_list.go index 82b191ef..040e6cc1 100644 --- a/cmd/cronjob_list.go +++ b/cmd/cronjob_list.go @@ -57,8 +57,10 @@ var cronjobListCmd = &cobra.Command{ var data [][]string for _, cronjob := range cronjobs { - data = append(data, []string{cronjob.Id, cronjob.Name, "Cronjob", - utils.FindStatusTextWithColor(statuses.GetJobs(), cronjob.Id), cronjob.UpdatedAt.String()}) + if cronjob.CronJobResponse != nil { + data = append(data, []string{cronjob.CronJobResponse.Id, cronjob.CronJobResponse.Name, "Cronjob", + utils.FindStatusTextWithColor(statuses.GetJobs(), cronjob.CronJobResponse.Id), cronjob.CronJobResponse.UpdatedAt.String()}) + } } err = utils.PrintTable([]string{"Id", "Name", "Type", "Status", "Last Update"}, data) @@ -75,13 +77,13 @@ func getCronjobJsonOutput(statuses []qovery.Status, cronjobs []qovery.JobRespons var results []interface{} for _, cronjob := range cronjobs { - if cronjob.Schedule.Cronjob != nil { + if cronjob.CronJobResponse.Schedule.Cronjob != nil { results = append(results, map[string]interface{}{ - "id": cronjob.Id, - "name": cronjob.Name, + "id": cronjob.CronJobResponse.Id, + "name": cronjob.CronJobResponse.Name, "type": "Cronjob", - "status": utils.FindStatus(statuses, cronjob.Id), - "updated_at": utils.ToIso8601(cronjob.UpdatedAt), + "status": utils.FindStatus(statuses, cronjob.CronJobResponse.Id), + "updated_at": utils.ToIso8601(cronjob.CronJobResponse.UpdatedAt), }) } } diff --git a/cmd/cronjob_redeploy.go b/cmd/cronjob_redeploy.go index 7874faca..0a271f5f 100644 --- a/cmd/cronjob_redeploy.go +++ b/cmd/cronjob_redeploy.go @@ -41,14 +41,14 @@ var cronjobRedeployCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs, cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - msg, err := utils.RedeployService(client, envId, cronjob.Id, utils.JobType, watchFlag) + msg, err := utils.RedeployService(client, envId, cronjob.CronJobResponse.Id, utils.JobType, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/cronjob_stop.go b/cmd/cronjob_stop.go index e1efee0b..9efd2047 100644 --- a/cmd/cronjob_stop.go +++ b/cmd/cronjob_stop.go @@ -69,7 +69,7 @@ var cronjobStopCmd = &cobra.Command{ var serviceIds []string for _, cronjobName := range strings.Split(cronjobNames, ",") { trimmedCronjobName := strings.TrimSpace(cronjobName) - serviceIds = append(serviceIds, utils.FindByJobName(cronjobs, trimmedCronjobName).Id) + serviceIds = append(serviceIds, utils.FindByJobName(cronjobs, trimmedCronjobName).CronJobResponse.Id) } // stop multiple services @@ -100,14 +100,14 @@ var cronjobStopCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs, cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - msg, err := utils.StopService(client, envId, cronjob.Id, utils.JobType, watchFlag) + msg, err := utils.StopService(client, envId, cronjob.CronJobResponse.Id, utils.JobType, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/cronjob_update.go b/cmd/cronjob_update.go index 63e81548..effabd9d 100644 --- a/cmd/cronjob_update.go +++ b/cmd/cronjob_update.go @@ -58,21 +58,21 @@ var cronjobUpdateCmd = &cobra.Command{ cronjob := utils.FindByJobName(cronjobs, cronjobName) - if cronjob == nil { + if cronjob == nil || cronjob.CronJobResponse == nil { utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName)) utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - var docker *qovery.JobResponseAllOfSourceOneOf1Docker = nil - if cronjob.Source.JobResponseAllOfSourceOneOf1 != nil { - docker = cronjob.Source.JobResponseAllOfSourceOneOf1.Docker + var docker *qovery.BaseJobResponseAllOfSourceOneOf1Docker = nil + if cronjob.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf1 != nil { + docker = cronjob.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf1.Docker } var image *qovery.ContainerSource = nil - if cronjob.Source.JobResponseAllOfSourceOneOf != nil { - image = cronjob.Source.JobResponseAllOfSourceOneOf.Image + if cronjob.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf != nil { + image = cronjob.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf.Image } if docker != nil && (cronjobTag != "" || cronjobImageName != "") { @@ -102,7 +102,7 @@ var cronjobUpdateCmd = &cobra.Command{ req.Source.Docker.Set(nil) } - _, res, err := client.JobMainCallsAPI.EditJob(context.Background(), cronjob.Id).JobRequest(req).Execute() + _, res, err := client.JobMainCallsAPI.EditJob(context.Background(), utils.GetJobId(cronjob)).JobRequest(req).Execute() if err != nil { result, _ := io.ReadAll(res.Body) diff --git a/cmd/environment_clone.go b/cmd/environment_clone.go index c164c954..ed8ff189 100644 --- a/cmd/environment_clone.go +++ b/cmd/environment_clone.go @@ -34,7 +34,7 @@ var environmentCloneCmd = &cobra.Command{ panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - req := qovery.CloneRequest{ + req := qovery.CloneEnvironmentRequest{ Name: newEnvironmentName, ApplyDeploymentRule: &applyDeploymentRule, } @@ -63,7 +63,7 @@ var environmentCloneCmd = &cobra.Command{ } } - _, res, err := client.EnvironmentActionsAPI.CloneEnvironment(context.Background(), envId).CloneRequest(req).Execute() + _, res, err := client.EnvironmentActionsAPI.CloneEnvironment(context.Background(), envId).CloneEnvironmentRequest(req).Execute() if err != nil { // print http body error message diff --git a/cmd/environment_stage_move.go b/cmd/environment_stage_move.go index bc929f3a..b5672cf0 100644 --- a/cmd/environment_stage_move.go +++ b/cmd/environment_stage_move.go @@ -121,7 +121,7 @@ func getServiceByName(client *qovery.APIClient, services []qovery.DeploymentStag return nil, err } - if job.GetName() == name { + if utils.GetJobName(job) == name { return &service, nil } default: diff --git a/cmd/lifecycle.go b/cmd/lifecycle.go index 15afa5dd..9ad24ce5 100644 --- a/cmd/lifecycle.go +++ b/cmd/lifecycle.go @@ -42,15 +42,12 @@ func ListLifecycleJobs(envId string, client *qovery.APIClient) ([]qovery.JobResp return nil, err } - cronjobs := make([]qovery.JobResponse, 0) + lifecycleJobs := make([]qovery.JobResponse, 0) for _, job := range jobs.GetResults() { - schedule := job.GetSchedule() - cronjob, _ := schedule.GetCronjobOk() - - if cronjob == nil || cronjob.ScheduledAt == "" { - cronjobs = append(cronjobs, job) + if job.LifecycleJobResponse != nil { + lifecycleJobs = append(lifecycleJobs, job) } } - return cronjobs, nil + return lifecycleJobs, nil } diff --git a/cmd/lifecycle_cancel.go b/cmd/lifecycle_cancel.go index 7a2a92f4..77bedadd 100644 --- a/cmd/lifecycle_cancel.go +++ b/cmd/lifecycle_cancel.go @@ -41,14 +41,14 @@ var lifecycleCancelCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles.GetResults(), lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycles with: qovery lifecycle list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - msg, err := utils.CancelServiceDeployment(client, envId, lifecycle.Id, utils.JobType, watchFlag) + msg, err := utils.CancelServiceDeployment(client, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/lifecycle_clone.go b/cmd/lifecycle_clone.go index 558290fb..747b8a92 100644 --- a/cmd/lifecycle_clone.go +++ b/cmd/lifecycle_clone.go @@ -37,7 +37,7 @@ var lifecycleCloneCmd = &cobra.Command{ job, err := getJobContextResource(client, lifecycleName, envId) - if err != nil { + if err != nil || job == nil || job.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all jobs with: qovery job list") os.Exit(1) @@ -70,15 +70,15 @@ var lifecycleCloneCmd = &cobra.Command{ if targetLifecycleName == "" { // use same job name as the source job - targetLifecycleName = job.Name + targetLifecycleName = job.LifecycleJobResponse.Name } - req := qovery.CloneJobRequest{ + req := qovery.CloneServiceRequest{ Name: targetLifecycleName, EnvironmentId: targetEnvironmentId, } - clonedService, res, err := client.JobsAPI.CloneJob(context.Background(), job.Id).CloneJobRequest(req).Execute() + clonedService, res, err := client.JobsAPI.CloneJob(context.Background(), job.LifecycleJobResponse.Id).CloneServiceRequest(req).Execute() if err != nil { // print http body error message @@ -94,7 +94,7 @@ var lifecycleCloneCmd = &cobra.Command{ name := "" if clonedService != nil { - name = clonedService.Name + name = clonedService.LifecycleJobResponse.Name } utils.Println(fmt.Sprintf("Job %s cloned!", pterm.FgBlue.Sprintf(name))) diff --git a/cmd/lifecycle_delete.go b/cmd/lifecycle_delete.go index e5bdec24..01a410cd 100644 --- a/cmd/lifecycle_delete.go +++ b/cmd/lifecycle_delete.go @@ -69,7 +69,7 @@ var lifecycleDeleteCmd = &cobra.Command{ var serviceIds []string for _, lifecycleName := range strings.Split(lifecycleNames, ",") { trimmedLifecycleName := strings.TrimSpace(lifecycleName) - serviceIds = append(serviceIds, utils.FindByJobName(lifecycles, trimmedLifecycleName).Id) + serviceIds = append(serviceIds, utils.FindByJobName(lifecycles, trimmedLifecycleName).LifecycleJobResponse.Id) } // stop multiple services @@ -100,14 +100,14 @@ var lifecycleDeleteCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles, lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycle jobs with: qovery lifecycle list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - msg, err := utils.DeleteService(client, envId, lifecycle.Id, utils.JobType, watchFlag) + msg, err := utils.DeleteService(client, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/lifecycle_deploy.go b/cmd/lifecycle_deploy.go index a6d7cab1..d119f892 100644 --- a/cmd/lifecycle_deploy.go +++ b/cmd/lifecycle_deploy.go @@ -92,21 +92,21 @@ var lifecycleDeployCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles, lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycle jobs with: qovery lifecycle list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - var docker *qovery.JobResponseAllOfSourceOneOf1Docker = nil - if lifecycle.Source.JobResponseAllOfSourceOneOf1 != nil { - docker = lifecycle.Source.JobResponseAllOfSourceOneOf1.Docker + var docker *qovery.BaseJobResponseAllOfSourceOneOf1Docker = nil + if lifecycle.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf1 != nil { + docker = lifecycle.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf1.Docker } var image *qovery.ContainerSource = nil - if lifecycle.Source.JobResponseAllOfSourceOneOf != nil { - image = lifecycle.Source.JobResponseAllOfSourceOneOf.Image + if lifecycle.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf != nil { + image = lifecycle.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf.Image } var req qovery.JobDeployRequest @@ -129,7 +129,7 @@ var lifecycleDeployCmd = &cobra.Command{ } } - msg, err := utils.DeployService(client, envId, lifecycle.Id, utils.JobType, req, watchFlag) + msg, err := utils.DeployService(client, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, req, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/lifecycle_env_alias_create.go b/cmd/lifecycle_env_alias_create.go index 80a8e522..583396bb 100644 --- a/cmd/lifecycle_env_alias_create.go +++ b/cmd/lifecycle_env_alias_create.go @@ -42,14 +42,14 @@ var lifecycleEnvAliasCreateCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles.GetResults(), lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycles with: qovery lifecycle list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - err = utils.CreateAlias(client, projectId, envId, lifecycle.Id, utils.JobType, utils.Key, utils.Alias, utils.JobScope) + err = utils.CreateAlias(client, projectId, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, utils.Key, utils.Alias, utils.JobScope) if err != nil { utils.PrintlnError(err) diff --git a/cmd/lifecycle_env_create.go b/cmd/lifecycle_env_create.go index 52f95d27..69aa63c0 100644 --- a/cmd/lifecycle_env_create.go +++ b/cmd/lifecycle_env_create.go @@ -42,7 +42,7 @@ var lifecycleEnvCreateCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles.GetResults(), lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycles with: qovery lifecycle list") os.Exit(1) @@ -50,7 +50,7 @@ var lifecycleEnvCreateCmd = &cobra.Command{ } if utils.IsSecret { - err = utils.CreateSecret(client, projectId, envId, lifecycle.Id, utils.Key, utils.Value, utils.JobScope) + err = utils.CreateSecret(client, projectId, envId, lifecycle.LifecycleJobResponse.Id, utils.Key, utils.Value, utils.JobScope) if err != nil { utils.PrintlnError(err) @@ -62,7 +62,7 @@ var lifecycleEnvCreateCmd = &cobra.Command{ return } - err = utils.CreateEnvironmentVariable(client, projectId, envId, lifecycle.Id, utils.Key, utils.Value, utils.JobScope) + err = utils.CreateEnvironmentVariable(client, projectId, envId, lifecycle.LifecycleJobResponse.Id, utils.Key, utils.Value, utils.JobScope) if err != nil { utils.PrintlnError(err) diff --git a/cmd/lifecycle_env_delete.go b/cmd/lifecycle_env_delete.go index 1b5e1227..092d186e 100644 --- a/cmd/lifecycle_env_delete.go +++ b/cmd/lifecycle_env_delete.go @@ -42,14 +42,14 @@ var lifecycleEnvDeleteCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles.GetResults(), lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycles with: qovery lifecycle list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - err = utils.DeleteByKey(client, projectId, envId, lifecycle.Id, utils.JobType, utils.Key) + err = utils.DeleteByKey(client, projectId, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, utils.Key) if err != nil { utils.PrintlnError(err) diff --git a/cmd/lifecycle_env_list.go b/cmd/lifecycle_env_list.go index 0400eabb..1fd640b8 100644 --- a/cmd/lifecycle_env_list.go +++ b/cmd/lifecycle_env_list.go @@ -42,7 +42,7 @@ var lifecycleEnvListCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles.GetResults(), lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil{ utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycles with: qovery lifecycle list") os.Exit(1) @@ -51,7 +51,7 @@ var lifecycleEnvListCmd = &cobra.Command{ envVars, _, err := client.JobEnvironmentVariableAPI.ListJobEnvironmentVariable( context.Background(), - lifecycle.Id, + lifecycle.LifecycleJobResponse.Id, ).Execute() if err != nil { @@ -62,7 +62,7 @@ var lifecycleEnvListCmd = &cobra.Command{ secrets, _, err := client.JobSecretAPI.ListJobSecrets( context.Background(), - lifecycle.Id, + lifecycle.LifecycleJobResponse.Id, ).Execute() if err != nil { diff --git a/cmd/lifecycle_env_override_create.go b/cmd/lifecycle_env_override_create.go index 91866695..9669752c 100644 --- a/cmd/lifecycle_env_override_create.go +++ b/cmd/lifecycle_env_override_create.go @@ -42,14 +42,14 @@ var lifecycleEnvOverrideCreateCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles.GetResults(), lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycles with: qovery lifecycle list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - err = utils.CreateOverride(client, projectId, envId, lifecycle.Id, utils.JobType, utils.Key, &utils.Value, utils.JobScope) + err = utils.CreateOverride(client, projectId, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, utils.Key, &utils.Value, utils.JobScope) if err != nil { utils.PrintlnError(err) diff --git a/cmd/lifecycle_list.go b/cmd/lifecycle_list.go index 175cd419..9567818f 100644 --- a/cmd/lifecycle_list.go +++ b/cmd/lifecycle_list.go @@ -58,8 +58,10 @@ var lifecycleListCmd = &cobra.Command{ var data [][]string for _, lifecycle := range lifecycles { - data = append(data, []string{lifecycle.Id, lifecycle.Name, "Lifecycle", - utils.FindStatusTextWithColor(statuses.GetJobs(), lifecycle.Id), lifecycle.UpdatedAt.String()}) + if lifecycle.LifecycleJobResponse != nil { + data = append(data, []string{lifecycle.LifecycleJobResponse.Id, lifecycle.LifecycleJobResponse.Name, "Lifecycle", + utils.FindStatusTextWithColor(statuses.GetJobs(), lifecycle.LifecycleJobResponse.Id), lifecycle.LifecycleJobResponse.UpdatedAt.String()}) + } } err = utils.PrintTable([]string{"Id", "Name", "Type", "Status", "Last Update"}, data) @@ -76,13 +78,13 @@ func getLifecycleJsonOutput(statuses []qovery.Status, lifecycles []qovery.JobRes var results []interface{} for _, lifecycle := range lifecycles { - if lifecycle.Schedule.Cronjob == nil { + if lifecycle.LifecycleJobResponse != nil { results = append(results, map[string]interface{}{ - "id": lifecycle.Id, - "name": lifecycle.Name, + "id": lifecycle.LifecycleJobResponse.Id, + "name": lifecycle.LifecycleJobResponse.Name, "type": "Lifecycle", - "status": utils.FindStatus(statuses, lifecycle.Id), - "updated_at": utils.ToIso8601(lifecycle.UpdatedAt), + "status": utils.FindStatus(statuses, lifecycle.LifecycleJobResponse.Id), + "updated_at": utils.ToIso8601(lifecycle.LifecycleJobResponse.UpdatedAt), }) } } diff --git a/cmd/lifecycle_redeploy.go b/cmd/lifecycle_redeploy.go index bd08619c..82d59f10 100644 --- a/cmd/lifecycle_redeploy.go +++ b/cmd/lifecycle_redeploy.go @@ -41,14 +41,14 @@ var lifecycleRedeployCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles, lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycle jobs with: qovery lifecycle list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - msg, err := utils.RedeployService(client, envId, lifecycle.Id, utils.JobType, watchFlag) + msg, err := utils.RedeployService(client, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/lifecycle_stop.go b/cmd/lifecycle_stop.go index 9fe4608a..2aa2854c 100644 --- a/cmd/lifecycle_stop.go +++ b/cmd/lifecycle_stop.go @@ -69,7 +69,7 @@ var lifecycleStopCmd = &cobra.Command{ var serviceIds []string for _, lifecycleName := range strings.Split(lifecycleNames, ",") { trimmedLifecycleName := strings.TrimSpace(lifecycleName) - serviceIds = append(serviceIds, utils.FindByJobName(lifecycles, trimmedLifecycleName).Id) + serviceIds = append(serviceIds, utils.GetJobId(utils.FindByJobName(lifecycles, trimmedLifecycleName))) } // stop multiple services @@ -100,14 +100,14 @@ var lifecycleStopCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles, lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycle jobs with: qovery lifecycle list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - msg, err := utils.StopService(client, envId, lifecycle.Id, utils.JobType, watchFlag) + msg, err := utils.StopService(client, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, watchFlag) if err != nil { utils.PrintlnError(err) diff --git a/cmd/lifecycle_update.go b/cmd/lifecycle_update.go index 91fb8c1d..ab5afc14 100644 --- a/cmd/lifecycle_update.go +++ b/cmd/lifecycle_update.go @@ -58,21 +58,21 @@ var lifecycleUpdateCmd = &cobra.Command{ lifecycle := utils.FindByJobName(lifecycles, lifecycleName) - if lifecycle == nil { + if lifecycle == nil || lifecycle.LifecycleJobResponse == nil { utils.PrintlnError(fmt.Errorf("lifecycle %s not found", lifecycleName)) utils.PrintlnInfo("You can list all lifecycles with: qovery lifecycle list") os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - var docker *qovery.JobResponseAllOfSourceOneOf1Docker = nil - if lifecycle.Source.JobResponseAllOfSourceOneOf1 != nil { - docker = lifecycle.Source.JobResponseAllOfSourceOneOf1.Docker + var docker *qovery.BaseJobResponseAllOfSourceOneOf1Docker = nil + if lifecycle.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf1 != nil { + docker = lifecycle.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf1.Docker } var image *qovery.ContainerSource = nil - if lifecycle.Source.JobResponseAllOfSourceOneOf != nil { - image = lifecycle.Source.JobResponseAllOfSourceOneOf.Image + if lifecycle.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf != nil { + image = lifecycle.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf.Image } if docker != nil && (lifecycleTag != "" || lifecycleImageName != "") { @@ -102,7 +102,7 @@ var lifecycleUpdateCmd = &cobra.Command{ req.Source.Docker.Set(nil) } - _, res, err := client.JobMainCallsAPI.EditJob(context.Background(), lifecycle.Id).JobRequest(req).Execute() + _, res, err := client.JobMainCallsAPI.EditJob(context.Background(), lifecycle.LifecycleJobResponse.Id).JobRequest(req).Execute() if err != nil { result, _ := io.ReadAll(res.Body) diff --git a/cmd/service_list.go b/cmd/service_list.go index 09e8c5a4..027d6b82 100644 --- a/cmd/service_list.go +++ b/cmd/service_list.go @@ -107,11 +107,11 @@ var serviceListCmd = &cobra.Command{ for _, job := range jobs.GetResults() { jobType := "Lifecycle" - if job.Schedule.Cronjob != nil { + if job.CronJobResponse != nil { jobType = "Cronjob" } - data = append(data, []string{job.Name, jobType, utils.FindStatusTextWithColor(statuses.GetJobs(), job.Id)}) + data = append(data, []string{utils.GetJobName(&job), jobType, utils.FindStatusTextWithColor(statuses.GetJobs(), utils.GetJobId(&job))}) } for _, database := range databases.GetResults() { @@ -344,15 +344,15 @@ func getServiceJsonOutput(statuses qovery.EnvironmentStatuses, apps []qovery.App for _, job := range jobs { jobType := "lifecycle" - if job.Schedule.Cronjob != nil { + if job.CronJobResponse != nil { jobType = "cronjob" } m := map[string]interface{}{ - "id": job.Id, - "name": job.Name, + "id": utils.GetJobId(&job), + "name": utils.GetJobName(&job), "type": jobType, - "status": utils.FindStatus(statuses.GetJobs(), job.Id), + "status": utils.FindStatus(statuses.GetJobs(), utils.GetJobId(&job)), } results = append(results, m) @@ -435,9 +435,9 @@ Powered by [Qovery](https://qovery.com).` } for _, job := range jobs { - consoleLink := fmt.Sprintf("https://console.qovery.com/organization/%s/project/%s/environment/%s/application/%s", orgId, projectId, envId, job.Id) - consoleLogsLink := fmt.Sprintf("https://console.qovery.com/organization/%s/project/%s/environment/%s/logs/%s/live-logs", orgId, projectId, envId, job.Id) - body += fmt.Sprintf("\n| [%s](%s) | [Show logs](%s) | %s |", job.Name, consoleLink, consoleLogsLink, na) + consoleLink := fmt.Sprintf("https://console.qovery.com/organization/%s/project/%s/environment/%s/application/%s", orgId, projectId, envId, utils.GetJobId(&job)) + consoleLogsLink := fmt.Sprintf("https://console.qovery.com/organization/%s/project/%s/environment/%s/logs/%s/live-logs", orgId, projectId, envId, utils.GetJobId(&job)) + body += fmt.Sprintf("\n| [%s](%s) | [Show logs](%s) | %s |", utils.GetJobName(&job), consoleLink, consoleLogsLink, na) } for _, db := range databases { diff --git a/go.mod b/go.mod index c017c021..a1bb821e 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/posthog/posthog-go v0.0.0-20221221115252-24dfed35d71a github.com/pterm/pterm v0.12.55 - github.com/qovery/qovery-client-go v0.0.0-20231026155011-32f75bc052b7 + github.com/qovery/qovery-client-go v0.0.0-20231208111827-88f2dd1feed0 github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 2aae05b9..b37f5f64 100644 --- a/go.sum +++ b/go.sum @@ -180,6 +180,8 @@ github.com/qovery/qovery-client-go v0.0.0-20231011161912-c7440f44509f h1:pa41jP4 github.com/qovery/qovery-client-go v0.0.0-20231011161912-c7440f44509f/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o= github.com/qovery/qovery-client-go v0.0.0-20231026155011-32f75bc052b7 h1:ud76488ko7z9k/u5jguFDZ1oKNh09VoPvrSOtPoP6bU= github.com/qovery/qovery-client-go v0.0.0-20231026155011-32f75bc052b7/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o= +github.com/qovery/qovery-client-go v0.0.0-20231208111827-88f2dd1feed0 h1:HGsxRtKkHQiqk+PutyzcHKfICDMdNDnNc83FDk8DNY4= +github.com/qovery/qovery-client-go v0.0.0-20231208111827-88f2dd1feed0/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= diff --git a/utils/qovery.go b/utils/qovery.go index f9f37c89..f45103f9 100644 --- a/utils/qovery.go +++ b/utils/qovery.go @@ -502,11 +502,23 @@ func SelectService(environment Id) (*Service, error) { } for _, job := range jobs.GetResults() { - servicesNames = append(servicesNames, job.Name) - services[job.Name] = Service{ - ID: Id(job.Id), - Name: Name(job.Name), - Type: JobType, + if job.CronJobResponse != nil { + cronJob := job.CronJobResponse + servicesNames = append(servicesNames, cronJob.Name) + services[cronJob.Name] = Service{ + ID: Id(cronJob.Id), + Name: Name(cronJob.Name), + Type: JobType, + } + } + if job.LifecycleJobResponse != nil { + lifecycleJob := job.LifecycleJobResponse + servicesNames = append(servicesNames, lifecycleJob.Name) + services[lifecycleJob.Name] = Service{ + ID: Id(lifecycleJob.Id), + Name: Name(lifecycleJob.Name), + Type: JobType, + } } } @@ -635,10 +647,21 @@ func GetJobById(id string) (*Job, error) { return nil, err } - return &Job{ - ID: Id(job.Id), - Name: Name(job.GetName()), - }, nil + if job.LifecycleJobResponse != nil { + return &Job{ + ID: Id(job.LifecycleJobResponse.Id), + Name: Name(job.LifecycleJobResponse.GetName()), + }, nil + } + + if job.CronJobResponse != nil { + return &Job{ + ID: Id(job.CronJobResponse.Id), + Name: Name(job.CronJobResponse.GetName()), + }, nil + } + + return nil, errors.New("Invalid job response") } func CheckAdminUrl() { @@ -974,7 +997,10 @@ func FindByContainerName(containers []qovery.ContainerResponse, name string) *qo func FindByJobName(jobs []qovery.JobResponse, name string) *qovery.JobResponse { for _, j := range jobs { - if j.Name == name { + if j.CronJobResponse != nil && j.CronJobResponse.Name == name { + return &j + } + if j.LifecycleJobResponse != nil && j.LifecycleJobResponse.Name == name { return &j } } @@ -1231,7 +1257,7 @@ func GetServiceNameByIdAndType(client *qovery.APIClient, serviceId string, servi if err != nil { return "" } - return job.GetName() + return GetJobName(job) default: return "Unknown" } @@ -1358,15 +1384,9 @@ func DeployJobs(client *qovery.APIClient, envId string, jobNames string, commitI return fmt.Errorf("job %s not found", trimmedJobName) } - var docker *qovery.JobResponseAllOfSourceOneOf1Docker = nil - if job.Source.JobResponseAllOfSourceOneOf1 != nil { - docker = job.Source.JobResponseAllOfSourceOneOf1.Docker - } - var image *qovery.ContainerSource = nil - if job.Source.JobResponseAllOfSourceOneOf != nil { - image = job.Source.JobResponseAllOfSourceOneOf.Image - } + var docker = GetJobDocker(job) + var image = GetJobImage(job) var mCommitId *string var mTag *string @@ -1385,8 +1405,9 @@ func DeployJobs(client *qovery.APIClient, envId string, jobNames string, commitI } } + var jobId = GetJobId(job) jobsToDeploy = append(jobsToDeploy, qovery.DeployAllRequestJobsInner{ - Id: &job.Id, + Id: &jobId, ImageTag: mTag, GitCommitId: mCommitId, }) @@ -1402,6 +1423,47 @@ func DeployJobs(client *qovery.APIClient, envId string, jobNames string, commitI return deployAllServices(client, envId, req) } +func GetJobDocker(job *qovery.JobResponse) *qovery.BaseJobResponseAllOfSourceOneOf1Docker { + if job.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf1 != nil { + return job.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf1.Docker + } + + if job.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf1 != nil { + return job.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf1.Docker + } + return nil +} + +func GetJobImage(job *qovery.JobResponse) *qovery.ContainerSource { + if job.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf != nil { + return job.CronJobResponse.Source.BaseJobResponseAllOfSourceOneOf.Image + } + if job.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf != nil { + return job.LifecycleJobResponse.Source.BaseJobResponseAllOfSourceOneOf.Image + } + return nil +} + +func GetJobId(job *qovery.JobResponse) string { + if job.CronJobResponse != nil { + return job.CronJobResponse.Id + } + if job.LifecycleJobResponse != nil { + return job.LifecycleJobResponse.Id + } + return "" +} + +func GetJobName(job *qovery.JobResponse) string { + if job.CronJobResponse != nil { + return job.CronJobResponse.Name + } + if job.LifecycleJobResponse != nil { + return job.LifecycleJobResponse.Name + } + return "" +} + func DeployDatabases(client *qovery.APIClient, envId string, databaseNames string) error { if databaseNames == "" { return nil @@ -2073,15 +2135,8 @@ func StopServices(client *qovery.APIClient, envId string, serviceIds []string, s } func ToJobRequest(job qovery.JobResponse) qovery.JobRequest { - var docker *qovery.JobResponseAllOfSourceOneOf1Docker = nil - if job.Source.JobResponseAllOfSourceOneOf1 != nil { - docker = job.Source.JobResponseAllOfSourceOneOf1.Docker - } - - var image *qovery.ContainerSource = nil - if job.Source.JobResponseAllOfSourceOneOf != nil { - image = job.Source.JobResponseAllOfSourceOneOf.Image - } + var docker = GetJobDocker(&job) + var image = GetJobImage(&job) var sourceImage qovery.JobRequestAllOfSourceImage @@ -2116,47 +2171,56 @@ func ToJobRequest(job qovery.JobResponse) qovery.JobRequest { source.Image.Set(&sourceImage) source.Docker.Set(&sourceDocker) - var schedule qovery.JobRequestAllOfSchedule - - if job.Schedule != nil { - var scheduleCronjob qovery.JobRequestAllOfScheduleCronjob + if job.LifecycleJobResponse != nil { + var schedule = qovery.JobRequestAllOfSchedule{ + OnStart: job.LifecycleJobResponse.Schedule.OnStart, + OnStop: job.LifecycleJobResponse.Schedule.OnStop, + OnDelete: job.LifecycleJobResponse.Schedule.OnDelete, + Cronjob: nil, + } - if job.Schedule.Cronjob != nil { - scheduleCronjob = qovery.JobRequestAllOfScheduleCronjob{ - Arguments: job.Schedule.Cronjob.Arguments, - Entrypoint: job.Schedule.Cronjob.Entrypoint, - ScheduledAt: job.Schedule.Cronjob.ScheduledAt, - } + return qovery.JobRequest{ + Name: job.LifecycleJobResponse.Name, + Description: job.LifecycleJobResponse.Description, + Cpu: Int32(job.LifecycleJobResponse.Cpu), + Memory: Int32(job.LifecycleJobResponse.Memory), + MaxNbRestart: job.LifecycleJobResponse.MaxNbRestart, + MaxDurationSeconds: job.LifecycleJobResponse.MaxDurationSeconds, + AutoPreview: Bool(job.LifecycleJobResponse.AutoPreview), + Port: job.LifecycleJobResponse.Port, + Source: &source, + Healthchecks: job.LifecycleJobResponse.Healthchecks, + Schedule: &schedule, + AutoDeploy: *qovery.NewNullableBool(job.LifecycleJobResponse.AutoDeploy), + } + } else { + var scheduleCronjob = qovery.JobRequestAllOfScheduleCronjob{ + Entrypoint: job.CronJobResponse.Schedule.Cronjob.Entrypoint, + Arguments: job.CronJobResponse.Schedule.Cronjob.Arguments, + ScheduledAt: job.CronJobResponse.Schedule.Cronjob.ScheduledAt, + } - schedule = qovery.JobRequestAllOfSchedule{ - OnStart: nil, - OnStop: nil, - OnDelete: nil, - Cronjob: &scheduleCronjob, - } - } else { - schedule = qovery.JobRequestAllOfSchedule{ - OnStart: job.Schedule.OnStart, - OnStop: job.Schedule.OnStop, - OnDelete: job.Schedule.OnDelete, - Cronjob: nil, - } + var schedule = qovery.JobRequestAllOfSchedule{ + OnStart: nil, + OnStop: nil, + OnDelete: nil, + Cronjob: &scheduleCronjob, } - } - return qovery.JobRequest{ - Name: job.Name, - Description: job.Description, - Cpu: Int32(job.Cpu), - Memory: Int32(job.Memory), - MaxNbRestart: job.MaxNbRestart, - MaxDurationSeconds: job.MaxDurationSeconds, - AutoPreview: Bool(job.AutoPreview), - Port: job.Port, - Source: &source, - Healthchecks: job.Healthchecks, - Schedule: &schedule, - AutoDeploy: *qovery.NewNullableBool(job.AutoDeploy), + return qovery.JobRequest{ + Name: job.LifecycleJobResponse.Name, + Description: job.LifecycleJobResponse.Description, + Cpu: Int32(job.LifecycleJobResponse.Cpu), + Memory: Int32(job.LifecycleJobResponse.Memory), + MaxNbRestart: job.LifecycleJobResponse.MaxNbRestart, + MaxDurationSeconds: job.LifecycleJobResponse.MaxDurationSeconds, + AutoPreview: Bool(job.LifecycleJobResponse.AutoPreview), + Port: job.LifecycleJobResponse.Port, + Source: &source, + Healthchecks: job.LifecycleJobResponse.Healthchecks, + Schedule: &schedule, + AutoDeploy: *qovery.NewNullableBool(job.LifecycleJobResponse.AutoDeploy), + } } }