mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-16 12:08:04 +00:00
make REST api more restful
This commit is contained in:
+1
-1
@@ -201,7 +201,7 @@ func Router(c *ctx.AptlyContext) http.Handler {
|
|||||||
api.DELETE("/snapshots/:name", apiSnapshotsDrop)
|
api.DELETE("/snapshots/:name", apiSnapshotsDrop)
|
||||||
api.GET("/snapshots/:name/diff/:withSnapshot", apiSnapshotsDiff)
|
api.GET("/snapshots/:name/diff/:withSnapshot", apiSnapshotsDiff)
|
||||||
api.POST("/snapshots/merge", apiSnapshotsMerge)
|
api.POST("/snapshots/merge", apiSnapshotsMerge)
|
||||||
api.POST("/snapshots/pull", apiSnapshotsPull)
|
api.POST("/snapshots/:name/pull", apiSnapshotsPull)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
+7
-6
@@ -486,8 +486,6 @@ func apiSnapshotsMerge(c *gin.Context) {
|
|||||||
type snapshotsPullBody struct {
|
type snapshotsPullBody struct {
|
||||||
// Source name where packages and dependencies will be searched
|
// Source name where packages and dependencies will be searched
|
||||||
Source string `binding:"required" json:"Source" example:"source-snapshot"`
|
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
|
// Name of the snapshot that will be created
|
||||||
Destination string `binding:"required" json:"Destination" example:"idestination-snapshot"`
|
Destination string `binding:"required" json:"Destination" example:"idestination-snapshot"`
|
||||||
// List of package queries, in the simplest form, name of package to be pulled from
|
// List of package queries, in the simplest form, name of package to be pulled from
|
||||||
@@ -504,13 +502,14 @@ type snapshotsPullBody struct {
|
|||||||
// @Param no-deps query int false "no-deps: 1 to enable"
|
// @Param no-deps query int false "no-deps: 1 to enable"
|
||||||
// @Param no-remove query int false "no-remove: 1 to enable"
|
// @Param no-remove query int false "no-remove: 1 to enable"
|
||||||
// @Accept json
|
// @Accept json
|
||||||
|
// @Param name path string true "Snapshot where packages and dependencies will be pulled to"
|
||||||
// @Param request body snapshotsPullBody true "See api.snapshotsPullBody"
|
// @Param request body snapshotsPullBody true "See api.snapshotsPullBody"
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @Failure 400 {object} Error "Bad Request"
|
// @Failure 400 {object} Error "Bad Request"
|
||||||
// @Failure 404 {object} Error "Not Found"
|
// @Failure 404 {object} Error "Not Found"
|
||||||
// @Failure 500 {object} Error "Internal Error"
|
// @Failure 500 {object} Error "Internal Error"
|
||||||
// @Router /api/snapshots/pull [post]
|
// @Router /api/snapshots/{name}/pull [post]
|
||||||
func apiSnapshotsPull(c *gin.Context) {
|
func apiSnapshotsPull(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
@@ -518,6 +517,8 @@ func apiSnapshotsPull(c *gin.Context) {
|
|||||||
body snapshotsPullBody
|
body snapshotsPullBody
|
||||||
)
|
)
|
||||||
|
|
||||||
|
name := c.Params.ByName("name")
|
||||||
|
|
||||||
if err = c.BindJSON(&body); err != nil {
|
if err = c.BindJSON(&body); err != nil {
|
||||||
AbortWithJSONError(c, http.StatusBadRequest, err)
|
AbortWithJSONError(c, http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
@@ -530,8 +531,8 @@ func apiSnapshotsPull(c *gin.Context) {
|
|||||||
|
|
||||||
collectionFactory := context.NewCollectionFactory()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
// Load <To> snapshot
|
// Load <name> snapshot
|
||||||
toSnapshot, err := collectionFactory.SnapshotCollection().ByName(body.To)
|
toSnapshot, err := collectionFactory.SnapshotCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
AbortWithJSONError(c, http.StatusNotFound, err)
|
AbortWithJSONError(c, http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
@@ -555,7 +556,7 @@ func apiSnapshotsPull(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resources := []string{string(sourceSnapshot.ResourceKey()), string(toSnapshot.ResourceKey())}
|
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) {
|
maybeRunTaskInBackground(c, taskName, resources, func(_ aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
// convert snapshots to package list
|
// convert snapshots to package list
|
||||||
toPackageList, err := deb.NewPackageListFromRefList(toSnapshot.RefList(), collectionFactory.PackageCollection(), context.Progress())
|
toPackageList, err := deb.NewPackageListFromRefList(toSnapshot.RefList(), collectionFactory.PackageCollection(), context.Progress())
|
||||||
|
|||||||
@@ -434,9 +434,8 @@ class SnapshotsAPITestPull(APITest):
|
|||||||
snapshot_pull_libboost = self.random_name()
|
snapshot_pull_libboost = self.random_name()
|
||||||
|
|
||||||
# dry run first
|
# 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,
|
'Source': snapshot_repo_with_libboost,
|
||||||
'To': snapshot_empty_repo,
|
|
||||||
'Destination': snapshot_pull_libboost,
|
'Destination': snapshot_pull_libboost,
|
||||||
'Queries': [
|
'Queries': [
|
||||||
'libboost-program-options-dev'
|
'libboost-program-options-dev'
|
||||||
@@ -449,9 +448,8 @@ class SnapshotsAPITestPull(APITest):
|
|||||||
self.check_equal(resp.status_code, 200)
|
self.check_equal(resp.status_code, 200)
|
||||||
|
|
||||||
# dry run, all-matches
|
# 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,
|
'Source': snapshot_repo_with_libboost,
|
||||||
'To': snapshot_empty_repo,
|
|
||||||
'Destination': snapshot_pull_libboost,
|
'Destination': snapshot_pull_libboost,
|
||||||
'Queries': [
|
'Queries': [
|
||||||
'libboost-program-options-dev'
|
'libboost-program-options-dev'
|
||||||
@@ -464,17 +462,15 @@ class SnapshotsAPITestPull(APITest):
|
|||||||
self.check_equal(resp.status_code, 200)
|
self.check_equal(resp.status_code, 200)
|
||||||
|
|
||||||
# missing argument
|
# missing argument
|
||||||
resp = self.post("/api/snapshots/pull", json={
|
resp = self.post("/api/snapshots/{snapshot_empty_repo}/pull", json={
|
||||||
'Source': snapshot_repo_with_libboost,
|
'Source': snapshot_repo_with_libboost,
|
||||||
'To': snapshot_empty_repo,
|
|
||||||
'Destination': snapshot_pull_libboost,
|
'Destination': snapshot_pull_libboost,
|
||||||
})
|
})
|
||||||
self.check_equal(resp.status_code, 400)
|
self.check_equal(resp.status_code, 400)
|
||||||
|
|
||||||
# dry run, emtpy architectures
|
# 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,
|
'Source': snapshot_repo_with_libboost,
|
||||||
'To': snapshot_empty_repo,
|
|
||||||
'Destination': snapshot_pull_libboost,
|
'Destination': snapshot_pull_libboost,
|
||||||
'Queries': [
|
'Queries': [
|
||||||
'libboost-program-options-dev'
|
'libboost-program-options-dev'
|
||||||
@@ -484,9 +480,8 @@ class SnapshotsAPITestPull(APITest):
|
|||||||
self.check_equal(resp.status_code, 500)
|
self.check_equal(resp.status_code, 500)
|
||||||
|
|
||||||
# dry run, non-existing To
|
# 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,
|
'Source': snapshot_repo_with_libboost,
|
||||||
'To': "asd123",
|
|
||||||
'Destination': snapshot_pull_libboost,
|
'Destination': snapshot_pull_libboost,
|
||||||
'Queries': [
|
'Queries': [
|
||||||
'libboost-program-options-dev'
|
'libboost-program-options-dev'
|
||||||
@@ -495,9 +490,8 @@ class SnapshotsAPITestPull(APITest):
|
|||||||
self.check_equal(resp.status_code, 404)
|
self.check_equal(resp.status_code, 404)
|
||||||
|
|
||||||
# dry run, non-existing source
|
# 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",
|
'Source': "asd123",
|
||||||
'To': snapshot_empty_repo,
|
|
||||||
'Destination': snapshot_pull_libboost,
|
'Destination': snapshot_pull_libboost,
|
||||||
'Queries': [
|
'Queries': [
|
||||||
'libboost-program-options-dev'
|
'libboost-program-options-dev'
|
||||||
@@ -506,9 +500,8 @@ class SnapshotsAPITestPull(APITest):
|
|||||||
self.check_equal(resp.status_code, 404)
|
self.check_equal(resp.status_code, 404)
|
||||||
|
|
||||||
# snapshot pull
|
# snapshot pull
|
||||||
resp = self.post("/api/snapshots/pull", json={
|
resp = self.post("/api/snapshots/{snapshot_empty_repo}/pull", json={
|
||||||
'Source': snapshot_repo_with_libboost,
|
'Source': snapshot_repo_with_libboost,
|
||||||
'To': snapshot_empty_repo,
|
|
||||||
'Destination': snapshot_pull_libboost,
|
'Destination': snapshot_pull_libboost,
|
||||||
'Queries': [
|
'Queries': [
|
||||||
'libboost-program-options-dev'
|
'libboost-program-options-dev'
|
||||||
@@ -532,9 +525,8 @@ class SnapshotsAPITestPull(APITest):
|
|||||||
# pull from non-existing source
|
# pull from non-existing source
|
||||||
non_existing_source = self.random_name()
|
non_existing_source = self.random_name()
|
||||||
destination = 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,
|
'Source': non_existing_source,
|
||||||
'To': snapshot_empty_repo,
|
|
||||||
'Destination': destination,
|
'Destination': destination,
|
||||||
'Queries': [
|
'Queries': [
|
||||||
'Name (~ *)'
|
'Name (~ *)'
|
||||||
@@ -549,9 +541,8 @@ class SnapshotsAPITestPull(APITest):
|
|||||||
# pull to non-existing snapshot
|
# pull to non-existing snapshot
|
||||||
non_existing_snapshot = self.random_name()
|
non_existing_snapshot = self.random_name()
|
||||||
destination = 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,
|
'Source': non_existing_snapshot,
|
||||||
'To': snapshot_empty_repo,
|
|
||||||
'Destination': destination,
|
'Destination': destination,
|
||||||
'Queries': [
|
'Queries': [
|
||||||
'Name (~ *)'
|
'Name (~ *)'
|
||||||
|
|||||||
Reference in New Issue
Block a user