Skip to content

Commit

Permalink
fix REST api
Browse files Browse the repository at this point in the history
  • Loading branch information
neolynx committed Oct 3, 2024
1 parent a3078fa commit c3fd172
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
13 changes: 7 additions & 6 deletions api/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,6 @@ func apiSnapshotsMerge(c *gin.Context) {
type snapshotsPullBody struct {
// Source name where packages and dependencies will be searched
Source string `binding:"required" json:"Source" example:"source-snapshot"`
// Snapshot where packages and dependencies will be pulled to
To string `binding:"required" json:"To" example:"to-snapshot"`
// Name of the snapshot that will be created
Destination string `binding:"required" json:"Destination" example:"idestination-snapshot"`
// List of package queries, in the simplest form, name of package to be pulled from
Expand All @@ -504,20 +502,23 @@ type snapshotsPullBody struct {
// @Param no-deps query int false "no-deps: 1 to enable"
// @Param no-remove query int false "no-remove: 1 to enable"
// @Accept json
// @Param name path string true "Snapshot where packages and dependencies will be pulled to"
// @Param request body snapshotsPullBody true "See api.snapshotsPullBody"
// @Produce json
// @Success 200
// @Failure 400 {object} Error "Bad Request"
// @Failure 404 {object} Error "Not Found"
// @Failure 500 {object} Error "Internal Error"
// @Router /api/snapshots/pull [post]
// @Router /api/snapshots/{name}/pull [post]
func apiSnapshotsPull(c *gin.Context) {
var (
err error
destinationSnapshot *deb.Snapshot
body snapshotsPullBody
)

name := c.Params.ByName("name")

if err = c.BindJSON(&body); err != nil {
AbortWithJSONError(c, http.StatusBadRequest, err)
return
Expand All @@ -530,8 +531,8 @@ func apiSnapshotsPull(c *gin.Context) {

collectionFactory := context.NewCollectionFactory()

// Load <To> snapshot
toSnapshot, err := collectionFactory.SnapshotCollection().ByName(body.To)
// Load <name> snapshot
toSnapshot, err := collectionFactory.SnapshotCollection().ByName(name)
if err != nil {
AbortWithJSONError(c, http.StatusNotFound, err)
return
Expand All @@ -555,7 +556,7 @@ func apiSnapshotsPull(c *gin.Context) {
}

resources := []string{string(sourceSnapshot.ResourceKey()), string(toSnapshot.ResourceKey())}
taskName := fmt.Sprintf("Pull snapshot %s into %s and save as %s", body.Source, body.To, body.Destination)
taskName := fmt.Sprintf("Pull snapshot %s into %s and save as %s", body.Source, name, body.Destination)
maybeRunTaskInBackground(c, taskName, resources, func(_ aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
// convert snapshots to package list
toPackageList, err := deb.NewPackageListFromRefList(toSnapshot.RefList(), collectionFactory.PackageCollection(), context.Progress())
Expand Down
27 changes: 9 additions & 18 deletions system/t12_api/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,8 @@ def check(self):
snapshot_pull_libboost = self.random_name()

# dry run first
resp = self.post("/api/snapshots/pull?dry-run=1", json={
resp = self.post(f"/api/snapshots/{snapshot_empty_repo}/pull?dry-run=1", json={
'Source': snapshot_repo_with_libboost,
'To': snapshot_empty_repo,
'Destination': snapshot_pull_libboost,
'Queries': [
'libboost-program-options-dev'
Expand All @@ -449,9 +448,8 @@ def check(self):
self.check_equal(resp.status_code, 200)

# dry run, all-matches
resp = self.post("/api/snapshots/pull?dry-run=1&all-matches=1", json={
resp = self.post("/api/snapshots/{snapshot_empty_repo}/pull?dry-run=1&all-matches=1", json={
'Source': snapshot_repo_with_libboost,
'To': snapshot_empty_repo,
'Destination': snapshot_pull_libboost,
'Queries': [
'libboost-program-options-dev'
Expand All @@ -464,17 +462,15 @@ def check(self):
self.check_equal(resp.status_code, 200)

# missing argument
resp = self.post("/api/snapshots/pull", json={
resp = self.post("/api/snapshots/{snapshot_empty_repo}/pull", json={
'Source': snapshot_repo_with_libboost,
'To': snapshot_empty_repo,
'Destination': snapshot_pull_libboost,
})
self.check_equal(resp.status_code, 400)

# dry run, emtpy architectures
resp = self.post("/api/snapshots/pull?dry-run=1", json={
resp = self.post("/api/snapshots/{snapshot_empty_repo}/pull?dry-run=1", json={
'Source': snapshot_repo_with_libboost,
'To': snapshot_empty_repo,
'Destination': snapshot_pull_libboost,
'Queries': [
'libboost-program-options-dev'
Expand All @@ -484,9 +480,8 @@ def check(self):
self.check_equal(resp.status_code, 500)

# dry run, non-existing To
resp = self.post("/api/snapshots/pull", json={
resp = self.post("/api/snapshots/asd123/pull", json={
'Source': snapshot_repo_with_libboost,
'To': "asd123",
'Destination': snapshot_pull_libboost,
'Queries': [
'libboost-program-options-dev'
Expand All @@ -495,9 +490,8 @@ def check(self):
self.check_equal(resp.status_code, 404)

# dry run, non-existing source
resp = self.post("/api/snapshots/pull?dry-run=1", json={
resp = self.post("/api/snapshots/{snapshot_empty_repo}/pull?dry-run=1", json={
'Source': "asd123",
'To': snapshot_empty_repo,
'Destination': snapshot_pull_libboost,
'Queries': [
'libboost-program-options-dev'
Expand All @@ -506,9 +500,8 @@ def check(self):
self.check_equal(resp.status_code, 404)

# snapshot pull
resp = self.post("/api/snapshots/pull", json={
resp = self.post("/api/snapshots/{snapshot_empty_repo}/pull", json={
'Source': snapshot_repo_with_libboost,
'To': snapshot_empty_repo,
'Destination': snapshot_pull_libboost,
'Queries': [
'libboost-program-options-dev'
Expand All @@ -532,9 +525,8 @@ def check(self):
# pull from non-existing source
non_existing_source = self.random_name()
destination = self.random_name()
resp = self.post("/api/snapshots/pull", json={
resp = self.post("/api/snapshots/{snapshot_empty_repo}/pull", json={
'Source': non_existing_source,
'To': snapshot_empty_repo,
'Destination': destination,
'Queries': [
'Name (~ *)'
Expand All @@ -549,9 +541,8 @@ def check(self):
# pull to non-existing snapshot
non_existing_snapshot = self.random_name()
destination = self.random_name()
resp = self.post("/api/snapshots/pull", json={
resp = self.post("/api/snapshots/{snapshot_empty_repo}/pull", json={
'Source': non_existing_snapshot,
'To': snapshot_empty_repo,
'Destination': destination,
'Queries': [
'Name (~ *)'
Expand Down

0 comments on commit c3fd172

Please sign in to comment.