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

feat: adapt to last qovery api (job response and clone request) #219

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions cmd/application_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/container_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions cmd/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/cronjob_cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions cmd/cronjob_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)))
Expand Down
4 changes: 2 additions & 2 deletions cmd/cronjob_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions cmd/cronjob_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cronjob_env_alias_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions cmd/cronjob_env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ 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)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cronjob_env_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions cmd/cronjob_env_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -51,7 +51,7 @@ var cronjobEnvListCmd = &cobra.Command{

envVars, _, err := client.JobEnvironmentVariableAPI.ListJobEnvironmentVariable(
context.Background(),
cronjob.Id,
cronjob.CronJobResponse.Id,
).Execute()

if err != nil {
Expand All @@ -62,7 +62,7 @@ var cronjobEnvListCmd = &cobra.Command{

secrets, _, err := client.JobSecretAPI.ListJobSecrets(
context.Background(),
cronjob.Id,
cronjob.CronJobResponse.Id,
).Execute()

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cronjob_env_override_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions cmd/cronjob_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/cronjob_redeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions cmd/cronjob_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions cmd/cronjob_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "") {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/environment_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/environment_stage_move.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading
Loading