-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(datastore): attempts endpoint removal
- Loading branch information
Showing
4 changed files
with
12 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
type GetAttemptsResponse struct { | ||
Count int `json:"count"` | ||
} | ||
|
||
func getRunAttemptArgs(c echo.Context) (string, string, string, error) { | ||
func getRunAttemptArgs(c echo.Context) (string, string, error) { | ||
namespace := c.Param("namespace") | ||
layer := c.Param("layer") | ||
run := c.Param("run") | ||
if namespace == "" || layer == "" || run == "" { | ||
return "", "", "", fmt.Errorf("missing query parameters") | ||
if namespace == "" || run == "" { | ||
return "", "", fmt.Errorf("missing query parameters") | ||
} | ||
return namespace, layer, run, nil | ||
return namespace, run, nil | ||
} | ||
|
||
func (a *API) GetAttemptsHandler(c echo.Context) error { | ||
namespace, layer, run, err := getRunAttemptArgs(c) | ||
namespace, run, err := getRunAttemptArgs(c) | ||
if err != nil { | ||
return c.String(http.StatusBadRequest, err.Error()) | ||
} | ||
attempts, err := a.Datastore.GetAttempts(namespace, layer, run) | ||
runObject := &configv1alpha1.TerraformRun{} | ||
err = a.Client.Get(context.Background(), types.NamespacedName{Name: run, Namespace: namespace}, runObject) | ||
if err != nil { | ||
return c.String(http.StatusInternalServerError, "could not get run attempt, there's an issue with the storage backend") | ||
return c.String(http.StatusInternalServerError, "could not get run attempt, there's an issue with the cluster: "+err.Error()) | ||
} | ||
response := GetAttemptsResponse{Count: attempts} | ||
response := GetAttemptsResponse{Count: len(runObject.Status.Attempts)} | ||
return c.JSON(http.StatusOK, &response) | ||
} |